Skip to content

Commit ff33873

Browse files
test: add background param to import all unit tests command
1 parent 861973b commit ff33873

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

dojo/management/commands/import_all_unittest_scans.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from inspect import isclass
88
from pathlib import Path
99

10+
from django.conf import settings
1011
from django.core.management.base import BaseCommand
1112
from django.urls import reverse
1213
from django.utils import timezone
@@ -43,6 +44,7 @@ def add_arguments(self, parser):
4344
parser.add_argument("--engagements-per-product", type=int, default=50, help="Number of engagements per product before a new product is created, defaults to 50")
4445
parser.add_argument("--products-per-product-type", type=int, default=15, help="Number of products per product type before a new product type is created, defaults to 15")
4546
parser.add_argument("--number-of-runs", type=int, default=1, help="Number of times to run the import of all sample scans, defaults to 1")
47+
parser.add_argument("--background-import", action="store_true", default=False, help="Use async/background imports (Pro feature, default: False)")
4648

4749
def get_test_admin(self, *args, **kwargs):
4850
return User.objects.get(username="admin")
@@ -64,7 +66,7 @@ def import_scan(self, payload, expected_http_status_code):
6466
def import_scan_with_params(self, filename, scan_type="ZAP Scan", engagement=1, minimum_severity="Low", *, active=True, verified=False,
6567
push_to_jira=None, endpoint_to_add=None, tags=None, close_old_findings=False, group_by=None, engagement_name=None,
6668
product_name=None, product_type_name=None, auto_create_context=None, expected_http_status_code=201, test_title=None,
67-
scan_date=None, service=None, force_active=True, force_verified=True):
69+
scan_date=None, service=None, force_active=True, force_verified=True, background_import=False):
6870

6971
with (Path("unittests/scans") / filename).open(encoding="utf-8") as testfile:
7072
payload = {
@@ -73,6 +75,7 @@ def import_scan_with_params(self, filename, scan_type="ZAP Scan", engagement=1,
7375
"file": testfile,
7476
"version": "1.0.1",
7577
"close_old_findings": close_old_findings,
78+
"background_import": background_import,
7679
}
7780

7881
if active is not None:
@@ -119,7 +122,7 @@ def import_scan_with_params(self, filename, scan_type="ZAP Scan", engagement=1,
119122

120123
return self.import_scan(payload, expected_http_status_code)
121124

122-
def import_all_unittest_scans(self, product_name_prefix=None, tests_per_engagement=10, engagements_per_product=50, products_per_product_type=15, *, include_very_big_scans=False, **kwargs):
125+
def import_all_unittest_scans(self, product_name_prefix=None, tests_per_engagement=10, engagements_per_product=50, products_per_product_type=15, *, include_very_big_scans=False, background_import=False, **kwargs):
123126
logger.info("product_name_prefix: %s, tests_per_engagement: %s, engagements_per_product: %s, products_per_product_type: %s", product_name_prefix, tests_per_engagement, engagements_per_product, products_per_product_type)
124127
product_type_prefix = "Sample scans " + datetime.now().strftime("%Y-%m-%d %H:%M:%S")
125128
product_type_index = 1
@@ -172,6 +175,7 @@ def import_all_unittest_scans(self, product_name_prefix=None, tests_per_engageme
172175
filename=module_name + "/" + scan_file.name,
173176
scan_type=parser.get_scan_types()[0],
174177
engagement=eng.id,
178+
background_import=background_import,
175179
)
176180
# logger.debug(f"Result of import: {result}")
177181
# raise Exception(f"Scan {scan_file.name} is not expected to be imported, but it was.")
@@ -191,6 +195,7 @@ def import_all_unittest_scans(self, product_name_prefix=None, tests_per_engageme
191195
logger.error("Error importing scan %s: %s", scan, message)
192196

193197
def handle(self, *args, **options):
198+
settings.SECURE_SSL_REDIRECT = False
194199
logger.info("EXPERIMENTAL: This command may be changed/deprecated/removed without prior notice.")
195200
for i in range(options.get("number_of_runs", 1)):
196201
product_name_prefix = options.get("product_name_prefix")
@@ -203,4 +208,5 @@ def handle(self, *args, **options):
203208
engagements_per_product=options.get("engagements_per_product"),
204209
products_per_product_type=options.get("products_per_product_type"),
205210
include_very_big_scans=options.get("include_very_big_scans"),
211+
background_import=options.get("background_import"),
206212
)

0 commit comments

Comments
 (0)