1
1
from re import search
2
2
from unittest import mock
3
3
4
- from boto3 import client
5
- from moto import mock_aws
6
-
7
4
from tests .providers .aws .audit_info_utils import (
8
5
AWS_ACCOUNT_NUMBER ,
9
6
AWS_REGION_US_EAST_1 ,
@@ -19,13 +16,20 @@ class Test_iam_root_hardware_mfa_enabled_test:
19
16
set_mocked_aws_audit_info ,
20
17
)
21
18
22
- @mock_aws
23
- def test_root_hardware_virtual_mfa_enabled (self ):
24
- iam = client ("iam" )
25
- mfa_device_name = "mfa-test"
26
- iam .create_virtual_mfa_device (VirtualMFADeviceName = mfa_device_name )
27
-
28
- from prowler .providers .aws .services .iam .iam_service import IAM
19
+ def test_root_virtual_mfa_enabled (self ):
20
+ iam_client = mock .MagicMock
21
+ iam_client .account_summary = {
22
+ "SummaryMap" : {"AccountMFAEnabled" : 1 },
23
+ }
24
+ iam_client .virtual_mfa_devices = [
25
+ {
26
+ "SerialNumber" : f"arn:aws:iam::{ AWS_ACCOUNT_NUMBER } :mfa/mfa" ,
27
+ "User" : {"Arn" : f"arn:aws:iam::{ AWS_ACCOUNT_NUMBER } :root" },
28
+ }
29
+ ]
30
+ iam_client .audited_partition = "aws"
31
+ iam_client .region = AWS_REGION_US_EAST_1
32
+ iam_client .mfa_arn_template = f"arn:aws:iam::{ AWS_ACCOUNT_NUMBER } :mfa"
29
33
30
34
current_audit_info = set_mocked_aws_audit_info ([AWS_REGION_US_EAST_1 ])
31
35
@@ -34,15 +38,12 @@ def test_root_hardware_virtual_mfa_enabled(self):
34
38
new = current_audit_info ,
35
39
), mock .patch (
36
40
"prowler.providers.aws.services.iam.iam_root_hardware_mfa_enabled.iam_root_hardware_mfa_enabled.iam_client" ,
37
- new = IAM ( current_audit_info ) ,
38
- ) as service_client :
41
+ new = iam_client ,
42
+ ):
39
43
from prowler .providers .aws .services .iam .iam_root_hardware_mfa_enabled .iam_root_hardware_mfa_enabled import (
40
44
iam_root_hardware_mfa_enabled ,
41
45
)
42
46
43
- service_client .account_summary ["SummaryMap" ]["AccountMFAEnabled" ] = 1
44
- service_client .virtual_mfa_devices [0 ]["SerialNumber" ] = "sddfaf-root-sfsfds"
45
-
46
47
check = iam_root_hardware_mfa_enabled ()
47
48
result = check .execute ()
48
49
assert result [0 ].status == "FAIL"
@@ -52,13 +53,15 @@ def test_root_hardware_virtual_mfa_enabled(self):
52
53
)
53
54
assert result [0 ].resource_id == "<root_account>"
54
55
55
- @mock_aws
56
- def test_root_hardware_virtual_hardware_mfa_enabled (self ):
57
- iam = client ("iam" )
58
- mfa_device_name = "mfa-test"
59
- iam .create_virtual_mfa_device (VirtualMFADeviceName = mfa_device_name )
60
-
61
- from prowler .providers .aws .services .iam .iam_service import IAM
56
+ def test_root_hardware_mfa_enabled (self ):
57
+ iam_client = mock .MagicMock
58
+ iam_client .account_summary = {
59
+ "SummaryMap" : {"AccountMFAEnabled" : 1 },
60
+ }
61
+ iam_client .virtual_mfa_devices = []
62
+ iam_client .audited_partition = "aws"
63
+ iam_client .region = AWS_REGION_US_EAST_1
64
+ iam_client .mfa_arn_template = f"arn:aws:iam::{ AWS_ACCOUNT_NUMBER } :mfa"
62
65
63
66
current_audit_info = set_mocked_aws_audit_info ([AWS_REGION_US_EAST_1 ])
64
67
@@ -67,15 +70,12 @@ def test_root_hardware_virtual_hardware_mfa_enabled(self):
67
70
new = current_audit_info ,
68
71
), mock .patch (
69
72
"prowler.providers.aws.services.iam.iam_root_hardware_mfa_enabled.iam_root_hardware_mfa_enabled.iam_client" ,
70
- new = IAM ( current_audit_info ) ,
71
- ) as service_client :
73
+ new = iam_client ,
74
+ ):
72
75
from prowler .providers .aws .services .iam .iam_root_hardware_mfa_enabled .iam_root_hardware_mfa_enabled import (
73
76
iam_root_hardware_mfa_enabled ,
74
77
)
75
78
76
- service_client .account_summary ["SummaryMap" ]["AccountMFAEnabled" ] = 1
77
- service_client .virtual_mfa_devices [0 ]["SerialNumber" ] = ""
78
-
79
79
check = iam_root_hardware_mfa_enabled ()
80
80
result = check .execute ()
81
81
assert result [0 ].status == "PASS"
@@ -84,7 +84,3 @@ def test_root_hardware_virtual_hardware_mfa_enabled(self):
84
84
result [0 ].status_extended ,
85
85
)
86
86
assert result [0 ].resource_id == "<root_account>"
87
- assert (
88
- result [0 ].resource_arn
89
- == f"arn:aws:iam:{ AWS_REGION_US_EAST_1 } :{ AWS_ACCOUNT_NUMBER } :mfa"
90
- )
0 commit comments