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

Co-authored-by: Sergio Garcia <38561120+sergargar@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2024-08-22 09:35:15 -04:00
committed by GitHub
parent 0a0fe10ab9
commit 97a9ee5a3c
@@ -1,4 +1,3 @@
from re import search
from unittest import mock
from tests.providers.aws.audit_info_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"
current_audit_info = set_mocked_aws_audit_info([AWS_REGION_US_EAST_1])
with mock.patch(
"prowler.providers.aws.lib.audit_info.audit_info.current_audit_info",
new=current_audit_info,
), 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