Skip to content

Commit

Permalink
chore(test): improve iam_root_hardware_mfa_enabled tests (#4835)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergio Garcia <[email protected]>
  • Loading branch information
github-actions[bot] and sergargar authored Aug 22, 2024
1 parent dae26ad commit fa05936
Showing 1 changed file with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from re import search
from unittest import mock

from tests.providers.aws.utils import (
Expand Down Expand Up @@ -46,12 +45,14 @@ def test_root_virtual_mfa_enabled(self):

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
Expand All @@ -78,9 +79,36 @@ def test_root_hardware_mfa_enabled(self):

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

0 comments on commit fa05936

Please sign in to comment.