Skip to content

Commit

Permalink
Add oscalkit-test (docker-archive#31)
Browse files Browse the repository at this point in the history
Signed-off-by: farhankamalkhan <farhankamalkhan@gmail.com>
  • Loading branch information
farhankamalkhan-10p authored and asadullah-yousuf-10p committed Jan 9, 2019
1 parent e367d82 commit ee7ab1d
Show file tree
Hide file tree
Showing 38 changed files with 3,336 additions and 0 deletions.
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

0 comments on commit ee7ab1d

Please sign in to comment.