diff --git a/api/src/backend/api/tests/test_views.py b/api/src/backend/api/tests/test_views.py index c3c654b20d..0173797062 100644 --- a/api/src/backend/api/tests/test_views.py +++ b/api/src/backend/api/tests/test_views.py @@ -847,9 +847,9 @@ class TestProviderViewSet: included_data = response.json()["included"] for expected_type in expected_resources: - assert any(d.get("type") == expected_type for d in included_data), ( - f"Expected type '{expected_type}' not found in included data" - ) + assert any( + d.get("type") == expected_type for d in included_data + ), f"Expected type '{expected_type}' not found in included data" def test_providers_retrieve(self, authenticated_client, providers_fixture): provider1, *_ = providers_fixture @@ -2226,9 +2226,9 @@ class TestResourceViewSet: included_data = response.json()["included"] for expected_type in expected_resources: - assert any(d.get("type") == expected_type for d in included_data), ( - f"Expected type '{expected_type}' not found in included data" - ) + assert any( + d.get("type") == expected_type for d in included_data + ), f"Expected type '{expected_type}' not found in included data" @pytest.mark.parametrize( "filter_name, filter_value, expected_count", @@ -2412,9 +2412,9 @@ class TestFindingViewSet: included_data = response.json()["included"] for expected_type in expected_resources: - assert any(d.get("type") == expected_type for d in included_data), ( - f"Expected type '{expected_type}' not found in included data" - ) + assert any( + d.get("type") == expected_type for d in included_data + ), f"Expected type '{expected_type}' not found in included data" @pytest.mark.parametrize( "filter_name, filter_value, expected_count", @@ -2692,9 +2692,9 @@ class TestJWTFields: reverse("token-obtain"), data, format="json" ) - assert response.status_code == status.HTTP_200_OK, ( - f"Unexpected status code: {response.status_code}" - ) + assert ( + response.status_code == status.HTTP_200_OK + ), f"Unexpected status code: {response.status_code}" access_token = response.data["attributes"]["access"] payload = jwt.decode(access_token, options={"verify_signature": False}) @@ -2708,23 +2708,23 @@ class TestJWTFields: # Verify expected fields for field in expected_fields: assert field in payload, f"The field '{field}' is not in the JWT" - assert payload[field] == expected_fields[field], ( - f"The value of '{field}' does not match" - ) + assert ( + payload[field] == expected_fields[field] + ), f"The value of '{field}' does not match" # Verify time fields are integers for time_field in ["exp", "iat", "nbf"]: assert time_field in payload, f"The field '{time_field}' is not in the JWT" - assert isinstance(payload[time_field], int), ( - f"The field '{time_field}' is not an integer" - ) + assert isinstance( + payload[time_field], int + ), f"The field '{time_field}' is not an integer" # Verify identification fields are non-empty strings for id_field in ["jti", "sub", "tenant_id"]: assert id_field in payload, f"The field '{id_field}' is not in the JWT" - assert isinstance(payload[id_field], str) and payload[id_field], ( - f"The field '{id_field}' is not a valid string" - ) + assert ( + isinstance(payload[id_field], str) and payload[id_field] + ), f"The field '{id_field}' is not a valid string" @pytest.mark.django_db diff --git a/prowler/lib/outputs/finding.py b/prowler/lib/outputs/finding.py index ca1c7fdea4..b6d92e6fd3 100644 --- a/prowler/lib/outputs/finding.py +++ b/prowler/lib/outputs/finding.py @@ -4,7 +4,13 @@ from typing import Optional, Union from pydantic import BaseModel, Field, ValidationError from prowler.config.config import prowler_version -from prowler.lib.check.models import Check_Report, CheckMetadata, Remediation, Code, Recommendation +from prowler.lib.check.models import ( + Check_Report, + CheckMetadata, + Remediation, + Code, + Recommendation, +) from prowler.lib.logger import logger from prowler.lib.outputs.common import Status, fill_common_finding_data from prowler.lib.outputs.compliance.compliance import get_check_compliance @@ -270,9 +276,7 @@ class Finding(BaseModel): raise error @classmethod - def transform_api_finding( - cls, finding - ) -> "Finding": + def transform_api_finding(cls, finding) -> "Finding": """ Transform a FindingModel instance into an API-friendly Finding object. @@ -308,12 +312,18 @@ class Finding(BaseModel): RelatedUrl=finding.check_metadata["relatedurl"], Remediation=Remediation( Recommendation=Recommendation( - Text=finding.check_metadata["remediation"]["recommendation"]["text"], + Text=finding.check_metadata["remediation"]["recommendation"][ + "text" + ], Url=finding.check_metadata["remediation"]["recommendation"]["url"], ), Code=Code( - NativeIaC=finding.check_metadata["remediation"]["code"]["nativeiac"], - Terraform=finding.check_metadata["remediation"]["code"]["terraform"], + NativeIaC=finding.check_metadata["remediation"]["code"][ + "nativeiac" + ], + Terraform=finding.check_metadata["remediation"]["code"][ + "terraform" + ], CLI=finding.check_metadata["remediation"]["code"]["cli"], Other=finding.check_metadata["remediation"]["code"]["other"], ), @@ -331,15 +341,15 @@ class Finding(BaseModel): output_data["resource_name"] = finding.resources.first().name output_data["resource_details"] = "" resource_tags = finding.resources.first().tags.all() - output_data["resource_tags"] = unroll_tags([{"key": tag.key, "value": tag.value} for tag in resource_tags]) + output_data["resource_tags"] = unroll_tags( + [{"key": tag.key, "value": tag.value} for tag in resource_tags] + ) output_data["region"] = finding.resources.first().region output_data["compliance"] = {} return cls(**output_data) - def _transform_findings_stats( - scan_summaries: list[dict] - ) -> dict: + def _transform_findings_stats(scan_summaries: list[dict]) -> dict: """ Aggregate and transform scan summary data into findings statistics.