11import datetime
22from datetime import datetime as date
33
4+ from django .test import override_settings
5+
46from dojo .models import Test
57from dojo .tools .acunetix .parser import AcunetixParser
68from unittests .dojo_test_case import DojoTestCase , get_unit_tests_scans_path
@@ -198,6 +200,7 @@ def test_parse_file_with_example_com(self):
198200 self .assertIsInstance (req_resp ["resp" ], str )
199201
200202 def test_parse_file_with_one_finding_acunetix360 (self ):
203+ """With USE_FIRST_SEEN=False (default), date should come from Generated (scan date)."""
201204 with (get_unit_tests_scans_path ("acunetix" ) / "acunetix360_one_finding.json" ).open (encoding = "utf-8" ) as testfile :
202205 parser = AcunetixParser ()
203206 findings = parser .get_findings (testfile , Test ())
@@ -213,9 +216,22 @@ def test_parse_file_with_one_finding_acunetix360(self):
213216 self .assertEqual (1 , len (self .get_unsaved_locations (finding )))
214217 location = self .get_unsaved_locations (finding )[0 ]
215218 self .assertEqual (str (location ), "http://php.testsparker.com/auth/login.php" )
216- self .assertEqual (finding .date , date (2021 , 6 , 16 , 12 , 30 ))
219+ # Generated date is "25/06/2021 09:59 AM" — with USE_FIRST_SEEN=False, FirstSeenDate is ignored
220+ self .assertEqual (finding .date , date (2021 , 6 , 25 , 9 , 59 ))
217221 self .assertIn ("https://online.acunetix360.com/issues/detail/735f4503-e9eb-4b4c-4306-ad49020a4c4b" , finding .references )
218222
223+ @override_settings (USE_FIRST_SEEN = True )
224+ def test_parse_file_with_one_finding_acunetix360_first_seen (self ):
225+ """With USE_FIRST_SEEN=True, date should come from FirstSeenDate."""
226+ with (get_unit_tests_scans_path ("acunetix" ) / "acunetix360_one_finding.json" ).open (encoding = "utf-8" ) as testfile :
227+ parser = AcunetixParser ()
228+ findings = parser .get_findings (testfile , Test ())
229+ self .assertEqual (1 , len (findings ))
230+ with self .subTest (i = 0 ):
231+ finding = findings [0 ]
232+ # FirstSeenDate is "16/06/2021 12:30 PM"
233+ self .assertEqual (finding .date , date (2021 , 6 , 16 , 12 , 30 ))
234+
219235 def test_parse_file_with_one_finding_false_positive (self ):
220236 with (get_unit_tests_scans_path ("acunetix" ) / "acunetix360_one_finding_false_positive.json" ).open (encoding = "utf-8" ) as testfile :
221237 parser = AcunetixParser ()
@@ -323,11 +339,25 @@ def test_parse_file_issue_10435(self):
323339 self .assertEqual (1 , len (findings ))
324340
325341 def test_parse_file_issue_11206 (self ):
342+ """With USE_FIRST_SEEN=False (default), date should come from Generated (scan date)."""
326343 with (get_unit_tests_scans_path ("acunetix" ) / "issue_11206.json" ).open (encoding = "utf-8" ) as testfile :
327344 parser = AcunetixParser ()
328345 findings = parser .get_findings (testfile , Test ())
329346 self .validate_locations (findings )
330347 self .assertEqual (1 , len (findings ))
331348 with self .subTest (i = 0 ):
332349 finding = findings [0 ]
350+ # Generated date is "25/06/2021 09:59 AM" — FirstSeenDate ignored when USE_FIRST_SEEN=False
351+ self .assertEqual (finding .date , date (2021 , 6 , 25 , 9 , 59 ))
352+
353+ @override_settings (USE_FIRST_SEEN = True )
354+ def test_parse_file_issue_11206_first_seen (self ):
355+ """With USE_FIRST_SEEN=True, date should come from FirstSeenDate."""
356+ with (get_unit_tests_scans_path ("acunetix" ) / "issue_11206.json" ).open (encoding = "utf-8" ) as testfile :
357+ parser = AcunetixParser ()
358+ findings = parser .get_findings (testfile , Test ())
359+ self .assertEqual (1 , len (findings ))
360+ with self .subTest (i = 0 ):
361+ finding = findings [0 ]
362+ # FirstSeenDate is "12/06/2021 12:30 PM"
333363 self .assertEqual (finding .date , date (2021 , 6 , 12 , 12 , 30 ))
0 commit comments