Merge branch 'master' of github.com:prowler-cloud/prowler into PRWLR-6129-review-check-report-init-for-region-resource-id-resource-arn

This commit is contained in:
Pepe Fagoaga committed 2025-01-30 11:24:33 +01:00
commit 8478da5b8f
9 files changed
+84 -16

No files matched your search

+44
View File
@@ -1,6 +1,9 @@
from datetime import datetime
from unittest.mock import MagicMock, patch
import pytest
from pydantic import ValidationError
from prowler.lib.check.models import (
CheckMetadata,
Code,
@@ -417,3 +420,44 @@ class TestFinding:
assert metadata is not None
assert isinstance(metadata, dict)
self.assert_keys_lowercase(metadata)
@patch(
"prowler.lib.outputs.finding.get_check_compliance",
new=mock_get_check_compliance,
)
def test_generate_output_validation_error(self):
# Mock provider
provider = MagicMock()
provider.type = "aws"
provider.identity.profile = "mock_auth"
provider.identity.account = "mock_account_uid"
provider.identity.partition = "aws"
provider.organizations_metadata.account_name = "mock_account_name"
provider.organizations_metadata.account_email = "mock_account_email"
provider.organizations_metadata.organization_arn = "mock_account_org_uid"
provider.organizations_metadata.organization_id = "mock_account_org_name"
provider.organizations_metadata.account_tags = {"tag1": "value1"}
# Mock check result
check_output = MagicMock()
check_output.resource_id = "test_resource_id"
check_output.resource_arn = "test_resource_arn"
check_output.resource_details = "test_resource_details"
check_output.resource_tags = {"tag1": "value1"}
check_output.region = "us-west-1"
check_output.partition = "aws"
check_output.status_extended = "mock_status_extended"
check_output.muted = False
check_output.check_metadata = mock_check_metadata(provider="aws")
check_output.resource = {}
# Mock output options
output_options = MagicMock()
output_options.unix_timestamp = False
# Bad Status Value
check_output.status = "Invalid"
# Generate the finding
with pytest.raises(ValidationError):
Finding.generate_output(provider, check_output, output_options)
@@ -65,6 +65,7 @@ class Test_sns_subscription_not_using_http_endpoints:
owner=AWS_ACCOUNT_NUMBER,
protocol="https",
endpoint="https://www.endpoint.com",
region=AWS_REGION_EU_WEST_1,
)
)
sns_client.topics = []
@@ -100,6 +101,7 @@ class Test_sns_subscription_not_using_http_endpoints:
owner=AWS_ACCOUNT_NUMBER,
protocol="https",
endpoint="https://www.endpoint.com",
region=AWS_REGION_EU_WEST_1,
)
)
sns_client.topics = []
@@ -131,6 +133,7 @@ class Test_sns_subscription_not_using_http_endpoints:
)
assert result[0].resource_id == subscription_id_1
assert result[0].resource_arn == subscription_arn_1
assert result[0].region == AWS_REGION_EU_WEST_1
def test_subscriptions_with_http(self):
sns_client = mock.MagicMock
@@ -142,6 +145,7 @@ class Test_sns_subscription_not_using_http_endpoints:
owner=AWS_ACCOUNT_NUMBER,
protocol="http",
endpoint="http://www.endpoint.com",
region=AWS_REGION_EU_WEST_1,
)
)
sns_client.topics = []
@@ -173,6 +177,7 @@ class Test_sns_subscription_not_using_http_endpoints:
)
assert result[0].resource_id == subscription_id_2
assert result[0].resource_arn == subscription_arn_2
assert result[0].region == AWS_REGION_EU_WEST_1
def test_subscriptions_with_http_and_https(self):
sns_client = mock.MagicMock
@@ -184,6 +189,7 @@ class Test_sns_subscription_not_using_http_endpoints:
owner=AWS_ACCOUNT_NUMBER,
protocol="https",
endpoint="https://www.endpoint.com",
region=AWS_REGION_EU_WEST_1,
)
)
subscriptions.append(
@@ -193,6 +199,7 @@ class Test_sns_subscription_not_using_http_endpoints:
owner=AWS_ACCOUNT_NUMBER,
protocol="http",
endpoint="http://www.endpoint.com",
region=AWS_REGION_EU_WEST_1,
)
)
sns_client.topics = []
@@ -224,6 +231,7 @@ class Test_sns_subscription_not_using_http_endpoints:
)
assert result[0].resource_id == subscription_id_1
assert result[0].resource_arn == subscription_arn_1
assert result[0].region == AWS_REGION_EU_WEST_1
assert result[1].status == "FAIL"
assert (
@@ -232,3 +240,4 @@ class Test_sns_subscription_not_using_http_endpoints:
)
assert result[1].resource_id == subscription_id_2
assert result[1].resource_arn == subscription_arn_2
assert result[1].region == AWS_REGION_EU_WEST_1