Skip to content

Commit c7ab425

Browse files
committed
update
1 parent cbb8c4d commit c7ab425

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

dojo/tools/anchore_grype/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,15 @@ def get_findings(self, file, test):
122122

123123
finding_mitigation = None
124124
fix_available = False
125+
fix_version = None
125126
if vuln_fix_versions:
126127
fix_available = True
127128
finding_mitigation = "Upgrade to version:"
128129
if len(vuln_fix_versions) == 1:
129130
finding_mitigation += f" {vuln_fix_versions[0]}"
131+
fix_version = vuln_fix_versions[0]
130132
else:
133+
fix_version = ", ".join(vuln_fix_versions)
131134
for fix_version in vuln_fix_versions:
132135
finding_mitigation += f"\n- {fix_version}"
133136

@@ -203,6 +206,7 @@ def get_findings(self, file, test):
203206
nb_occurences=1,
204207
file_path=file_path,
205208
fix_available=fix_available,
209+
fix_version=fix_version,
206210
)
207211
dupes[dupe_key].unsaved_vulnerability_ids = vulnerability_ids
208212

unittests/tools/test_anchore_grype_parser.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,22 @@ def test_grype_issue_9618(self):
265265
parser = AnchoreGrypeParser()
266266
findings = parser.get_findings(testfile, Test())
267267
self.assertEqual(35, len(findings))
268+
269+
def test_grype_fix_not_available(self):
270+
with (get_unit_tests_scans_path("anchore_grype") / "fix_not_available.json").open(encoding="utf-8") as testfile:
271+
parser = AnchoreGrypeParser()
272+
findings = parser.get_findings(testfile, Test())
273+
self.assertEqual(1, len(findings))
274+
self.assertEqual(findings[0].fix_available, False)
275+
self.assertEqual(findings[0].fix_version, None)
276+
277+
def test_grype_fix_available(self):
278+
with (get_unit_tests_scans_path("anchore_grype") / "fix_available.json").open(encoding="utf-8") as testfile:
279+
parser = AnchoreGrypeParser()
280+
findings = parser.get_findings(testfile, Test())
281+
self.assertEqual(1, len(findings))
268282
self.assertEqual(findings[0].fix_available, True)
283+
self.assertEqual(findings[0].fix_version, "1.2.3")
269284

270285
def test_grype_issue_9942(self):
271286
with (get_unit_tests_scans_path("anchore_grype") / "issue_9942.json").open(encoding="utf-8") as testfile:

0 commit comments

Comments
 (0)