|
2 | 2 | from datetime import UTC, datetime, timedelta |
3 | 3 | from types import SimpleNamespace |
4 | 4 | from unittest.mock import MagicMock, call, patch |
| 5 | +from uuid import uuid4 |
5 | 6 |
|
6 | 7 | import pytest |
| 8 | +from api.db_utils import rls_transaction |
7 | 9 | from api.models import ( |
8 | 10 | AttackPathsScan, |
9 | 11 | Finding, |
|
15 | 17 | StatusChoices, |
16 | 18 | Task, |
17 | 19 | ) |
| 20 | +from django.db import DEFAULT_DB_ALIAS |
18 | 21 | from django_celery_results.models import TaskResult |
19 | 22 | from prowler.lib.check.models import Severity |
20 | 23 | from tasks.jobs.attack_paths import findings as findings_module |
@@ -2244,6 +2247,58 @@ def test_analysis_zero_exposed_resources(self): |
2244 | 2247 | class TestAttackPathsDbUtilsGraphDataReady: |
2245 | 2248 | """Tests for db_utils functions related to graph_data_ready lifecycle.""" |
2246 | 2249 |
|
| 2250 | + def test_database_defaults_allow_legacy_insert_without_cutover_columns( |
| 2251 | + self, tenants_fixture, providers_fixture, scans_fixture |
| 2252 | + ): |
| 2253 | + tenant = tenants_fixture[0] |
| 2254 | + provider = providers_fixture[0] |
| 2255 | + provider.provider = Provider.ProviderChoices.AWS |
| 2256 | + provider.save() |
| 2257 | + scan = scans_fixture[0] |
| 2258 | + scan.provider = provider |
| 2259 | + scan.save() |
| 2260 | + |
| 2261 | + attack_paths_scan_id = uuid4() |
| 2262 | + now = datetime.now(tz=UTC) |
| 2263 | + |
| 2264 | + with rls_transaction(str(tenant.id), using=DEFAULT_DB_ALIAS) as cursor: |
| 2265 | + cursor.execute( |
| 2266 | + """ |
| 2267 | + INSERT INTO attack_paths_scans ( |
| 2268 | + id, |
| 2269 | + inserted_at, |
| 2270 | + updated_at, |
| 2271 | + state, |
| 2272 | + progress, |
| 2273 | + graph_data_ready, |
| 2274 | + started_at, |
| 2275 | + tenant_id, |
| 2276 | + provider_id, |
| 2277 | + scan_id |
| 2278 | + ) |
| 2279 | + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) |
| 2280 | + """, |
| 2281 | + [ |
| 2282 | + attack_paths_scan_id, |
| 2283 | + now, |
| 2284 | + now, |
| 2285 | + StateChoices.SCHEDULED, |
| 2286 | + 0, |
| 2287 | + False, |
| 2288 | + now, |
| 2289 | + tenant.id, |
| 2290 | + provider.id, |
| 2291 | + scan.id, |
| 2292 | + ], |
| 2293 | + ) |
| 2294 | + |
| 2295 | + attack_paths_scan = AttackPathsScan.objects.get(id=attack_paths_scan_id) |
| 2296 | + |
| 2297 | + assert attack_paths_scan.is_migrated is False |
| 2298 | + assert ( |
| 2299 | + attack_paths_scan.sink_backend == AttackPathsScan.SinkBackendChoices.NEO4J |
| 2300 | + ) |
| 2301 | + |
2247 | 2302 | def test_create_attack_paths_scan_first_scan_defaults_to_false( |
2248 | 2303 | self, tenants_fixture, providers_fixture, scans_fixture |
2249 | 2304 | ): |
|
0 commit comments