Skip to content

Commit 6a87922

Browse files
test: regression test for #14363 via API serializer path
Add test_reimport_auto_create_does_not_close_findings_in_existing_test to ImportReimportTestAPI. It calls the reimport endpoint with auto_create_context=True and close_old_findings=True targeting a non-existing test title, verifying that the existing test's findings are not closed when the endpoint auto-creates a new test. This test would fail if the close_old_findings=False override in the serializer were reverted.
1 parent b5fa7aa commit 6a87922

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

unittests/test_import_reimport.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,63 @@ def test_reimport_set_scan_date_parser_sets_date(self):
25132513
date = findings["results"][0]["date"]
25142514
self.assertEqual(date, "2006-12-26")
25152515

2516+
def test_reimport_auto_create_does_not_close_findings_in_existing_test(self):
2517+
"""
2518+
Regression test for #14363: when reimport with auto_create_context=True creates
2519+
a brand new test, close_old_findings must not close findings from other tests in
2520+
the same engagement scope.
2521+
2522+
The serializer now forces close_old_findings=False when calling DefaultImporter
2523+
in this path. Without the fix, all 4 findings from the pre-existing test would be
2524+
incorrectly closed.
2525+
"""
2526+
product_type, _ = Product_Type.objects.get_or_create(name="PT CloseOld AutoCreate")
2527+
product, _ = Product.objects.get_or_create(
2528+
name="P CloseOld AutoCreate",
2529+
description="test",
2530+
prod_type=product_type,
2531+
)
2532+
engagement = Engagement.objects.create(
2533+
name="E CloseOld AutoCreate",
2534+
product=product,
2535+
target_start=timezone.now(),
2536+
target_end=timezone.now(),
2537+
)
2538+
2539+
acunetix_many_findings = get_unit_tests_scans_path("acunetix") / "many_findings.xml"
2540+
2541+
# Step 1: import 4 findings into an existing test (test1) in the engagement.
2542+
# minimum_severity="Info" is required to include all 4 findings in the file.
2543+
import1 = self.import_scan_with_params(
2544+
acunetix_many_findings,
2545+
scan_type=self.scan_type_acunetix,
2546+
engagement=engagement.id,
2547+
minimum_severity="Info",
2548+
)
2549+
test1_id = import1["test"]
2550+
self.assert_finding_count_json(4, self.get_test_findings_api(test1_id, active=True))
2551+
2552+
# Step 2: call the reimport endpoint with auto_create_context=True and a
2553+
# different test_title so a new test is created. close_old_findings=True
2554+
# is the value a caller would pass (and the reimport default); the serializer
2555+
# must suppress it when auto-creating a new test. The scan uses a different
2556+
# file so its hash codes don't overlap with test1's findings, meaning the
2557+
# bug would close all 4 of test1's findings if the fix were reverted.
2558+
self.reimport_scan_with_params(
2559+
None,
2560+
self.acunetix_file_name,
2561+
scan_type=self.scan_type_acunetix,
2562+
test_title="Brand New Test From Reimport",
2563+
product_name="P CloseOld AutoCreate",
2564+
engagement_name="E CloseOld AutoCreate",
2565+
product_type_name="PT CloseOld AutoCreate",
2566+
auto_create_context=True,
2567+
close_old_findings=True,
2568+
)
2569+
2570+
# Step 3: test1's 4 findings must all still be active
2571+
self.assert_finding_count_json(4, self.get_test_findings_api(test1_id, active=True))
2572+
25162573
@override_settings(
25172574
IMPORT_REIMPORT_DEDUPE_BATCH_SIZE=200,
25182575
IMPORT_REIMPORT_MATCH_BATCH_SIZE=200,

0 commit comments

Comments
 (0)