Skip to content

Commit

Permalink
add tests to new status
Browse files Browse the repository at this point in the history
  • Loading branch information
orz25 committed Mar 19, 2024
1 parent f911581 commit 1d5e32c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func TestXrayAuditMultiProjects(t *testing.T) {
defer securityTestUtils.CleanTestsHomeEnv()
output := securityTests.PlatformCli.WithoutCredentials().RunCliCmdWithOutput(t, "audit", "--format="+string(format.SimpleJson), workingDirsFlag)
securityTestUtils.VerifySimpleJsonScanResults(t, output, 35, 0)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 1, 9, 7, 3)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 1, 9, 7, 6, 25)
}

func TestXrayAuditPipJson(t *testing.T) {
Expand Down Expand Up @@ -430,18 +430,18 @@ func addDummyPackageDescriptor(t *testing.T, hasPackageJson bool) {

func TestXrayAuditJasSimpleJson(t *testing.T) {
output := testXrayAuditJas(t, string(format.SimpleJson), filepath.Join("jas", "jas-test"))
securityTestUtils.VerifySimpleJsonJasResults(t, output, 1, 9, 7, 2)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 1, 9, 7, 3, 3)
}

func TestXrayAuditJasSimpleJsonWithConfig(t *testing.T) {
output := testXrayAuditJas(t, string(format.SimpleJson), filepath.Join("jas", "jas-config"))
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 1, 2)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 1, 3, 3)
}

func TestXrayAuditJasNoViolationsSimpleJson(t *testing.T) {
output := testXrayAuditJas(t, string(format.SimpleJson), filepath.Join("package-managers", "npm", "npm"))
securityTestUtils.VerifySimpleJsonScanResults(t, output, 1, 0)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 0, 0)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 0, 0, 0)
}

func testXrayAuditJas(t *testing.T, format string, project string) string {
Expand Down
7 changes: 5 additions & 2 deletions tests/utils/test_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,25 @@ func VerifySimpleJsonScanResults(t *testing.T, content string, minVulnerabilitie
}
}

func VerifySimpleJsonJasResults(t *testing.T, content string, minSastViolations, minIacViolations, minSecrets, minApplicable int) {
func VerifySimpleJsonJasResults(t *testing.T, content string, minSastViolations, minIacViolations, minSecrets, minApplicable, minNotCovered int) {
var results formats.SimpleJsonResults
err := json.Unmarshal([]byte(content), &results)
if assert.NoError(t, err) {
assert.GreaterOrEqual(t, len(results.Sast), minSastViolations, "Found less sast then expected")
assert.GreaterOrEqual(t, len(results.Secrets), minSecrets, "Found less secrets then expected")
assert.GreaterOrEqual(t, len(results.Iacs), minIacViolations, "Found less IaC then expected")
var applicableResults, notApplicableResults int
var applicableResults, notApplicableResults, notCoveredResults int
for _, vuln := range results.Vulnerabilities {
if vuln.Applicable == string(utils.NotApplicable) {

Check failure on line 65 in tests/utils/test_validation.go

View workflow job for this annotation

GitHub Actions / Static-Check

ifElseChain: rewrite if-else to switch statement (gocritic)
notApplicableResults++
} else if vuln.Applicable == string(utils.Applicable) {
applicableResults++
} else if vuln.Applicable == string(utils.NotCovered) {
notCoveredResults++
}
}
assert.GreaterOrEqual(t, applicableResults, minApplicable, "Found less applicableResults then expected")
assert.GreaterOrEqual(t, notApplicableResults, 1, "Found less notApplicableResults then expected")
assert.GreaterOrEqual(t, notCoveredResults, minNotCovered, "Found less notCoveredResults then expected")
}
}

0 comments on commit 1d5e32c

Please sign in to comment.