From 555928af5d56b33326d0b4309c175065e3f422ae Mon Sep 17 00:00:00 2001 From: Daniel Fangl Date: Thu, 22 Dec 2022 20:03:33 +0100 Subject: [PATCH] IAM: add tags for users to get-account-authorization-details response (#5803) --- moto/iam/responses.py | 9 +++++++++ tests/test_iam/test_iam.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/moto/iam/responses.py b/moto/iam/responses.py index e0b6a707e..06f2fa1e7 100644 --- a/moto/iam/responses.py +++ b/moto/iam/responses.py @@ -849,6 +849,7 @@ class IamResponse(BaseResponse): groups=account_details["groups"], roles=account_details["roles"], get_groups_for_user=self.backend.get_groups_for_user, + list_tags_for_user=self.backend.list_user_tags, ) def create_saml_provider(self): @@ -2279,6 +2280,14 @@ GET_ACCOUNT_AUTHORIZATION_DETAILS_TEMPLATE = """ {% endif %} + + {% for tag in list_tags_for_user(user.name).get("Tags", []) %} + + {{ tag['Key'] }} + {{ tag['Value'] }} + + {% endfor %} + {% endfor %} diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index 4280a80b2..f5a7ff193 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -2339,6 +2339,14 @@ def test_get_account_authorization_details(): RoleName="my-role", PolicyArn=f"arn:aws:iam::{ACCOUNT_ID}:policy/testPolicy", ) + # add tags to the user + conn.tag_user( + UserName="testUser", + Tags=[ + {"Key": "somekey", "Value": "somevalue"}, + {"Key": "someotherkey", "Value": "someothervalue"}, + ], + ) result = conn.get_account_authorization_details(Filter=["Role"]) assert len(result["RoleDetailList"]) == 1 @@ -2377,6 +2385,7 @@ def test_get_account_authorization_details(): assert len(result["UserDetailList"][0]["GroupList"]) == 1 assert len(result["UserDetailList"][0]["UserPolicyList"]) == 1 assert len(result["UserDetailList"][0]["AttachedManagedPolicies"]) == 1 + assert len(result["UserDetailList"][0]["Tags"]) == 2 assert len(result["GroupDetailList"]) == 0 assert len(result["Policies"]) == 0 assert (