-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: munishchouhan <[email protected]>
- Loading branch information
1 parent
44e455d
commit 6653ec3
Showing
3 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,86 @@ class TrivyResultProcessorTest extends Specification { | |
|
||
} | ||
|
||
def "should return a sorted map of vulnerabilities"() { | ||
given: | ||
def trivyDockerResulJson = """ | ||
{ "Results": [ | ||
{ | ||
"Target": "sample-application", | ||
"Class": "os-pkgs", | ||
"Type": "linux", | ||
"Vulnerabilities": [ | ||
{ | ||
"VulnerabilityID": "CVE-2023-0001", | ||
"PkgID": "[email protected]", | ||
"PkgName": "example-lib", | ||
"InstalledVersion": "1.0.0", | ||
"FixedVersion": "1.0.1", | ||
"Severity": "LOW", | ||
"Description": "A minor vulnerability with low impact.", | ||
"PrimaryURL": "https://example.com/CVE-2023-0001" | ||
}, | ||
{ | ||
"VulnerabilityID": "CVE-2023-0002", | ||
"PkgID": "[email protected]", | ||
"PkgName": "example-lib", | ||
"InstalledVersion": "1.2.3", | ||
"FixedVersion": "1.2.4", | ||
"Severity": "MEDIUM", | ||
"Description": "A vulnerability that allows unauthorized access.", | ||
"PrimaryURL": "https://example.com/CVE-2023-0002" | ||
}, | ||
{ | ||
"VulnerabilityID": "CVE-2023-0003", | ||
"PkgID": "[email protected]", | ||
"PkgName": "example-lib", | ||
"InstalledVersion": "2.3.4", | ||
"FixedVersion": "2.3.5", | ||
"Severity": "HIGH", | ||
"Description": "A vulnerability that could lead to remote code execution.", | ||
"PrimaryURL": "https://example.com/CVE-2023-0003" | ||
}, | ||
{ | ||
"VulnerabilityID": "CVE-2023-0004", | ||
"PkgID": "[email protected]", | ||
"PkgName": "example-lib", | ||
"InstalledVersion": "3.0.0", | ||
"FixedVersion": "3.0.1", | ||
"Severity": "HIGH", | ||
"Description": "A random test vulnerability with unspecified impact.", | ||
"PrimaryURL": "https://example.com/CVE-2023-0004" | ||
}, | ||
{ | ||
"VulnerabilityID": "CVE-2023-0005", | ||
"PkgID": "[email protected]", | ||
"PkgName": "example-lib", | ||
"InstalledVersion": "3.1.0", | ||
"FixedVersion": "3.1.1", | ||
"Severity": "CRITICAL", | ||
"Description": "Another random test vulnerability for testing purposes.", | ||
"PrimaryURL": "https://example.com/CVE-2023-0005" | ||
} | ||
] | ||
} | ||
] | ||
}""".stripIndent() | ||
|
||
when: | ||
def result = TrivyResultProcessor.process(trivyDockerResulJson) | ||
result = TrivyResultProcessor.filter(result, 4) | ||
|
||
then: | ||
result.size() == 4 | ||
result[0].severity == "CRITICAL" | ||
result[0].id == "CVE-2023-0005" | ||
result[1].severity == "HIGH" | ||
result[1].id == "CVE-2023-0003" | ||
result[2].severity == "HIGH" | ||
result[2].id == "CVE-2023-0004" | ||
result[3].severity == "MEDIUM" | ||
result[3].id == "CVE-2023-0002" | ||
} | ||
|
||
def "process should throw exception if json is not correct"() { | ||
when: | ||
TrivyResultProcessor.process("invalid json") | ||
|