mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 13:01:56 +00:00
fix(findings): avoid backfill on empty scans (#8188)
Co-authored-by: Víctor Fernández Poyatos <victor@prowler.com>
This commit is contained in:
@@ -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
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ name = "prowler-api"
|
||||
package-mode = false
|
||||
# Needed for the SDK compatibility
|
||||
requires-python = ">=3.11,<3.13"
|
||||
version = "1.9.0"
|
||||
version = "1.9.1"
|
||||
|
||||
[project.scripts]
|
||||
celery = "src.backend.config.settings.celery"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
title: Prowler API
|
||||
version: 1.9.0
|
||||
version: 1.9.1
|
||||
description: |-
|
||||
Prowler API specification.
|
||||
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -271,7 +271,7 @@ class SchemaView(SpectacularAPIView):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
spectacular_settings.TITLE = "Prowler API"
|
||||
spectacular_settings.VERSION = "1.9.0"
|
||||
spectacular_settings.VERSION = "1.9.1"
|
||||
spectacular_settings.DESCRIPTION = (
|
||||
"Prowler API specification.\n\nThis file is auto-generated."
|
||||
)
|
||||
@@ -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