mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 04:21:52 +00:00
fix(findings): avoid backfill on empty scans (#8183)
This commit is contained in:
committed by
GitHub
parent
7eb08b0f14
commit
e7c2fa0699
@@ -6,6 +6,13 @@ All notable changes to the **Prowler API** are documented in this file.
|
||||
|
||||
---
|
||||
|
||||
## [v1.9.1] (Prowler v5.8.1)
|
||||
|
||||
### Fixed
|
||||
- Scan with no resources will not trigger legacy code for findings metadata [(#8183)](https://github.com/prowler-cloud/prowler/pull/8183)
|
||||
|
||||
---
|
||||
|
||||
## [v1.9.0] (Prowler v5.8.0)
|
||||
|
||||
### Added
|
||||
|
||||
@@ -3371,6 +3371,61 @@ class TestFindingViewSet:
|
||||
]
|
||||
}
|
||||
|
||||
def test_findings_metadata_backfill(
|
||||
self, authenticated_client, scans_fixture, findings_fixture
|
||||
):
|
||||
scan = scans_fixture[0]
|
||||
scan.unique_resource_count = 1
|
||||
scan.save()
|
||||
|
||||
with patch(
|
||||
"api.v1.views.backfill_scan_resource_summaries_task.apply_async"
|
||||
) as mock_backfill_task:
|
||||
response = authenticated_client.get(
|
||||
reverse("finding-metadata"),
|
||||
{"filter[scan]": str(scan.id)},
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
mock_backfill_task.assert_called()
|
||||
|
||||
def test_findings_metadata_backfill_no_resources(
|
||||
self, authenticated_client, scans_fixture
|
||||
):
|
||||
scan_id = str(scans_fixture[0].id)
|
||||
with patch(
|
||||
"api.v1.views.backfill_scan_resource_summaries_task.apply_async"
|
||||
) as mock_backfill_task:
|
||||
response = authenticated_client.get(
|
||||
reverse("finding-metadata"),
|
||||
{"filter[scan]": scan_id},
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
mock_backfill_task.assert_not_called()
|
||||
|
||||
def test_findings_metadata_latest_backfill(
|
||||
self, authenticated_client, scans_fixture, findings_fixture
|
||||
):
|
||||
scan = scans_fixture[0]
|
||||
scan.unique_resource_count = 1
|
||||
scan.save()
|
||||
|
||||
with patch(
|
||||
"api.v1.views.backfill_scan_resource_summaries_task.apply_async"
|
||||
) as mock_backfill_task:
|
||||
response = authenticated_client.get(reverse("finding-metadata_latest"))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
mock_backfill_task.assert_called()
|
||||
|
||||
def test_findings_metadata_latest_backfill_no_resources(
|
||||
self, authenticated_client, scans_fixture
|
||||
):
|
||||
with patch(
|
||||
"api.v1.views.backfill_scan_resource_summaries_task.apply_async"
|
||||
) as mock_backfill_task:
|
||||
response = authenticated_client.get(reverse("finding-metadata_latest"))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
mock_backfill_task.assert_not_called()
|
||||
|
||||
def test_findings_latest(self, authenticated_client, latest_scan_finding):
|
||||
response = authenticated_client.get(
|
||||
reverse("finding-latest"),
|
||||
|
||||
@@ -2127,9 +2127,12 @@ class FindingViewSet(PaginateByPkMixin, BaseRLSViewSet):
|
||||
|
||||
# ToRemove: Temporary fallback mechanism
|
||||
if not queryset.exists():
|
||||
scan_ids = Scan.objects.filter(
|
||||
raw_scans_ids = Scan.objects.filter(
|
||||
tenant_id=tenant_id, **scan_based_filters
|
||||
).values_list("id", flat=True)
|
||||
).values_list("id", "unique_resource_count")
|
||||
scan_ids = [
|
||||
scan_id for scan_id, count in raw_scans_ids if count and count > 0
|
||||
]
|
||||
for scan_id in scan_ids:
|
||||
backfill_scan_resource_summaries_task.apply_async(
|
||||
kwargs={"tenant_id": tenant_id, "scan_id": scan_id}
|
||||
@@ -2215,7 +2218,12 @@ class FindingViewSet(PaginateByPkMixin, BaseRLSViewSet):
|
||||
.order_by("provider_id", "-inserted_at")
|
||||
.distinct("provider_id")
|
||||
)
|
||||
latest_scans_ids = list(latest_scans_queryset.values_list("id", flat=True))
|
||||
raw_latest_scans_ids = list(
|
||||
latest_scans_queryset.values_list("id", "unique_resource_count")
|
||||
)
|
||||
latest_scans_ids = [
|
||||
scan_id for scan_id, count in raw_latest_scans_ids if count and count > 0
|
||||
]
|
||||
|
||||
queryset = ResourceScanSummary.objects.filter(
|
||||
tenant_id=tenant_id,
|
||||
|
||||
Reference in New Issue
Block a user