|
18 | 18 | STACK_HAWK_SUBSET_FILENAME = get_unit_tests_scans_path("stackhawk") / "stackhawk_many_vul_without_duplicated_findings_subset.json" |
19 | 19 | STACK_HAWK_SCAN_TYPE = "StackHawk HawkScan" |
20 | 20 |
|
| 21 | +NPM_AUDIT_NO_VULN_FILENAME = get_unit_tests_scans_path("npm_audit") / "no_vuln.json" |
| 22 | +NPM_AUDIT_SCAN_TYPE = "NPM Audit Scan" |
| 23 | + |
21 | 24 |
|
22 | 25 | class TestDojoImporterPerformance(DojoTestCase): |
23 | 26 |
|
24 | 27 | def setUp(self): |
25 | 28 | super().setUp() |
26 | 29 | self.system_settings(enable_webhooks_notifications=False) |
27 | 30 | self.system_settings(enable_product_grade=False) |
| 31 | + self.system_settings(enable_github=False) |
28 | 32 |
|
29 | 33 | @contextmanager |
30 | 34 | def assertNumAsyncTask(self, num): |
@@ -66,6 +70,30 @@ def import_reimport_performance(self, expected_num_queries1, expected_num_async_ |
66 | 70 | lead, _ = User.objects.get_or_create(username="admin") |
67 | 71 | environment, _ = Development_Environment.objects.get_or_create(name="Development") |
68 | 72 |
|
| 73 | + # first we do a bogus import to make sure any caches are loaded. |
| 74 | + # without this the number of queries will be higher as the audit log will load content_type ids from the db |
| 75 | + |
| 76 | + engagement_dummy, _created = Engagement.objects.get_or_create( |
| 77 | + name="Test Create Dummy Engagement", |
| 78 | + product=product, |
| 79 | + target_start=timezone.now(), |
| 80 | + target_end=timezone.now(), |
| 81 | + ) |
| 82 | + import_options = { |
| 83 | + "user": lead, |
| 84 | + "lead": lead, |
| 85 | + "scan_date": None, |
| 86 | + "environment": environment, |
| 87 | + "minimum_severity": "Info", |
| 88 | + "active": True, |
| 89 | + "verified": True, |
| 90 | + "sync": True, |
| 91 | + "scan_type": NPM_AUDIT_SCAN_TYPE, |
| 92 | + "engagement": engagement_dummy, |
| 93 | + } |
| 94 | + importer = DefaultImporter(**import_options) |
| 95 | + test, _, _len_new_findings, _len_closed_findings, _, _, _ = importer.process_scan(NPM_AUDIT_NO_VULN_FILENAME.open(encoding="utf-8")) |
| 96 | + |
69 | 97 | # first import the subset which missed one finding and a couple of endpoints on some of the findings |
70 | 98 | with ( |
71 | 99 | self.subTest("import1"), impersonate(Dojo_User.objects.get(username="admin")), |
@@ -132,7 +160,7 @@ def import_reimport_performance(self, expected_num_queries1, expected_num_async_ |
132 | 160 |
|
133 | 161 | def test_import_reimport_reimport_performance(self): |
134 | 162 | self.import_reimport_performance( |
135 | | - expected_num_queries1=603, |
| 163 | + expected_num_queries1=605, |
136 | 164 | expected_num_async_tasks1=15, |
137 | 165 | expected_num_queries2=489, |
138 | 166 | expected_num_async_tasks2=23, |
@@ -169,7 +197,7 @@ def test_import_reimport_reimport_performance_no_async_with_product_grading(self |
169 | 197 | """ |
170 | 198 | self.system_settings(enable_product_grade=True) |
171 | 199 | self.import_reimport_performance( |
172 | | - expected_num_queries1=673, |
| 200 | + expected_num_queries1=675, |
173 | 201 | expected_num_async_tasks1=25, |
174 | 202 | expected_num_queries2=544, |
175 | 203 | expected_num_async_tasks2=30, |
|
0 commit comments