|
| 1 | +from dojo.models import Test |
| 2 | +from dojo.tools.iriusrisk.parser import IriusriskParser |
| 3 | +from unittests.dojo_test_case import DojoTestCase, get_unit_tests_scans_path |
| 4 | + |
| 5 | + |
| 6 | +class TestIriusriskParser(DojoTestCase): |
| 7 | + |
| 8 | + def test_parse_no_findings(self): |
| 9 | + with (get_unit_tests_scans_path("iriusrisk") / "no_vuln.csv").open(encoding="utf-8") as testfile: |
| 10 | + parser = IriusriskParser() |
| 11 | + findings = parser.get_findings(testfile, Test()) |
| 12 | + self.assertEqual(0, len(findings)) |
| 13 | + |
| 14 | + def test_parse_one_finding(self): |
| 15 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 16 | + parser = IriusriskParser() |
| 17 | + findings = parser.get_findings(testfile, Test()) |
| 18 | + self.assertEqual(1, len(findings)) |
| 19 | + |
| 20 | + def test_parse_many_findings(self): |
| 21 | + with (get_unit_tests_scans_path("iriusrisk") / "many_vulns.csv").open(encoding="utf-8") as testfile: |
| 22 | + parser = IriusriskParser() |
| 23 | + findings = parser.get_findings(testfile, Test()) |
| 24 | + self.assertEqual(5, len(findings)) |
| 25 | + |
| 26 | + def test_finding_severity_high(self): |
| 27 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 28 | + parser = IriusriskParser() |
| 29 | + findings = parser.get_findings(testfile, Test()) |
| 30 | + self.assertEqual("High", findings[0].severity) |
| 31 | + |
| 32 | + def test_finding_severity_medium(self): |
| 33 | + with (get_unit_tests_scans_path("iriusrisk") / "many_vulns.csv").open(encoding="utf-8") as testfile: |
| 34 | + parser = IriusriskParser() |
| 35 | + findings = parser.get_findings(testfile, Test()) |
| 36 | + self.assertEqual("Medium", findings[1].severity) |
| 37 | + |
| 38 | + def test_finding_severity_low(self): |
| 39 | + with (get_unit_tests_scans_path("iriusrisk") / "many_vulns.csv").open(encoding="utf-8") as testfile: |
| 40 | + parser = IriusriskParser() |
| 41 | + findings = parser.get_findings(testfile, Test()) |
| 42 | + self.assertEqual("Low", findings[2].severity) |
| 43 | + |
| 44 | + def test_finding_severity_very_low_maps_to_info(self): |
| 45 | + with (get_unit_tests_scans_path("iriusrisk") / "many_vulns.csv").open(encoding="utf-8") as testfile: |
| 46 | + parser = IriusriskParser() |
| 47 | + findings = parser.get_findings(testfile, Test()) |
| 48 | + self.assertEqual("Info", findings[3].severity) |
| 49 | + |
| 50 | + def test_finding_title_truncated_at_150_chars(self): |
| 51 | + with (get_unit_tests_scans_path("iriusrisk") / "many_vulns.csv").open(encoding="utf-8") as testfile: |
| 52 | + parser = IriusriskParser() |
| 53 | + findings = parser.get_findings(testfile, Test()) |
| 54 | + self.assertLessEqual(len(findings[4].title), 150) |
| 55 | + self.assertTrue(findings[4].title.endswith("...")) |
| 56 | + |
| 57 | + def test_finding_title_not_truncated_when_short(self): |
| 58 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 59 | + parser = IriusriskParser() |
| 60 | + findings = parser.get_findings(testfile, Test()) |
| 61 | + self.assertEqual("Accessing functionality not properly constrained by ACLs", findings[0].title) |
| 62 | + |
| 63 | + def test_finding_component_name(self): |
| 64 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 65 | + parser = IriusriskParser() |
| 66 | + findings = parser.get_findings(testfile, Test()) |
| 67 | + self.assertEqual("Router", findings[0].component_name) |
| 68 | + |
| 69 | + def test_finding_description_contains_all_fields(self): |
| 70 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 71 | + parser = IriusriskParser() |
| 72 | + findings = parser.get_findings(testfile, Test()) |
| 73 | + desc = findings[0].description |
| 74 | + self.assertIn("Accessing functionality not properly constrained by ACLs", desc) |
| 75 | + self.assertIn("Router", desc) |
| 76 | + self.assertIn("Elevation of Privilege", desc) |
| 77 | + self.assertIn("Created by Rules Engine", desc) |
| 78 | + self.assertIn("High", desc) |
| 79 | + |
| 80 | + def test_finding_mitigation(self): |
| 81 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 82 | + parser = IriusriskParser() |
| 83 | + findings = parser.get_findings(testfile, Test()) |
| 84 | + self.assertEqual( |
| 85 | + "Planned mitigation: 0%. Mitigated: 0%. Unmitigated: 100%.", |
| 86 | + findings[0].mitigation, |
| 87 | + ) |
| 88 | + |
| 89 | + def test_finding_active_when_risk_not_very_low(self): |
| 90 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 91 | + parser = IriusriskParser() |
| 92 | + findings = parser.get_findings(testfile, Test()) |
| 93 | + self.assertTrue(findings[0].active) |
| 94 | + |
| 95 | + def test_finding_inactive_when_very_low(self): |
| 96 | + with (get_unit_tests_scans_path("iriusrisk") / "many_vulns.csv").open(encoding="utf-8") as testfile: |
| 97 | + parser = IriusriskParser() |
| 98 | + findings = parser.get_findings(testfile, Test()) |
| 99 | + self.assertFalse(findings[3].active) |
| 100 | + |
| 101 | + def test_finding_static_finding(self): |
| 102 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 103 | + parser = IriusriskParser() |
| 104 | + findings = parser.get_findings(testfile, Test()) |
| 105 | + self.assertTrue(findings[0].static_finding) |
| 106 | + self.assertFalse(findings[0].dynamic_finding) |
| 107 | + |
| 108 | + def test_finding_unique_id_from_tool(self): |
| 109 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 110 | + parser = IriusriskParser() |
| 111 | + findings = parser.get_findings(testfile, Test()) |
| 112 | + self.assertIsNotNone(findings[0].unique_id_from_tool) |
| 113 | + self.assertGreater(len(findings[0].unique_id_from_tool), 0) |
| 114 | + |
| 115 | + def test_finding_unique_id_is_consistent(self): |
| 116 | + """Parsing the same file twice should produce the same unique IDs.""" |
| 117 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 118 | + findings1 = IriusriskParser().get_findings(testfile, Test()) |
| 119 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 120 | + findings2 = IriusriskParser().get_findings(testfile, Test()) |
| 121 | + self.assertEqual(findings1[0].unique_id_from_tool, findings2[0].unique_id_from_tool) |
| 122 | + |
| 123 | + def test_finding_with_owner(self): |
| 124 | + with (get_unit_tests_scans_path("iriusrisk") / "many_vulns.csv").open(encoding="utf-8") as testfile: |
| 125 | + parser = IriusriskParser() |
| 126 | + findings = parser.get_findings(testfile, Test()) |
| 127 | + self.assertIn("John Smith", findings[4].description) |
| 128 | + |
| 129 | + def test_finding_with_empty_owner(self): |
| 130 | + with (get_unit_tests_scans_path("iriusrisk") / "one_vuln.csv").open(encoding="utf-8") as testfile: |
| 131 | + parser = IriusriskParser() |
| 132 | + findings = parser.get_findings(testfile, Test()) |
| 133 | + self.assertNotIn("None", findings[0].description) |
0 commit comments