diff --git a/dojo/importers/base_importer.py b/dojo/importers/base_importer.py index 7734fc42d93..d6b63ee339c 100644 --- a/dojo/importers/base_importer.py +++ b/dojo/importers/base_importer.py @@ -463,6 +463,7 @@ def update_import_history( import_settings["close_old_findings"] = self.close_old_findings_toggle import_settings["push_to_jira"] = self.push_to_jira import_settings["tags"] = self.tags + import_settings["scan_date"] = self.scan_date.isoformat() if self.scan_date_override else None if settings.V3_FEATURE_LOCATIONS: # Add the list of locations that were added exclusively at import time if len(self.endpoints_to_add) > 0: diff --git a/unittests/test_update_import_history.py b/unittests/test_update_import_history.py index 8f263bb2a79..d4192281985 100644 --- a/unittests/test_update_import_history.py +++ b/unittests/test_update_import_history.py @@ -1,4 +1,6 @@ +import json import logging +from datetime import UTC, datetime from unittest.mock import patch from django.contrib.auth.models import User as DjangoUser @@ -149,3 +151,29 @@ def test_precheck_filters_out_deleted_findings_allows_successful_bulk(self): expected = (len(new_findings) - 1) + (len(closed_findings) - 1) created = Test_Import_Finding_Action.objects.filter(test_import=test_import).count() self.assertEqual(created, expected) + + def test_import_settings_scan_date_when_user_supplies_scan_date(self): + """When the user supplies a scan_date, import_settings should contain the ISO-formatted date.""" + user_scan_date = datetime(2025, 6, 15, 12, 0, 0, tzinfo=UTC) + self.importer.scan_date = user_scan_date + self.importer.scan_date_override = True + + new_findings = self._create_findings(1) + test_import = self.importer.update_import_history(new_findings=new_findings) + + settings = test_import.import_settings + # Verify import_settings is JSON-serializable (the original bug) + json.dumps(settings) + self.assertEqual(settings["scan_date"], user_scan_date.isoformat()) + + def test_import_settings_scan_date_when_no_scan_date_supplied(self): + """When no scan_date override is provided, import_settings should have scan_date as None.""" + self.importer.scan_date_override = False + + new_findings = self._create_findings(1) + test_import = self.importer.update_import_history(new_findings=new_findings) + + settings = test_import.import_settings + # Verify import_settings is JSON-serializable + json.dumps(settings) + self.assertIsNone(settings["scan_date"])