mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-01-25 02:08:11 +00:00
refactor(reports): change API response message when tasks are running (#7837)
This commit is contained in:
committed by
GitHub
parent
44afd9ed31
commit
15e4d1acce
@@ -5376,7 +5376,8 @@ paths:
|
||||
'403':
|
||||
description: There is a problem with credentials
|
||||
'404':
|
||||
description: The scan has no reports
|
||||
description: The scan has no reports, or the report generation task has
|
||||
not started yet
|
||||
/api/v1/schedules/daily:
|
||||
post:
|
||||
operationId: schedules_daily_create
|
||||
|
||||
@@ -2304,7 +2304,10 @@ class TestScanViewSet:
|
||||
url = reverse("scan-report", kwargs={"pk": scan.id})
|
||||
response = authenticated_client.get(url)
|
||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||
assert response.json()["errors"]["detail"] == "The scan has no reports."
|
||||
assert (
|
||||
response.json()["errors"]["detail"]
|
||||
== "The scan has no reports, or the report generation task has not started yet."
|
||||
)
|
||||
|
||||
def test_report_s3_no_credentials(
|
||||
self, authenticated_client, scans_fixture, monkeypatch
|
||||
@@ -2372,7 +2375,7 @@ class TestScanViewSet:
|
||||
):
|
||||
"""
|
||||
When output_location is a local path and glob.glob returns an empty list,
|
||||
the view should return HTTP 404 with detail "The scan has no reports."
|
||||
the view should return HTTP 404 with detail "The scan has no reports, or the report generation task has not started yet."
|
||||
"""
|
||||
scan = scans_fixture[0]
|
||||
scan.output_location = "/tmp/nonexistent_report_pattern.zip"
|
||||
@@ -2384,7 +2387,10 @@ class TestScanViewSet:
|
||||
response = authenticated_client.get(url)
|
||||
|
||||
assert response.status_code == 404
|
||||
assert response.json()["errors"]["detail"] == "The scan has no reports."
|
||||
assert (
|
||||
response.json()["errors"]["detail"]
|
||||
== "The scan has no reports, or the report generation task has not started yet."
|
||||
)
|
||||
|
||||
def test_report_local_file(self, authenticated_client, scans_fixture, monkeypatch):
|
||||
scan = scans_fixture[0]
|
||||
@@ -2459,7 +2465,10 @@ class TestScanViewSet:
|
||||
url = reverse("scan-compliance", kwargs={"pk": scan.id, "name": framework})
|
||||
resp = authenticated_client.get(url)
|
||||
assert resp.status_code == status.HTTP_404_NOT_FOUND
|
||||
assert resp.json()["errors"]["detail"] == "The scan has no reports."
|
||||
assert (
|
||||
resp.json()["errors"]["detail"]
|
||||
== "The scan has no reports, or the report generation task has not started yet."
|
||||
)
|
||||
|
||||
def test_compliance_s3_no_credentials(
|
||||
self, authenticated_client, scans_fixture, monkeypatch
|
||||
@@ -2681,7 +2690,10 @@ class TestScanViewSet:
|
||||
response = authenticated_client.get(url)
|
||||
|
||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||
assert response.json()["errors"]["detail"] == "The scan has no reports."
|
||||
assert (
|
||||
response.json()["errors"]["detail"]
|
||||
== "The scan has no reports, or the report generation task has not started yet."
|
||||
)
|
||||
|
||||
@patch("api.v1.views.get_s3_client")
|
||||
def test_report_s3_client_error_other(
|
||||
|
||||
@@ -1160,7 +1160,9 @@ class ProviderViewSet(BaseRLSViewSet):
|
||||
200: OpenApiResponse(description="Report obtained successfully"),
|
||||
202: OpenApiResponse(description="The task is in progress"),
|
||||
403: OpenApiResponse(description="There is a problem with credentials"),
|
||||
404: OpenApiResponse(description="The scan has no reports"),
|
||||
404: OpenApiResponse(
|
||||
description="The scan has no reports, or the report generation task has not started yet"
|
||||
),
|
||||
},
|
||||
),
|
||||
compliance=extend_schema(
|
||||
@@ -1363,7 +1365,9 @@ class ScanViewSet(BaseRLSViewSet):
|
||||
code = e.response.get("Error", {}).get("Code")
|
||||
if code == "NoSuchKey":
|
||||
return Response(
|
||||
{"detail": "The scan has no reports."},
|
||||
{
|
||||
"detail": "The scan has no reports, or the report generation task has not started yet."
|
||||
},
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
return Response(
|
||||
@@ -1376,7 +1380,9 @@ class ScanViewSet(BaseRLSViewSet):
|
||||
files = glob.glob(path_pattern)
|
||||
if not files:
|
||||
return Response(
|
||||
{"detail": "The scan has no reports."},
|
||||
{
|
||||
"detail": "The scan has no reports, or the report generation task has not started yet."
|
||||
},
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
filepath = files[0]
|
||||
@@ -1402,7 +1408,10 @@ class ScanViewSet(BaseRLSViewSet):
|
||||
|
||||
if not scan.output_location:
|
||||
return Response(
|
||||
{"detail": "The scan has no reports."}, status=status.HTTP_404_NOT_FOUND
|
||||
{
|
||||
"detail": "The scan has no reports, or the report generation task has not started yet."
|
||||
},
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
if scan.output_location.startswith("s3://"):
|
||||
@@ -1440,7 +1449,10 @@ class ScanViewSet(BaseRLSViewSet):
|
||||
|
||||
if not scan.output_location:
|
||||
return Response(
|
||||
{"detail": "The scan has no reports."}, status=status.HTTP_404_NOT_FOUND
|
||||
{
|
||||
"detail": "The scan has no reports, or the report generation task has not started yet."
|
||||
},
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
if scan.output_location.startswith("s3://"):
|
||||
|
||||
Reference in New Issue
Block a user