22from pathlib import Path
33
44from dojo .models import Test
5- from dojo .tools .cyberwatch .parser import CyberwatchParser
5+ from dojo .tools .cyberwatch_galeax .parser import CyberwatchParser
66
77
88class 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