Skip to content

Commit 0a0a460

Browse files
authored
Generic JSON: Explicitly process tags like other tools (#12056)
* Generic JSON: Explicitly process tags like other tools * Update tests * Remove extra cruft
1 parent 2bc529d commit 0a0a460

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

dojo/tools/generic/json_parser.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,26 @@ def _get_test_json(self, data):
1717
)
1818
test_internal.findings = []
1919
for item in data.get("findings", []):
20-
# remove endpoints of the dictionnary
20+
# remove endpoints from the dictionary
2121
unsaved_endpoints = None
2222
if "endpoints" in item:
2323
unsaved_endpoints = item["endpoints"]
2424
del item["endpoints"]
25-
# remove files of the dictionnary
25+
# remove files from the dictionary
2626
unsaved_files = None
2727
if "files" in item:
2828
unsaved_files = item["files"]
2929
del item["files"]
30-
# remove vulnerability_ids of the dictionnary
30+
# remove tags from the dictionary
31+
unsaved_tags = None
32+
if "tags" in item:
33+
unsaved_tags = item["tags"]
34+
del item["tags"]
35+
# remove vulnerability_ids from the dictionary
3136
unsaved_vulnerability_ids = None
3237
if "vulnerability_ids" in item:
3338
unsaved_vulnerability_ids = item["vulnerability_ids"]
3439
del item["vulnerability_ids"]
35-
3640
# check for required keys
3741
required = {"title", "severity", "description"}
3842
missing = sorted(required.difference(item))
@@ -115,6 +119,8 @@ def _get_test_json(self, data):
115119
FileUpload(title=title, file=ContentFile(data)).clean()
116120

117121
finding.unsaved_files = unsaved_files
122+
if unsaved_tags:
123+
finding.unsaved_tags = unsaved_tags
118124
if finding.cve:
119125
finding.unsaved_vulnerability_ids = [finding.cve]
120126
if unsaved_vulnerability_ids:

unittests/tools/test_generic_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ def test_parse_json(self):
452452
self.assertEqual("CVE-2020-36234", finding.unsaved_vulnerability_ids[0])
453453
self.assertEqual(261, finding.cwe)
454454
self.assertEqual("CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:L/I:L/A:N", finding.cvssv3)
455-
self.assertIn("security", finding.tags)
456-
self.assertIn("network", finding.tags)
455+
self.assertIn("security", finding.unsaved_tags)
456+
self.assertIn("network", finding.unsaved_tags)
457457
self.assertEqual("3287f2d0-554f-491b-8516-3c349ead8ee5", finding.unique_id_from_tool)
458458
self.assertEqual("TEST1", finding.vuln_id_from_tool)
459459
with self.subTest(i=1):
@@ -631,8 +631,8 @@ def test_parse_json_custom_test(self):
631631
self.assertEqual("CVE-2020-36234", finding.cve)
632632
self.assertEqual(261, finding.cwe)
633633
self.assertEqual("CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:L/I:L/A:N", finding.cvssv3)
634-
self.assertIn("security", finding.tags)
635-
self.assertIn("network", finding.tags)
634+
self.assertIn("security", finding.unsaved_tags)
635+
self.assertIn("network", finding.unsaved_tags)
636636
self.assertEqual("3287f2d0-554f-491b-8516-3c349ead8ee5", finding.unique_id_from_tool)
637637
self.assertEqual("TEST1", finding.vuln_id_from_tool)
638638

0 commit comments

Comments
 (0)