Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Add oscalkit-test #31

Merged
merged 1 commit into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions test/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Test

Test is a utility used for testing the go structures being generated by oscalkit from the profiles being provided.

Prerequisite
======

```
NOTE: The downloaded profile that needs to be tested should contain downloadable href links to catalogs and profiles. In case a relative path is provided, replace them with the absolute downloadable link.
```

Run Test
========

```
NOTE: This is a test so output.go (generated using oscalkit cli) should already exist when running this test.
```
To run the test run `cd test/` to change directory to the test scripts and run

`go run *.go -p <path to the downloaded profile to be tested>`

58 changes: 58 additions & 0 deletions test/TestCases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"log"
"os"
"path/filepath"

"github.com/fatih/color"
"github.com/opencontrol/oscalkit/types/oscal/catalog"
)

// SecurityControlsSubcontrolCheck is a test to verify that all controls from the catalog are being mapped correctly
func SecurityControlsSubcontrolCheck(check []catalog.Catalog, ProfileFile string) error {

codeGeneratedControls := ProtocolsMapping(check)

f, err := os.Open(ProfileFile)
if err != nil {
log.Fatal(err)
}

parsedProfile, err := GetProfile(f)
if err != nil {
log.Fatal(err)
}

profileControlsDetails := ProfileProcessing(parsedProfile)

if len(codeGeneratedControls) == len(profileControlsDetails) {
println("Perfect Count Match")
println("Go file control, sub-control count: ", len(codeGeneratedControls))
println("Profile control, sub-control count: ", len(profileControlsDetails))
codeGeneratedMapping := ProtocolsMapping(check)
mapcompareflag := AreMapsSame(profileControlsDetails, codeGeneratedMapping)
if mapcompareflag {
color.Green("ID, Class & Title Mapping Correct")
} else {
color.Red("ID, Class & Title Mapping Incorrect")
}
} else if len(codeGeneratedControls) > len(profileControlsDetails) {
println("Controls in go file are greater in number then present in profile")
println("Go file control, sub-control count: ", len(codeGeneratedControls))
println("Profile control, sub-control count: ", len(profileControlsDetails))
color.Red("ID, Class & Title Mapping Incorrect")
} else if len(codeGeneratedControls) < len(profileControlsDetails) {
println("Controls in profile are greater in number then present in go file")
println("Go file control, sub-control count: ", len(codeGeneratedControls))
println("Profile control, sub-control count: ", len(profileControlsDetails))
color.Red("ID, Class & Title Mapping Incorrect")
}
file, _ := filepath.Glob("./oscaltesttmp*")
if file != nil {
for _, f := range file {
os.RemoveAll(f)
}
}
return nil
}
23 changes: 23 additions & 0 deletions test/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"flag"
"os"
"path/filepath"

"github.com/opencontrol/oscalkit"
)

func main() {

var check = oscalkit.ApplicableControls
profile := flag.String("p", "", "Path of the profile")
flag.Parse()
file, _ := filepath.Glob("./oscaltesttmp*")
if file != nil {
for _, f := range file {
os.RemoveAll(f)
}
}
SecurityControlsSubcontrolCheck(check, *profile)
}
Loading