Skip to content

Commit 832366b

Browse files
committed
Add string validation for docker scan
1 parent 05867c6 commit 832366b

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

scans_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ func runDockerScan(t *testing.T, testCli *coreTests.JfrogCli, imageName, watchNa
174174
if validateSecrets {
175175
validations.VerifySimpleJsonResults(t, output, validations.ValidationParams{Inactive: minInactives})
176176
} else {
177-
validations.VerifyJsonResults(t, output, validations.ValidationParams{Vulnerabilities: minVulnerabilities, Licenses: minLicenses})
177+
validations.VerifyJsonResults(t, output, validations.ValidationParams{
178+
Vulnerabilities: minVulnerabilities,
179+
Licenses: minLicenses,
180+
//ExistingProperties: []string{"targets[].sca_scans.xray_scan[].vulnerabilities[].components[*].impact_paths[][].full_path"}})
181+
//ExistingProperties: []string{"vulnerabilities[].components[*].impact_paths[][].full_path"}})
182+
ExistingProperties: []string{"impact_paths", "full_path"}})
178183
}
179184
}
180185
// Run docker scan on image with watch
@@ -184,7 +189,7 @@ func runDockerScan(t *testing.T, testCli *coreTests.JfrogCli, imageName, watchNa
184189
cmdArgs = append(cmdArgs, "--watches="+watchName)
185190
output = testCli.WithoutCredentials().RunCliCmdWithOutput(t, cmdArgs...)
186191
if assert.NotEmpty(t, output) {
187-
validations.VerifyJsonResults(t, output, validations.ValidationParams{SecurityViolations: minViolations})
192+
validations.VerifyJsonResults(t, output, validations.ValidationParams{SecurityViolations: minViolations, Vulnerabilities: 0})
188193
}
189194
}
190195
}

utils/validations/test_validate_sca.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package validations
33
import (
44
"encoding/json"
55
"fmt"
6+
"reflect"
7+
"strings"
68
"testing"
79

810
"github.com/jfrog/jfrog-cli-security/utils"
@@ -37,6 +39,13 @@ func ValidateCommandJsonOutput(t *testing.T, params ValidationParams) {
3739
if params.FailBuild == true {
3840
ValidateScanResponseFailBuild(t, params.FailBuildCVESeverity, results)
3941
}
42+
if params.ExistingProperties != nil {
43+
//TODO: TEMP Function - to use ValidatePaths
44+
ValidateContainedStrings(t, fmt.Sprintf("%v", results), params.ExistingProperties)
45+
//for _, res := range results {
46+
// ValidatePaths(t, res, params.ExistingProperties)
47+
//}
48+
}
4049
}
4150
}
4251

@@ -96,3 +105,9 @@ func getScanResponseByScanId(scanId string, content []services.ScanResponse) *se
96105
}
97106
return nil
98107
}
108+
109+
func ValidateContainedStrings(t *testing.T, output string, strings []string) {
110+
for _, str := range strings {
111+
assert.Contains(t, output, str, "string not found: %s", str)
112+
}
113+
}

utils/validations/test_validation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type ValidationParams struct {
2626
Actual interface{}
2727
// If provided, the test will check if the content matches the expected results.
2828
Expected interface{}
29+
// If provided, will go through this list of point attribute - and validate they exists in the actual content.
30+
ExistingProperties []string
2931
// If provided, the test will check exact values and not only the minimum values / existence.
3032
ExactResultsMatch bool
3133
// Expected issues for each type to check if the content has the correct amount of issues.

0 commit comments

Comments
 (0)