fix(cloudwatch): handle None metric alarms (#7205)

This commit is contained in:
Sergio Garcia authored and GitHub committed 2025-03-12 14:44:36 +01:00
1 parent 443dc067b3
commit 6564ec1ff5
4 files changed
+87 -24

No files matched your search

@@ -28,7 +28,6 @@ class Test_cloudwatch_alarm_actions_alarm_state_configured:
new=CloudWatch(aws_provider),
),
):
from prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_alarm_state_configured.cloudwatch_alarm_actions_alarm_state_configured import (
cloudwatch_alarm_actions_alarm_state_configured,
)
@@ -38,6 +37,38 @@ class Test_cloudwatch_alarm_actions_alarm_state_configured:
assert len(result) == 0
@mock_aws
def test_none_cloudwatch_alarms(self):
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
cloudwatch_client.metric_alarms = []
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
CloudWatch,
)
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
with (
mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
),
mock.patch(
"prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_alarm_state_configured.cloudwatch_alarm_actions_alarm_state_configured.cloudwatch_client",
new=CloudWatch(aws_provider),
) as cloudwatch_client_mock,
):
from prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_alarm_state_configured.cloudwatch_alarm_actions_alarm_state_configured import (
cloudwatch_alarm_actions_alarm_state_configured,
)
cloudwatch_client_mock.metric_alarms = None
check = cloudwatch_alarm_actions_alarm_state_configured()
result = check.execute()
assert len(result) == 0
@mock_aws
def test_cloudwatch_alarms_actions_configured(self):
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
@@ -66,7 +97,6 @@ class Test_cloudwatch_alarm_actions_alarm_state_configured:
new=CloudWatch(aws_provider),
),
):
from prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_alarm_state_configured.cloudwatch_alarm_actions_alarm_state_configured import (
cloudwatch_alarm_actions_alarm_state_configured,
)
@@ -116,7 +146,6 @@ class Test_cloudwatch_alarm_actions_alarm_state_configured:
new=CloudWatch(aws_provider),
),
):
from prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_alarm_state_configured.cloudwatch_alarm_actions_alarm_state_configured import (
cloudwatch_alarm_actions_alarm_state_configured,
)
@@ -28,7 +28,6 @@ class Test_cloudwatch_alarm_actions_enabled:
new=CloudWatch(aws_provider),
),
):
from prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_enabled.cloudwatch_alarm_actions_enabled import (
cloudwatch_alarm_actions_enabled,
)
@@ -38,6 +37,37 @@ class Test_cloudwatch_alarm_actions_enabled:
assert len(result) == 0
def test_none_cloudwatch_alarms(self):
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
cloudwatch_client.metric_alarms = []
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
CloudWatch,
)
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
with (
mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
),
mock.patch(
"prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_enabled.cloudwatch_alarm_actions_enabled.cloudwatch_client",
new=CloudWatch(aws_provider),
) as cloudwatch_client_mock,
):
from prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_enabled.cloudwatch_alarm_actions_enabled import (
cloudwatch_alarm_actions_enabled,
)
cloudwatch_client_mock.metric_alarms = None
check = cloudwatch_alarm_actions_enabled()
result = check.execute()
assert len(result) == 0
@mock_aws
def test_cloudwatch_alarms_actions_enabled(self):
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
@@ -66,7 +96,6 @@ class Test_cloudwatch_alarm_actions_enabled:
new=CloudWatch(aws_provider),
),
):
from prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_enabled.cloudwatch_alarm_actions_enabled import (
cloudwatch_alarm_actions_enabled,
)
@@ -116,7 +145,6 @@ class Test_cloudwatch_alarm_actions_enabled:
new=CloudWatch(aws_provider),
),
):
from prowler.providers.aws.services.cloudwatch.cloudwatch_alarm_actions_enabled.cloudwatch_alarm_actions_enabled import (
cloudwatch_alarm_actions_enabled,
)