-
Notifications
You must be signed in to change notification settings - Fork 89
Fix TestCreateVulnerabilitiesMap tests #1038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3_er
Are you sure you want to change the base?
Fix TestCreateVulnerabilitiesMap tests #1038
Conversation
- Fix all test cases that were corrupted due to V3 changes - Update vulnerability tests to use real SBOM structure from testdata files - Add SBOM testdata files with proper JFrog catalog format: - sbom_with_vulnerabilities.json: Main vulnerability test with axios CVEs - sbom_multiple_vulns_same_pkg.json: Tests max version selection logic - sbom_no_fix_version.json: Tests that vulns without fixes are excluded - Update violations test to use SecurityCommandResults.Violations field - Add support for loading SBOM from testdata files in test runner Test cases now properly validate: - Vulnerabilities processed from SBOM format - Violations processed from Violations field - Max fix version selection when multiple CVEs affect same package - Vulnerabilities without fix versions are not added to map
📗 Scan Summary
|
at 🎯 Static Application Security Testing (SAST) VulnerabilityFull descriptionVulnerability Details
OverviewStored Cross-Site Scripting (XSS) is a type of vulnerability where malicious Vulnerable examplefunc serveMessage(w http.ResponseWriter, r *http.Request) {
db, _ := sql.Open("sqlite3", "test.db")
message := db.QueryRow("SELECT message FROM messages WHERE id = 1")
fmt.Fprintf(w, "<h1>%s</h1>", message)
}In this example, the RemediationTo mitigate Stored XSS vulnerabilities, always sanitize and encode user func serveMessage(w http.ResponseWriter, r *http.Request) {
db, _ := sql.Open("sqlite3", "test.db")
message := db.QueryRow("SELECT message FROM messages WHERE id = 1")
- fmt.Fprintf(w, "<h1>%s</h1>", message)
+ fmt.Fprintf(w, "<h1>%s</h1>", html.EscapeString(message))
}In the remediation, we've used the Code FlowsVulnerable data flow analysis result
|
|
|
||
| testCases := []struct { | ||
| name string | ||
| sbomFile string // Optional: path to SBOM JSON file to load |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to sbomFilePath and you can delete the comment (if you want to leave it -place it above)
| JasResults: &results.JasScansResults{}, | ||
| }}, | ||
| }, | ||
| // axios@1.2.0 has 4 CVEs with fix versions: 1.6.0, 1.7.8, 1.12.0, 1.8.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete comment
| SuggestedFixedVersion: "1.9.1", | ||
| IsDirectDependency: true, | ||
| Cves: []string{"CVE-2023-1234", "CVE-2023-4321"}, | ||
| Cves: []string{"CVE-2023-1234"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you remove the second CVE due to the bug you found that we only take a single CVE even when several exist?
| JasResults: &results.JasScansResults{}, | ||
| }}, | ||
| }, | ||
| // shared-pkg@1.0.0 has 3 CVEs with fix versions: 1.5.0, 1.8.0, 1.6.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete comment
|
|
||
| for _, testCase := range testCases { | ||
| t.Run(testCase.name, func(t *testing.T) { | ||
| // Load SBOM from file if specified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete comment
| var sbom cyclonedx.BOM | ||
| err = json.Unmarshal(sbomData, &sbom) | ||
| require.NoError(t, err, "Failed to unmarshal SBOM") | ||
| // Set the SBOM in the first target's ScaResults |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete comment
eranturgeman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great! please see my comments and please place all sbom files in an inner dir inside testdata/scanrepository just for better ordering


Test cases now properly validate: