Skip to content

Commit

Permalink
Correct group inline policy rendering (#3069)
Browse files Browse the repository at this point in the history
* Correct group inline policy rendering in iam:GetAccountAuthorizationDetails response

* Include user inline policy if exists

* Add tests for IAM inline policies

* Remove unnecessary print stmts
  • Loading branch information
limitusus authored Jun 14, 2020
1 parent 1f2e6b8 commit 849f16f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion moto/iam/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,16 @@ def get_account_summary(self):
<UserName>{{ user.name }}</UserName>
<Arn>{{ user.arn }}</Arn>
<CreateDate>{{ user.created_iso_8601 }}</CreateDate>
{% if user.policies %}
<UserPolicyList>
{% for policy in user.policies %}
<member>
<PolicyName>{{ policy }}</PolicyName>
<PolicyDocument>{{ user.policies[policy] }}</PolicyDocument>
</member>
{% endfor %}
</UserPolicyList>
{% endif %}
</member>
{% endfor %}
</UserDetailList>
Expand All @@ -2106,7 +2116,7 @@ def get_account_summary(self):
{% for policy in group.policies %}
<member>
<PolicyName>{{ policy }}</PolicyName>
<PolicyDocument>{{ group.get_policy(policy) }}</PolicyDocument>
<PolicyDocument>{{ group.policies[policy] }}</PolicyDocument>
</member>
{% endfor %}
</GroupPolicyList>
Expand Down
10 changes: 10 additions & 0 deletions tests/test_iam/test_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,11 +1690,15 @@ def test_get_account_authorization_details():
assert result["RoleDetailList"][0]["AttachedManagedPolicies"][0][
"PolicyArn"
] == "arn:aws:iam::{}:policy/testPolicy".format(ACCOUNT_ID)
assert result["RoleDetailList"][0]["RolePolicyList"][0][
"PolicyDocument"
] == json.loads(test_policy)

result = conn.get_account_authorization_details(Filter=["User"])
assert len(result["RoleDetailList"]) == 0
assert len(result["UserDetailList"]) == 1
assert len(result["UserDetailList"][0]["GroupList"]) == 1
assert len(result["UserDetailList"][0]["UserPolicyList"]) == 1
assert len(result["UserDetailList"][0]["AttachedManagedPolicies"]) == 1
assert len(result["GroupDetailList"]) == 0
assert len(result["Policies"]) == 0
Expand All @@ -1705,6 +1709,9 @@ def test_get_account_authorization_details():
assert result["UserDetailList"][0]["AttachedManagedPolicies"][0][
"PolicyArn"
] == "arn:aws:iam::{}:policy/testPolicy".format(ACCOUNT_ID)
assert result["UserDetailList"][0]["UserPolicyList"][0][
"PolicyDocument"
] == json.loads(test_policy)

result = conn.get_account_authorization_details(Filter=["Group"])
assert len(result["RoleDetailList"]) == 0
Expand All @@ -1720,6 +1727,9 @@ def test_get_account_authorization_details():
assert result["GroupDetailList"][0]["AttachedManagedPolicies"][0][
"PolicyArn"
] == "arn:aws:iam::{}:policy/testPolicy".format(ACCOUNT_ID)
assert result["GroupDetailList"][0]["GroupPolicyList"][0][
"PolicyDocument"
] == json.loads(test_policy)

result = conn.get_account_authorization_details(Filter=["LocalManagedPolicy"])
assert len(result["RoleDetailList"]) == 0
Expand Down

0 comments on commit 849f16f

Please sign in to comment.