// ComputeGapAnalysis will compute the gap analysis and return the inventory of the controls for the
// opencontrol workspace if successful. Otherwise, it will return a list of error messages.
// TODO: fix the error return to return of type error. This was used because existing code returned that type
// TODO: e.g. GetCertification
func ComputeGapAnalysis(config Config) (Inventory, []error) {
	// Initialize inventory with certification
	certificationPath, errs := certifications.GetCertification(config.OpencontrolDir, config.Certification)
	if certificationPath == "" {
		return Inventory{}, errs
	}
	openControlData, _ := models.LoadData(config.OpencontrolDir, certificationPath)
	i := Inventory{
		OpenControl:             openControlData,
		masterControlList:       make(map[string]models.Control),
		actualSatisfiedControls: make(map[string]base.Satisfies),
		MissingControlList:      make(map[string]models.Control),
	}
	if i.Certification == nil || i.Components == nil {
		return Inventory{}, []error{fmt.Errorf("Unable to load data in %s for certification %s", config.OpencontrolDir, config.Certification)}
	}

	// Gather list of all controls for certification
	i.retrieveMasterControlsList()
	// Find the documented controls.
	i.findDocumentedControls()
	// Calculate the Missing controls / Non documented
	i.calculateNonDocumentedControls()

	return i, nil
}
func TestExportControl(t *testing.T) {
	for _, example := range exportControlTests {
		dir, err := ioutil.TempDir("", "example")
		if err != nil {
			log.Fatal(err)
		}
		defer os.RemoveAll(dir)
		openControlData, errs := models.LoadData(example.opencontrolDir, example.certificationPath)
		if len(errs) > 0 {
			log.Fatal("Should have loaded the opencontrol data.")
		}
		openControl := OpenControlGitBook{
			openControlData,
			"",
			dir,
			fs.OSUtil{},
		}
		control := openControl.Standards.Get(example.standardKey).Controls[example.controlKey]
		actualPath, actualText := openControl.exportControl(&ControlGitbook{&control, dir, example.standardKey, example.controlKey})
		expectedPath := filepath.Join(dir, example.expectedPath)
		// Verify the expected export path is the same as the actual export path
		if expectedPath != actualPath {
			t.Errorf("Expected %s, Actual: %s", example.expectedPath, actualPath)
		}
		// Verify the expected text is the same as the actual text
		if example.expectedText != strings.Replace(actualText, "\\", "/", -1) {
			t.Errorf("Expected %s, Actual: %s", example.expectedText, actualText)
		}

	}
Exemple #3
0
//BuildDocx exports a Docx ssp based on a template
func (config *Config) BuildDocx() error {
	openControlData, _ := models.LoadData(config.OpencontrolDir, "")
	openControl := OpenControlDocx{openControlData}
	docTemplate, err := docTemp.GetTemplate(config.TemplatePath)
	if err != nil {
		return err
	}
	funcMap := template.FuncMap{
		"getAllControlSections": openControl.FormatAllNarratives,
		"getControlSection":     openControl.FormatNarrative,
		"getParameter":          openControl.FormatParameter,
		"getResponsibleRole":    openControl.FormatResponsibleRoles,
	}
	docTemplate.AddFunctions(funcMap)
	docTemplate.Parse()
	docTemplate.Execute(config.ExportPath, nil)
	return err
}
func TestBuildComponentsSummaries(t *testing.T) {
	for _, example := range buildComponentsSummariesTests {
		openControlData, _ := models.LoadData(example.opencontrolDir, example.certificationPath)
		openControl := OpenControlGitBook{
			openControlData,
			"",
			example.exportPath,
			fs.OSUtil{},
		}
		actualSummary := openControl.buildComponentsSummaries()
		data, err := ioutil.ReadFile(example.expectedSummary)
		if err != nil {
			log.Fatal(err)
		}
		expectedSummary := string(data)
		// Check that the actual and expected summaries are similar
		if strings.Replace(actualSummary, "\\", "/", -1) != expectedSummary {
			t.Errorf("Expected: `%s`, Actual: `%s`", expectedSummary, actualSummary)
		}
	}
// BuildGitbook entry point for creating gitbook
func (config Config) BuildGitbook() []error {
	var errs []error
	openControlData, err := models.LoadData(config.OpencontrolDir, config.Certification)
	if err != nil && len(err) > 0 {
		return append(errs, err...)
	}
	openControl := OpenControlGitBook{
		openControlData,
		config.MarkdownPath,
		config.ExportPath,
		fs.OSUtil{},
	}
	openControl.FSUtil.Mkdirs(config.ExportPath)
	openControl.FSUtil.Mkdirs(filepath.Join(config.ExportPath, "components"))
	openControl.FSUtil.Mkdirs(filepath.Join(config.ExportPath, "standards"))
	if err := openControl.buildSummaries(); err != nil {
		return append(errs, err)
	}
	openControl.exportComponents()
	openControl.exportStandards()
	return nil
}
	"path/filepath"

	"github.com/opencontrol/compliance-masonry/models"
	"github.com/opencontrol/doc-template"

	"fmt"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/ginkgo/extensions/table"
	v3 "github.com/opencontrol/compliance-masonry/models/components/versions/3_0_0"
	"github.com/stretchr/testify/assert"
)

var _ = Describe("Docx", func() {

	DescribeTable("FormatAllNarratives", func(standard string, control string, expectedData string) {
		openControlData, err := models.LoadData(filepath.Join("..", "fixtures", "opencontrol_fixtures"), "")
		openControl := OpenControlDocx{
			OpenControl: openControlData,
		}
		actualData := openControl.FormatAllNarratives(standard, control)
		assert.Nil(GinkgoT(), err)
		assert.Equal(GinkgoT(), expectedData, actualData)
	},
		// Get All Control Data
		Entry("openControl.FormatAllNarratives([email protected])", "PCI-DSS-MAY-2015", "2.1", "Amazon Elastic Compute Cloud\nJustification in narrative form for 2.1\n"),
		Entry("openControl.FormatAllNarratives([email protected]) - Missing Control", "PCI-DSS-MAY-2015", "1.1.1", "No information found for the combination of standard PCI-DSS-MAY-2015 and control 1.1.1"),
		Entry("openControl.FormatAllNarratives(BogusStandard@NothingControl)", "BogusStandard", "NothingControl", "No information found for the combination of standard BogusStandard and control NothingControl"),
	)

	DescribeTable("FormatNarrative", func(standard string, control string, expectedData string, sectionKeys ...string) {
		openControlData, err := models.LoadData(filepath.Join("..", "fixtures", "opencontrol_fixtures"), "")