Skip to content

Commit 412bada

Browse files
committed
update invicti test
1 parent 114c1ed commit 412bada

1 file changed

Lines changed: 55 additions & 4 deletions

File tree

unittests/tools/test_netsparker_parser.py

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
from django.test import override_settings
3+
24
from dojo.models import Test
35
from dojo.tools.netsparker.parser import NetsparkerParser
46
from unittests.dojo_test_case import DojoTestCase, get_unit_tests_scans_path
@@ -7,6 +9,7 @@
79
class TestNetsparkerParser(DojoTestCase):
810

911
def test_parse_file_with_one_finding(self):
12+
"""With USE_FIRST_SEEN=False (default), date should come from Generated (scan date)."""
1013
with (get_unit_tests_scans_path("netsparker") / "netsparker_one_finding.json").open(encoding="utf-8") as testfile:
1114
parser = NetsparkerParser()
1215
findings = parser.get_findings(testfile, Test())
@@ -16,15 +19,32 @@ def test_parse_file_with_one_finding(self):
1619
finding = findings[0]
1720
self.assertEqual("Medium", finding.severity)
1821
self.assertEqual(16, finding.cwe)
19-
self.assertEqual("16/06/2021", finding.date.strftime("%d/%m/%Y"))
22+
# Generated date is "25/06/2021 09:59 AM"
23+
self.assertEqual("25/06/2021", finding.date.strftime("%d/%m/%Y"))
2024
self.assertIsNotNone(finding.description)
2125
self.assertGreater(len(finding.description), 0)
2226
self.assertEqual("CVSS:3.0/AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:N/A:N/E:H/RL:O/RC:C", finding.cvssv3)
2327
self.assertEqual(1, len(self.get_unsaved_locations(finding)))
2428
location = self.get_unsaved_locations(finding)[0]
2529
self.assertEqual(str(location), "http://php.testsparker.com/auth/login.php")
2630

31+
@override_settings(USE_FIRST_SEEN=True)
32+
def test_parse_file_with_one_finding_first_seen(self):
33+
"""With USE_FIRST_SEEN=True, date should come from FirstSeenDate."""
34+
with (get_unit_tests_scans_path("netsparker") / "netsparker_one_finding.json").open(encoding="utf-8") as testfile:
35+
parser = NetsparkerParser()
36+
findings = parser.get_findings(testfile, Test())
37+
self.assertEqual(1, len(findings))
38+
self.validate_locations(findings)
39+
with self.subTest(i=0):
40+
finding = findings[0]
41+
self.assertEqual("Medium", finding.severity)
42+
self.assertEqual(16, finding.cwe)
43+
# FirstSeenDate is "16/06/2021 12:30 PM"
44+
self.assertEqual("16/06/2021", finding.date.strftime("%d/%m/%Y"))
45+
2746
def test_parse_file_with_multiple_finding(self):
47+
"""With USE_FIRST_SEEN=False (default), dates should come from Generated (scan date)."""
2848
with (get_unit_tests_scans_path("netsparker") / "netsparker_many_findings.json").open(encoding="utf-8") as testfile:
2949
parser = NetsparkerParser()
3050
findings = parser.get_findings(testfile, Test())
@@ -34,7 +54,8 @@ def test_parse_file_with_multiple_finding(self):
3454
finding = findings[0]
3555
self.assertEqual("Medium", finding.severity)
3656
self.assertEqual(16, finding.cwe)
37-
self.assertEqual("16/06/2021", finding.date.strftime("%d/%m/%Y"))
57+
# Generated date is "25/06/2021 10:00 AM"
58+
self.assertEqual("25/06/2021", finding.date.strftime("%d/%m/%Y"))
3859
self.assertIsNotNone(finding.description)
3960
self.assertGreater(len(finding.description), 0)
4061
self.assertEqual("CVSS:3.0/AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:N/A:N/E:H/RL:O/RC:C", finding.cvssv3)
@@ -46,7 +67,7 @@ def test_parse_file_with_multiple_finding(self):
4667
finding = findings[1]
4768
self.assertEqual("Critical", finding.severity)
4869
self.assertEqual(89, finding.cwe)
49-
self.assertEqual("16/06/2021", finding.date.strftime("%d/%m/%Y"))
70+
self.assertEqual("25/06/2021", finding.date.strftime("%d/%m/%Y"))
5071
self.assertIsNotNone(finding.description)
5172
self.assertGreater(len(finding.description), 0)
5273
self.assertEqual("CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H", finding.cvssv3)
@@ -58,14 +79,30 @@ def test_parse_file_with_multiple_finding(self):
5879
finding = findings[2]
5980
self.assertEqual("Medium", finding.severity)
6081
self.assertEqual(205, finding.cwe)
61-
self.assertEqual("15/06/2021", finding.date.strftime("%d/%m/%Y"))
82+
self.assertEqual("25/06/2021", finding.date.strftime("%d/%m/%Y"))
6283
self.assertIsNotNone(finding.description)
6384
self.assertGreater(len(finding.description), 0)
6485
self.assertEqual("CVSS:3.0/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N/E:H/RL:O/RC:C", finding.cvssv3)
6586
self.assertEqual(1, len(self.get_unsaved_locations(finding)))
6687
location = self.get_unsaved_locations(finding)[0]
6788
self.assertEqual(str(location), "http://php.testsparker.com")
6889

90+
@override_settings(USE_FIRST_SEEN=True)
91+
def test_parse_file_with_multiple_finding_first_seen(self):
92+
"""With USE_FIRST_SEEN=True, dates should come from FirstSeenDate."""
93+
with (get_unit_tests_scans_path("netsparker") / "netsparker_many_findings.json").open(encoding="utf-8") as testfile:
94+
parser = NetsparkerParser()
95+
findings = parser.get_findings(testfile, Test())
96+
self.assertEqual(16, len(findings))
97+
with self.subTest(i=0):
98+
finding = findings[0]
99+
# FirstSeenDate is "16/06/2021 12:30 PM"
100+
self.assertEqual("16/06/2021", finding.date.strftime("%d/%m/%Y"))
101+
with self.subTest(i=2):
102+
finding = findings[2]
103+
# FirstSeenDate is "15/06/2021 01:44 PM"
104+
self.assertEqual("15/06/2021", finding.date.strftime("%d/%m/%Y"))
105+
69106
def test_parse_file_issue_9816(self):
70107
with (get_unit_tests_scans_path("netsparker") / "issue_9816.json").open(encoding="utf-8") as testfile:
71108
parser = NetsparkerParser()
@@ -91,6 +128,7 @@ def test_parse_file_issue_10311(self):
91128
self.assertEqual("03/02/2019", finding.date.strftime("%d/%m/%Y"))
92129

93130
def test_parse_file_issue_11020(self):
131+
"""With USE_FIRST_SEEN=False (default), date should come from Generated (scan date)."""
94132
with (get_unit_tests_scans_path("netsparker") / "issue_11020.json").open(encoding="utf-8") as testfile:
95133
parser = NetsparkerParser()
96134
findings = parser.get_findings(testfile, Test())
@@ -100,4 +138,17 @@ def test_parse_file_issue_11020(self):
100138
finding = findings[0]
101139
self.assertEqual("Low", finding.severity)
102140
self.assertEqual(205, finding.cwe)
141+
# Generated date is "2024-10-08 02:33 PM"
142+
self.assertEqual("08/10/2024", finding.date.strftime("%d/%m/%Y"))
143+
144+
@override_settings(USE_FIRST_SEEN=True)
145+
def test_parse_file_issue_11020_first_seen(self):
146+
"""With USE_FIRST_SEEN=True, date should come from FirstSeenDate."""
147+
with (get_unit_tests_scans_path("netsparker") / "issue_11020.json").open(encoding="utf-8") as testfile:
148+
parser = NetsparkerParser()
149+
findings = parser.get_findings(testfile, Test())
150+
self.assertEqual(3, len(findings))
151+
with self.subTest(i=0):
152+
finding = findings[0]
153+
# FirstSeenDate is "2024-07-23 05:32 PM"
103154
self.assertEqual("23/07/2024", finding.date.strftime("%d/%m/%Y"))

0 commit comments

Comments
 (0)