Skip to content

Commit c15a2f6

Browse files
committed
Fix parser name, Add assert on epss score and cwe
1 parent da491fb commit c15a2f6

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

dojo/tools/cyberwatch/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
class CyberwatchParser:
1515
def get_scan_types(self):
16-
return ["Cyberwatch scan"]
16+
return ["Cyberwatch scan (Galeax)"]
1717

1818
def get_label_for_scan_types(self, scan_type):
19-
return "Cyberwatch scan"
19+
return "Cyberwatch scan (Galeax)"
2020

2121
def get_description_for_scan_types(self, scan_type):
22-
return "Import Cyberwatch scan results in JSON format."
22+
return "Import Cyberwatch Cve and Security Issue data in JSON format, you can get the json from this tool : https://github.com/Galeax/Cyberwatch-API-DefectDojo"
2323

2424
def get_findings(self, filename, test):
2525
logger.debug(f"Starting get_findings with filename: {filename}")

unittests/tools/test_cyberwatch_parser.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def test_one_security_issue(self):
2626
finding = findings[0]
2727
self.assertEqual("Security Issue - Fingerprint Web Application Framework", finding.title)
2828
self.assertEqual("Info", finding.severity)
29-
# Expect both endpoints to have the same host as per new JSON
29+
# Validate endpoints
30+
for endpoint in finding.unsaved_endpoints:
31+
endpoint.clean()
3032
endpoint_hosts = [e.host for e in finding.unsaved_endpoints]
3133
self.assertEqual(2, len(endpoint_hosts))
3234
self.assertTrue(all(host == "host" for host in endpoint_hosts))
@@ -40,17 +42,19 @@ def test_one_cve(self):
4042
self.assertEqual(1, len(findings))
4143

4244
finding = findings[0]
43-
# When there are no products, title equals the CVE code
4445
self.assertEqual("CVE-2023-42366", finding.title)
4546
self.assertEqual("Medium", finding.severity)
4647
self.assertIn("CVSS Base vector:", finding.description)
4748
self.assertIn("CVE Published At: 2023-11-27T23:15:07.420+01:00", finding.description)
4849
self.assertIn("Exploit Code Maturity: proof_of_concept", finding.description)
49-
self.assertIn("EPSS: 0.00044", finding.description)
50-
# Since there are no updates_assets, mitigation is set to a string starting with "Fixed At:"
5150
self.assertTrue(finding.mitigation.startswith("Fixed At:"))
51+
self.assertEqual(float(0.00044), finding.epss_score)
5252
self.assertEqual("Updated At: 2024-12-06T14:15:19.530+01:00", finding.references)
5353
self.assertEqual(1, len(finding.unsaved_endpoints))
54+
self.assertEqual(787, finding.cwe)
55+
# Validate endpoints
56+
for endpoint in finding.unsaved_endpoints:
57+
endpoint.clean()
5458
endpoint_hosts = [e.host for e in finding.unsaved_endpoints]
5559
self.assertIn("computer_name", endpoint_hosts)
5660

@@ -61,27 +65,32 @@ def test_mixed_findings(self):
6165

6266
self.assertEqual(3, len(findings))
6367

64-
# Separate CVEs and Security Issues by title
6568
cve_findings = [f for f in findings if f.title.startswith("CVE-")]
6669
security_issues = [f for f in findings if f.title.startswith("Security Issue")]
6770

6871
self.assertEqual(1, len(cve_findings))
6972
self.assertEqual(2, len(security_issues))
7073

71-
# For the CVE finding, check expected properties
7274
cve_finding = cve_findings[0]
7375
self.assertEqual("CVE-2023-42366", cve_finding.title)
7476
self.assertEqual("Medium", cve_finding.severity)
7577
self.assertIn("CVE Published At:", cve_finding.description)
7678
self.assertIn("Updated At: 2024-12-06T14:15:19.530+01:00", cve_finding.references)
7779
self.assertEqual(1, len(cve_finding.unsaved_endpoints))
80+
self.assertEqual(float(0.00044), cve_finding.epss_score)
81+
self.assertEqual(787, cve_finding.cwe)
82+
# Validate endpoints
83+
for endpoint in cve_finding.unsaved_endpoints:
84+
endpoint.clean()
7885
self.assertIsNone(cve_finding.component_name)
7986

80-
# For each security issue, check that title and severity are valid and endpoints exist
8187
for sec_issue in security_issues:
8288
self.assertTrue(sec_issue.title.startswith("Security Issue - "))
8389
self.assertIn(sec_issue.severity, ["Critical", "High", "Medium", "Low", "Info"])
8490
self.assertTrue(len(sec_issue.unsaved_endpoints) > 0)
91+
# Validate endpoints
92+
for endpoint in sec_issue.unsaved_endpoints:
93+
endpoint.clean()
8594
self.assertIsNotNone(sec_issue.description)
8695
self.assertIsNotNone(sec_issue.mitigation)
8796
self.assertIsNotNone(sec_issue.impact)

0 commit comments

Comments
 (0)