From b8e08539e33eb0999ee25d616815890daf7a02d3 Mon Sep 17 00:00:00 2001 From: Brian Pandola Date: Mon, 9 Nov 2020 14:59:06 -0800 Subject: [PATCH] Fix: Return `Tags` in iam:CreateUserResponse Fixes #3450 --- moto/iam/responses.py | 10 ++++++++++ tests/test_iam/test_iam.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/moto/iam/responses.py b/moto/iam/responses.py index 55a7c2076..d6f8ae020 100644 --- a/moto/iam/responses.py +++ b/moto/iam/responses.py @@ -1684,6 +1684,16 @@ USER_TEMPLATE = """<{{ action }}UserResponse> {{ user.id }} {{ user.created_iso_8601 }} {{ user.arn }} + {% if user.tags %} + + {% for tag in user.tags %} + + {{ tag['Key'] }} + {{ tag['Value'] }} + + {% endfor %} + + {% endif %} diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index 7db2f0162..a7f4aea23 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -4007,3 +4007,20 @@ def test_list_roles_none_found_returns_empty_list(): response = iam.list_roles(MaxItems=10) roles = response["Roles"] assert len(roles) == 0 + + +@mock_iam() +def test_create_user_with_tags(): + conn = boto3.client("iam", region_name="us-east-1") + user_name = "test-user" + tags = [ + {"Key": "somekey", "Value": "somevalue"}, + {"Key": "someotherkey", "Value": "someothervalue"}, + ] + resp = conn.create_user(UserName=user_name, Tags=tags) + assert resp["User"]["Tags"] == tags + resp = conn.list_user_tags(UserName=user_name) + assert resp["Tags"] == tags + + resp = conn.create_user(UserName="test-create-user-no-tags") + assert "Tags" not in resp["User"]