Skip to content

Commit 31eab9b

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

9 files changed

Lines changed: 27 additions & 18 deletions

File tree

docs/content/en/connecting_your_tools/parsers/file/cyberwatch.md renamed to docs/content/en/connecting_your_tools/parsers/file/cyberwatch_galeax.md

File renamed without changes.

dojo/settings/settings.dist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ def saml2_attrib_map_format(din):
13461346
"KrakenD Audit Scan": ["description", "mitigation", "severity"],
13471347
"Red Hat Satellite": ["description", "severity"],
13481348
"Qualys Hacker Guardian Scan": ["title", "severity", "description"],
1349-
"Cyberwatch scan": ["title", "description", "severity"],
1349+
"Cyberwatch scan (Galeax)": ["title", "description", "severity"],
13501350
}
13511351

13521352
# Override the hardcoded settings here via the env var
@@ -1417,7 +1417,7 @@ def saml2_attrib_map_format(din):
14171417
"Threagile risks report": True,
14181418
"HCL AppScan on Cloud SAST XML": True,
14191419
"AWS Inspector2 Scan": True,
1420-
"Cyberwatch scan": True,
1420+
"Cyberwatch scan (Galeax)": True,
14211421
}
14221422

14231423
# List of fields that are known to be usable in hash_code computation)
@@ -1599,7 +1599,7 @@ def saml2_attrib_map_format(din):
15991599
"PTART Report": DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL,
16001600
"Red Hat Satellite": DEDUPE_ALGO_HASH_CODE,
16011601
"Qualys Hacker Guardian Scan": DEDUPE_ALGO_HASH_CODE,
1602-
"Cyberwatch scan": DEDUPE_ALGO_HASH_CODE,
1602+
"Cyberwatch scan (Galeax)": DEDUPE_ALGO_HASH_CODE,
16031603
}
16041604

16051605
# Override the hardcoded settings here via the env var
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}")
File renamed without changes.
File renamed without changes.
File renamed without changes.

unittests/scans/cyberwatch/one_security_issue.json renamed to unittests/scans/cyberwatch_galeax/one_security_issue.json

File renamed without changes.

unittests/tools/test_cyberwatch_parser.py renamed to unittests/tools/test_cyberwatch_galeax_parser.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33

44
from dojo.models import Test
5-
from dojo.tools.cyberwatch.parser import CyberwatchParser
5+
from dojo.tools.cyberwatch_galeax.parser import CyberwatchParser
66

77

88
class TestCyberwatchParser(unittest.TestCase):
@@ -12,76 +12,85 @@ def setUp(self):
1212
self.test = Test()
1313

1414
def test_no_findings(self):
15-
testfile = Path("unittests/scans/cyberwatch/no_findings.json")
15+
testfile = Path("unittests/scans/cyberwatch_galeax/no_findings.json")
1616
with testfile.open("rb") as file:
1717
findings = self.parser.get_findings(file, self.test)
1818
self.assertEqual(0, len(findings))
1919

2020
def test_one_security_issue(self):
21-
testfile = Path("unittests/scans/cyberwatch/one_security_issue.json")
21+
testfile = Path("unittests/scans/cyberwatch_galeax/one_security_issue.json")
2222
with testfile.open("rb") as file:
2323
findings = self.parser.get_findings(file, self.test)
2424
self.assertEqual(1, len(findings))
2525

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))
3335
self.assertEqual("No mitigation provided.", finding.mitigation)
3436
self.assertEqual("", finding.references)
3537

3638
def test_one_cve(self):
37-
testfile = Path("unittests/scans/cyberwatch/one_cve.json")
39+
testfile = Path("unittests/scans/cyberwatch_galeax/one_cve.json")
3840
with testfile.open("rb") as file:
3941
findings = self.parser.get_findings(file, self.test)
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(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

5761
def test_mixed_findings(self):
58-
testfile = Path("unittests/scans/cyberwatch/mixed_findings.json")
62+
testfile = Path("unittests/scans/cyberwatch_galeax/mixed_findings.json")
5963
with testfile.open("rb") as file:
6064
findings = self.parser.get_findings(file, self.test)
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(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)