@@ -8,7 +8,6 @@ def sample_path(file_name):
88
99
1010class TestOpenreportsParser (DojoTestCase ):
11-
1211 def test_no_results (self ):
1312 with sample_path ("openreports_no_results.json" ).open (encoding = "utf-8" ) as test_file :
1413 parser = OpenreportsParser ()
@@ -19,7 +18,7 @@ def test_single_report(self):
1918 with sample_path ("openreports_single_report.json" ).open (encoding = "utf-8" ) as test_file :
2019 parser = OpenreportsParser ()
2120 findings = parser .get_findings (test_file , Test ())
22- self .assertEqual (len (findings ), 2 )
21+ self .assertEqual (len (findings ), 3 )
2322
2423 # Test first finding (warn/low severity)
2524 finding1 = findings [0 ]
@@ -35,6 +34,9 @@ def test_single_report(self):
3534 self .assertTrue (finding1 .fix_available )
3635 self .assertEqual (1 , len (finding1 .unsaved_vulnerability_ids ))
3736 self .assertEqual ("CVE-2025-9232" , finding1 .unsaved_vulnerability_ids [0 ])
37+ self .assertEqual (
38+ "b1fcca57-2efd-44d3-89e9-949e29b61936:CVE-2025-9232:libcrypto3" , finding1 .unique_id_from_tool
39+ )
3840 self .assertIn ("vulnerability scan" , finding1 .tags )
3941 self .assertIn ("image-scanner" , finding1 .tags )
4042 self .assertIn ("Deployment" , finding1 .tags )
@@ -53,31 +55,61 @@ def test_single_report(self):
5355 self .assertTrue (finding2 .fix_available )
5456 self .assertEqual (1 , len (finding2 .unsaved_vulnerability_ids ))
5557 self .assertEqual ("CVE-2025-47907" , finding2 .unsaved_vulnerability_ids [0 ])
58+ self .assertEqual ("b1fcca57-2efd-44d3-89e9-949e29b61936:CVE-2025-47907:stdlib" , finding2 .unique_id_from_tool )
59+
60+ # Test third finding (non-CVE policy, fail/low severity)
61+ finding3 = findings [2 ]
62+ self .assertEqual ("CIS-BENCH-001: Missing security headers in HTTP response" , finding3 .title )
63+ self .assertEqual ("Low" , finding3 .severity )
64+ self .assertEqual ("web-server" , finding3 .component_name )
65+ self .assertEqual ("N/A" , finding3 .component_version )
66+ self .assertEqual ("Upgrade to version: Configure proper security headers" , finding3 .mitigation )
67+ self .assertEqual ("https://www.cisecurity.org/benchmark/docker" , finding3 .references )
68+ self .assertEqual ("test/Deployment/test-app" , finding3 .service )
69+ self .assertTrue (finding3 .active )
70+ self .assertTrue (finding3 .verified )
71+ self .assertTrue (finding3 .fix_available )
72+ # Non-CVE policies should not have vulnerability IDs
73+ self .assertIsNone (finding3 .unsaved_vulnerability_ids )
74+ self .assertEqual (
75+ "b1fcca57-2efd-44d3-89e9-949e29b61936:CIS-BENCH-001:web-server" , finding3 .unique_id_from_tool
76+ )
77+ self .assertIn ("compliance check" , finding3 .tags )
78+ self .assertIn ("compliance-scanner" , finding3 .tags )
79+ self .assertIn ("Deployment" , finding3 .tags )
5680
5781 def test_list_format (self ):
5882 with sample_path ("openreports_list_format.json" ).open (encoding = "utf-8" ) as test_file :
5983 parser = OpenreportsParser ()
6084 findings = parser .get_findings (test_file , Test ())
61- self .assertEqual (len (findings ), 2 )
85+ self .assertEqual (len (findings ), 3 )
6286
6387 # Verify findings from different reports have different services
6488 services = {finding .service for finding in findings }
6589 self .assertEqual (len (services ), 2 )
6690 self .assertIn ("test/Deployment/app1" , services )
6791 self .assertIn ("test/Deployment/app2" , services )
6892
69- # Verify CVE IDs
70- cve_ids = [finding .unsaved_vulnerability_ids [0 ] for finding in findings ]
93+ # Verify CVE IDs - only findings with CVE policies should have vulnerability IDs
94+ cve_findings = [finding for finding in findings if finding .unsaved_vulnerability_ids ]
95+ self .assertEqual (len (cve_findings ), 2 )
96+ cve_ids = [finding .unsaved_vulnerability_ids [0 ] for finding in cve_findings ]
7197 self .assertIn ("CVE-2025-9232" , cve_ids )
7298 self .assertIn ("CVE-2025-47907" , cve_ids )
7399
100+ # Verify there's at least one non-CVE finding
101+ non_cve_findings = [finding for finding in findings if not finding .unsaved_vulnerability_ids ]
102+ self .assertEqual (len (non_cve_findings ), 1 )
103+ non_cve_finding = non_cve_findings [0 ]
104+ self .assertEqual ("SECURITY-001: Container running as root user" , non_cve_finding .title )
105+
74106 def test_parser_metadata (self ):
75107 parser = OpenreportsParser ()
76108 scan_types = parser .get_scan_types ()
77- self .assertEqual (["OpenReports Scan " ], scan_types )
109+ self .assertEqual (["OpenReports" ], scan_types )
78110
79- label = parser .get_label_for_scan_types ("OpenReports Scan " )
80- self .assertEqual ("OpenReports Scan " , label )
111+ label = parser .get_label_for_scan_types ("OpenReports" )
112+ self .assertEqual ("OpenReports" , label )
81113
82- description = parser .get_description_for_scan_types ("OpenReports Scan " )
83- self .assertEqual ("Import OpenReports JSON scan report." , description )
114+ description = parser .get_description_for_scan_types ("OpenReports" )
115+ self .assertEqual ("Import OpenReports JSON report." , description )
0 commit comments