fix(fms): Handle PolicyComplianceStatusList key error (#3230)

Co-authored-by: Sergio Garcia <sergargar1@gmail.com>
This commit is contained in:
Pepe Fagoaga
2023-12-28 18:25:21 +01:00
committed by GitHub
parent d1bd097079
commit 423f96b95f
3 changed files with 46 additions and 11 deletions

View File

@@ -170,3 +170,32 @@ class Test_fms_policy_compliant:
assert result[0].resource_id == "12345678901"
assert result[0].resource_arn == "arn:aws:fms:us-east-1:12345678901"
assert result[0].region == AWS_REGION_US_EAST_1
def test_fms_admin_without_policies(self):
fms_client = mock.MagicMock
fms_client.audited_account = AWS_ACCOUNT_NUMBER
fms_client.audited_account_arn = f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}:root"
fms_client.region = AWS_REGION_US_EAST_1
fms_client.fms_admin_account = True
fms_client.fms_policies = []
with mock.patch(
"prowler.providers.aws.services.fms.fms_service.FMS",
new=fms_client,
):
# Test Check
from prowler.providers.aws.services.fms.fms_policy_compliant.fms_policy_compliant import (
fms_policy_compliant,
)
check = fms_policy_compliant()
result = check.execute()
assert len(result) == 1
assert result[0].status == "FAIL"
assert (
result[0].status_extended
== f"FMS without any compliant policy for account {AWS_ACCOUNT_NUMBER}."
)
assert result[0].resource_id == AWS_ACCOUNT_NUMBER
assert result[0].resource_arn == fms_client.audited_account_arn
assert result[0].region == AWS_REGION_US_EAST_1