Skip to content

Commit 1088935

Browse files
committed
update
1 parent fcab916 commit 1088935

2 files changed

Lines changed: 28 additions & 40 deletions

File tree

dojo/tools/n0s1/parser.py

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33

44
from dojo.models import Finding
5-
from dojo.tools.parser_test import ParserTest
65

76

87
class N0s1Parser:
@@ -15,45 +14,34 @@ def get_label_for_scan_types(self, scan_type):
1514
def get_description_for_scan_types(self, scan_type):
1615
return "JSON output from the n0s1 scanner."
1716

18-
def get_tests(self, scan_type, handle):
19-
data = json.load(handle)
20-
tests = []
21-
22-
# Determine sub-scanner type based on platform or regex_config
23-
subscanner = "n0s1"
24-
findings = data.get("findings", {})
25-
platforms = {f.get("details", {}).get("platform", "") for f in findings.values()}
17+
def detect_subscanner(self, data):
18+
platforms = {f.get("details", {}).get("platform", "") for f in data.get("findings", {}).values()}
2619
if "Confluence" in platforms:
27-
subscanner = "n0s1 Confluence"
28-
elif "GitHub" in platforms:
29-
subscanner = "n0s1 GitHub"
30-
elif "GitLab" in platforms:
31-
subscanner = "n0s1 GitLab"
32-
# Add more platform checks as needed
33-
34-
test = ParserTest(
35-
name=subscanner,
36-
parser_type=subscanner,
37-
version=data.get("tool", {}).get("version", ""),
38-
description=f"Scan from {subscanner}",
39-
)
20+
return "n0s1 Confluence"
21+
if "GitHub" in platforms:
22+
return "n0s1 GitHub"
23+
if "GitLab" in platforms:
24+
return "n0s1 GitLab"
25+
return "n0s1"
4026

41-
test.findings = self.get_findings_from_data(data, test)
42-
tests.append(test)
43-
return tests
27+
def get_findings(self, scan_file, test):
28+
data = json.load(scan_file)
29+
subscanner = self.detect_subscanner(data)
30+
if hasattr(test, "test_type") and test.test_type:
31+
test.test_type.name = subscanner
32+
test.description = f"Scan from {subscanner}"
33+
return self.get_findings_from_data(data)
4434

45-
def get_findings_from_data(self, data, test):
35+
def get_findings_from_data(self, data):
4636
dupes = {}
4737
regex_configs = {}
4838
if "regex_config" in data and "rules" in data["regex_config"]:
4939
for rule in data["regex_config"]["rules"]:
5040
regex_configs[rule["id"]] = rule
51-
5241
for finding_id, finding_data in data.get("findings", {}).items():
5342
details = finding_data.get("details", {})
5443
regex_ref = details.get("matched_regex_config", {})
5544
regex_id = regex_ref.get("id")
56-
5745
regex_info = regex_configs.get(regex_id, {})
5846
merged_regex = {
5947
"id": regex_id,
@@ -79,7 +67,6 @@ def get_findings_from_data(self, data, test):
7967
continue
8068
finding = Finding(
8169
title=title,
82-
test=test,
8370
description=description,
8471
severity="High",
8572
dynamic_finding=True,
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
from dojo.models import Test
2+
import json
3+
4+
from dojo.models import Test, Test_Type
35
from dojo.tools.n0s1.parser import N0s1Parser
46
from unittests.dojo_test_case import DojoTestCase, get_unit_tests_scans_path
57

@@ -9,21 +11,20 @@ class TestN0s1Parser(DojoTestCase):
911
def test_n0s1_parser_with_multiple_findings(self):
1012
with (get_unit_tests_scans_path("n0s1") / "many_findings.json").open(encoding="utf-8") as testfile:
1113
parser = N0s1Parser()
12-
findings = parser.get_findings(testfile, Test())
14+
test_type = Test_Type(name="n0s1 Scanner")
15+
test = Test(test_type=test_type)
16+
findings = parser.get_findings(testfile, test)
1317
self.assertEqual(17, len(findings))
1418
finding = findings[0]
1519
self.assertEqual(finding.title, "AWS")
1620
self.assertIsNotNone(finding.description)
1721
self.assertTrue(finding.dynamic_finding)
22+
self.assertEqual(test.test_type.name, "n0s1 Confluence")
23+
self.assertEqual(test.description, "Scan from n0s1 Confluence")
1824

19-
def test_n0s1_get_tests_returns_correct_subscanner(self):
25+
def test_detect_subscanner_returns_correct_type(self):
2026
with (get_unit_tests_scans_path("n0s1") / "many_findings.json").open(encoding="utf-8") as testfile:
2127
parser = N0s1Parser()
22-
tests = parser.get_tests("n0s1 Scanner", testfile)
23-
self.assertEqual(1, len(tests))
24-
test = tests[0]
25-
self.assertEqual("n0s1 Confluence", test.name)
26-
self.assertEqual("n0s1 Confluence", test.parser_type)
27-
self.assertEqual("Scan from n0s1 Confluence", test.description)
28-
self.assertEqual(17, len(test.findings))
29-
self.assertTrue(all(f.dynamic_finding for f in test.findings))
28+
data = json.load(testfile)
29+
subscanner = parser.detect_subscanner(data)
30+
self.assertEqual("n0s1 Confluence", subscanner)

0 commit comments

Comments
 (0)