chore(test): improve iam_root_hardware_mfa_enabled tests (#4835)

Co-authored-by: Sergio Garcia <38561120+sergargar@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2024-08-22 09:34:39 -04:00
committed by GitHub
parent dae26ad484
commit fa059363c7
@@ -1,4 +1,3 @@
from re import search
from unittest import mock
from tests.providers.aws.utils import (
@@ -46,12 +45,14 @@ class Test_iam_root_hardware_mfa_enabled_test:
check = iam_root_hardware_mfa_enabled()
result = check.execute()
assert len(result) == 1
assert result[0].status == "FAIL"
assert search(
"Root account has a virtual MFA instead of a hardware MFA device enabled.",
result[0].status_extended,
assert (
result[0].status_extended
== "Root account has a virtual MFA instead of a hardware MFA device enabled."
)
assert result[0].resource_id == "<root_account>"
assert result[0].resource_arn == f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}:mfa"
def test_root_hardware_mfa_enabled(self):
iam_client = mock.MagicMock
@@ -78,9 +79,36 @@ class Test_iam_root_hardware_mfa_enabled_test:
check = iam_root_hardware_mfa_enabled()
result = check.execute()
assert len(result) == 1
assert result[0].status == "PASS"
assert search(
"Root account has a hardware MFA device enabled.",
result[0].status_extended,
assert (
result[0].status_extended
== "Root account has a hardware MFA device enabled."
)
assert result[0].resource_id == "<root_account>"
assert result[0].resource_arn == f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}:mfa"
def test_root_hardware_mfa_enabled_none_summary(self):
iam_client = mock.MagicMock
iam_client.account_summary = None
iam_client.virtual_mfa_devices = []
iam_client.audited_partition = "aws"
iam_client.region = AWS_REGION_US_EAST_1
iam_client.mfa_arn_template = f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}:mfa"
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.iam.iam_root_hardware_mfa_enabled.iam_root_hardware_mfa_enabled.iam_client",
new=iam_client,
):
from prowler.providers.aws.services.iam.iam_root_hardware_mfa_enabled.iam_root_hardware_mfa_enabled import (
iam_root_hardware_mfa_enabled,
)
check = iam_root_hardware_mfa_enabled()
result = check.execute()
assert len(result) == 0