Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
orto17 committed Sep 29, 2024
1 parent 1e53792 commit 5bb8b0d
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,20 @@ import (
"github.com/jfrog/jfrog-client-go/xray/services"
)

func TestXrayAuditSastCppFlagJson(t *testing.T) {
output := testAuditC(t, string(format.Json), true)
securityTestUtils.VerifyJsonScanResults(t, output, 0, 1, 0)
}

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

func TestXrayAuditWithoutSastCppFlagJson(t *testing.T) {
output := testAuditC(t, string(format.Json), false)
securityTestUtils.VerifyJsonScanResults(t, output, 0, 0, 0)
}

func TestXrayAuditWithoutSastCppFlagSimpleJson(t *testing.T) {
output := testAuditC(t, string(format.Json), false)
securityTestUtils.VerifyJsonScanResults(t, output, 0, 0, 0)
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()
Expand All @@ -69,7 +62,7 @@ func testAuditC(t *testing.T, format string, enableCppFlag bool) string {
defer unsetEnv()
}
args := []string{"audit", "--licenses", "--vuln", "--format=" + format, "--watches=" + watchName, "--fail=false"}
return securityTests.PlatformCli.RunCliCmdWithOutput(t, args...)
return cliToRun.WithoutCredentials().RunCliCmdWithOutput(t, args...)
}

func TestXrayAuditNpmJson(t *testing.T) {
Expand Down Expand Up @@ -492,6 +485,22 @@ func TestXrayAuditNotEntitledForJas(t *testing.T) {
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 0, 0, 0, 0, 0, 0, 0)
}

func getJasAuditMockCommand() components.Command {
return components.Command{
Name: docs.Audit,
Flags: docs.GetCommandFlags(docs.Audit),
Action: func(c *components.Context) error {
auditCmd, err := cli.CreateAuditCmd(c)
if err != nil {
return err
}
// Disable Jas for this test
auditCmd.SetUseJas(true)
return progressbar.ExecWithProgress(auditCmd)
},
}
}

func getNoJasAuditMockCommand() components.Command {
return components.Command{
Name: docs.Audit,
Expand Down

0 comments on commit 5bb8b0d

Please sign in to comment.