forked from docker-archive/oscalkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add oscalkit-test (docker-archive#31)
Signed-off-by: farhankamalkhan <farhankamalkhan@gmail.com>
- Loading branch information
1 parent
e367d82
commit ee7ab1d
Showing
38 changed files
with
3,336 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.