Skip to content

Commit

Permalink
after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
orto17 committed Sep 29, 2024
1 parent 5c28352 commit 116c874
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,6 @@ import (
"github.com/jfrog/jfrog-client-go/xray/services"
)

func TestXrayAuditSastCppFlagSimpleJson(t *testing.T) {
output := testAuditC(t, string(format.SimpleJson), true)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 1, 0, 0, 0, 0, 0, 0, 0, 0)

}

func TestXrayAuditWithoutSastCppFlagSimpleJson(t *testing.T) {
output := testAuditC(t, string(format.SimpleJson), false)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 0, 0, 0, 0, 0, 0, 0)
}

func testAuditC(t *testing.T, format string, enableCppFlag bool) string {
cliToRun, cleanUp := securityTestUtils.InitTestWithMockCommandOrParams(t, getJasAuditMockCommand)
defer cleanUp()
securityTestUtils.InitSecurityTest(t, scangraph.GraphScanMinXrayVersion)
tempDirPath, createTempDirCallback := coreTests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
cProjectPath := filepath.Join(filepath.FromSlash(securityTestUtils.GetTestResourcesPath()), "projects", "package-managers", "c")
// Copy the c project from the testdata to a temp dir
assert.NoError(t, biutils.CopyDir(cProjectPath, tempDirPath, true, nil))
prevWd := securityTestUtils.ChangeWD(t, tempDirPath)
defer clientTests.ChangeDirAndAssert(t, prevWd)
watchName, deleteWatch := securityTestUtils.CreateTestWatch(t, "audit-policy", "audit-watch", xrayUtils.High)
defer deleteWatch()
if enableCppFlag {
unsetEnv := clientTests.SetEnvWithCallbackAndAssert(t, "JFROG_SAST_ENABLE_CPP", "1")
defer unsetEnv()
}
args := []string{"audit", "--licenses", "--vuln", "--format=" + format, "--watches=" + watchName, "--fail=false"}
return cliToRun.WithoutCredentials().RunCliCmdWithOutput(t, args...)
}

func TestXrayAuditNpmJson(t *testing.T) {
output := testAuditNpm(t, string(format.Json), false)
securityTestUtils.VerifyJsonScanResults(t, output, 1, 0, 1)
Expand Down Expand Up @@ -505,6 +473,39 @@ func addDummyPackageDescriptor(t *testing.T, hasPackageJson bool) {

// JAS

func TestXrayAuditSastCppFlagSimpleJson(t *testing.T) {
output := testAuditC(t, string(format.SimpleJson), true)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 1, 0, 0, 0, 0, 0, 0, 0, 0)

}

func TestXrayAuditWithoutSastCppFlagSimpleJson(t *testing.T) {
output := testAuditC(t, string(format.SimpleJson), false)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 0, 0, 0, 0, 0, 0, 0)
}

// Helper for both C & Cpp Sast scans tests
func testAuditC(t *testing.T, format string, enableCppFlag bool) string {
cliToRun, cleanUp := securityTestUtils.InitTestWithMockCommandOrParams(t, getJasAuditMockCommand)
defer cleanUp()
securityTestUtils.InitSecurityTest(t, scangraph.GraphScanMinXrayVersion)
tempDirPath, createTempDirCallback := coreTests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
cProjectPath := filepath.Join(filepath.FromSlash(securityTestUtils.GetTestResourcesPath()), "projects", "package-managers", "c")
// Copy the c project from the testdata to a temp dir
assert.NoError(t, biutils.CopyDir(cProjectPath, tempDirPath, true, nil))
prevWd := securityTestUtils.ChangeWD(t, tempDirPath)
defer clientTests.ChangeDirAndAssert(t, prevWd)
watchName, deleteWatch := securityTestUtils.CreateTestWatch(t, "audit-policy", "audit-watch", xrayUtils.High)
defer deleteWatch()
if enableCppFlag {
unsetEnv := clientTests.SetEnvWithCallbackAndAssert(t, "JFROG_SAST_ENABLE_CPP", "1")
defer unsetEnv()
}
args := []string{"audit", "--licenses", "--vuln", "--format=" + format, "--watches=" + watchName, "--fail=false"}
return cliToRun.WithoutCredentials().RunCliCmdWithOutput(t, args...)
}

func TestXrayAuditNotEntitledForJas(t *testing.T) {
cliToRun, cleanUp := securityTestUtils.InitTestWithMockCommandOrParams(t, getNoJasAuditMockCommand)
defer cleanUp()
Expand Down

0 comments on commit 116c874

Please sign in to comment.