|
11 | 11 | # from drf_spectacular.renderers import OpenApiJsonRenderer |
12 | 12 | from unittest.mock import ANY, MagicMock, call, patch |
13 | 13 |
|
| 14 | +from django.conf import settings |
14 | 15 | from django.contrib.auth.models import Permission |
15 | 16 | from django.test import tag as test_tag |
| 17 | +from django.test.utils import override_settings |
16 | 18 | from django.urls import reverse |
17 | 19 | from drf_spectacular.drainage import GENERATOR_STATS |
18 | 20 | from drf_spectacular.settings import spectacular_settings |
@@ -1245,6 +1247,63 @@ def test_duplicate(self): |
1245 | 1247 | self.assertFalse(result_json["duplicate"]) |
1246 | 1248 | self.assertIsNone(result_json["duplicate_finding"]) |
1247 | 1249 |
|
| 1250 | + def test_hash_code_includes_vulnerability_ids_on_create(self): |
| 1251 | + zap_fields = ["title", "cwe", "severity", "vulnerability_ids"] |
| 1252 | + current = dict(getattr(settings, "HASHCODE_FIELDS_PER_SCANNER", {})) |
| 1253 | + current["ZAP Scan"] = zap_fields |
| 1254 | + |
| 1255 | + with override_settings(HASHCODE_FIELDS_PER_SCANNER=current): |
| 1256 | + orig = Finding.objects.filter(test__test_type__name="ZAP Scan").first() |
| 1257 | + self.assertIsNotNone(orig, "Fixture must provide a ZAP Scan finding") |
| 1258 | + |
| 1259 | + cve_value = "CVE-9999-0001" |
| 1260 | + |
| 1261 | + model_clone = Finding( |
| 1262 | + test=orig.test, |
| 1263 | + title=orig.title, |
| 1264 | + date=orig.date, |
| 1265 | + cwe=orig.cwe, |
| 1266 | + severity=orig.severity, |
| 1267 | + description=orig.description, |
| 1268 | + mitigation=orig.mitigation, |
| 1269 | + impact=orig.impact, |
| 1270 | + references=orig.references, |
| 1271 | + active=orig.active, |
| 1272 | + verified=orig.verified, |
| 1273 | + false_p=orig.false_p, |
| 1274 | + duplicate=orig.duplicate, |
| 1275 | + out_of_scope=orig.out_of_scope, |
| 1276 | + under_review=orig.under_review, |
| 1277 | + under_defect_review=orig.under_defect_review, |
| 1278 | + numerical_severity=orig.numerical_severity, |
| 1279 | + reporter=orig.reporter, |
| 1280 | + static_finding=orig.static_finding, |
| 1281 | + dynamic_finding=orig.dynamic_finding, |
| 1282 | + file_path=orig.file_path, |
| 1283 | + line=orig.line, |
| 1284 | + ) |
| 1285 | + model_clone.unsaved_vulnerability_ids = [cve_value] |
| 1286 | + model_clone.save() |
| 1287 | + model_hash = model_clone.hash_code |
| 1288 | + |
| 1289 | + payload = self.payload.copy() |
| 1290 | + payload.update({ |
| 1291 | + "test": orig.test.id, |
| 1292 | + "title": orig.title, |
| 1293 | + "cwe": orig.cwe, |
| 1294 | + "severity": orig.severity, |
| 1295 | + "vulnerability_ids": [{"vulnerability_id": cve_value}], |
| 1296 | + }) |
| 1297 | + payload["found_by"] = [] |
| 1298 | + |
| 1299 | + response = self.client.post(self.url, payload, format="json") |
| 1300 | + self.assertEqual(201, response.status_code, response.content[:1000]) |
| 1301 | + new_id = response.data.get("id") |
| 1302 | + self.assertIsNotNone(new_id) |
| 1303 | + created = Finding.objects.get(id=new_id) |
| 1304 | + |
| 1305 | + self.assertEqual(model_hash, created.hash_code) |
| 1306 | + |
1248 | 1307 | def test_filter_steps_to_reproduce(self): |
1249 | 1308 | # Confirm initial data |
1250 | 1309 | result = self.client.get(self.url + "?steps_to_reproduce=lorem") |
|
0 commit comments