@@ -473,6 +473,39 @@ func addDummyPackageDescriptor(t *testing.T, hasPackageJson bool) {
473
473
474
474
// JAS
475
475
476
+ func TestXrayAuditSastCppFlagSimpleJson (t * testing.T ) {
477
+ output := testAuditC (t , string (format .SimpleJson ), true )
478
+ securityTestUtils .VerifySimpleJsonJasResults (t , output , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
479
+
480
+ }
481
+
482
+ func TestXrayAuditWithoutSastCppFlagSimpleJson (t * testing.T ) {
483
+ output := testAuditC (t , string (format .SimpleJson ), false )
484
+ securityTestUtils .VerifySimpleJsonJasResults (t , output , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
485
+ }
486
+
487
+ // Helper for both C & Cpp Sast scans tests
488
+ func testAuditC (t * testing.T , format string , enableCppFlag bool ) string {
489
+ cliToRun , cleanUp := securityTestUtils .InitTestWithMockCommandOrParams (t , getJasAuditMockCommand )
490
+ defer cleanUp ()
491
+ securityTestUtils .InitSecurityTest (t , scangraph .GraphScanMinXrayVersion )
492
+ tempDirPath , createTempDirCallback := coreTests .CreateTempDirWithCallbackAndAssert (t )
493
+ defer createTempDirCallback ()
494
+ cProjectPath := filepath .Join (filepath .FromSlash (securityTestUtils .GetTestResourcesPath ()), "projects" , "package-managers" , "c" )
495
+ // Copy the c project from the testdata to a temp dir
496
+ assert .NoError (t , biutils .CopyDir (cProjectPath , tempDirPath , true , nil ))
497
+ prevWd := securityTestUtils .ChangeWD (t , tempDirPath )
498
+ defer clientTests .ChangeDirAndAssert (t , prevWd )
499
+ watchName , deleteWatch := securityTestUtils .CreateTestWatch (t , "audit-policy" , "audit-watch" , xrayUtils .High )
500
+ defer deleteWatch ()
501
+ if enableCppFlag {
502
+ unsetEnv := clientTests .SetEnvWithCallbackAndAssert (t , "JFROG_SAST_ENABLE_CPP" , "1" )
503
+ defer unsetEnv ()
504
+ }
505
+ args := []string {"audit" , "--licenses" , "--vuln" , "--format=" + format , "--watches=" + watchName , "--fail=false" }
506
+ return cliToRun .WithoutCredentials ().RunCliCmdWithOutput (t , args ... )
507
+ }
508
+
476
509
func TestXrayAuditNotEntitledForJas (t * testing.T ) {
477
510
cliToRun , cleanUp := securityTestUtils .InitTestWithMockCommandOrParams (t , getNoJasAuditMockCommand )
478
511
defer cleanUp ()
@@ -483,6 +516,22 @@ func TestXrayAuditNotEntitledForJas(t *testing.T) {
483
516
securityTestUtils .VerifySimpleJsonJasResults (t , output , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
484
517
}
485
518
519
+ func getJasAuditMockCommand () components.Command {
520
+ return components.Command {
521
+ Name : docs .Audit ,
522
+ Flags : docs .GetCommandFlags (docs .Audit ),
523
+ Action : func (c * components.Context ) error {
524
+ auditCmd , err := cli .CreateAuditCmd (c )
525
+ if err != nil {
526
+ return err
527
+ }
528
+ // Disable Jas for this test
529
+ auditCmd .SetUseJas (true )
530
+ return progressbar .ExecWithProgress (auditCmd )
531
+ },
532
+ }
533
+ }
534
+
486
535
func getNoJasAuditMockCommand () components.Command {
487
536
return components.Command {
488
537
Name : docs .Audit ,
0 commit comments