From fecde6c001b92f15bd20eb9834da42502a083a04 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Tue, 26 Sep 2023 21:59:37 +0000 Subject: [PATCH] IAM: list_groups() now returns the CreateDate-attribute (#6854) --- moto/iam/responses.py | 1 + tests/test_iam/test_iam.py | 42 +++++++++++++------------------ tests/test_iam/test_iam_groups.py | 2 ++ 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/moto/iam/responses.py b/moto/iam/responses.py index 60ab3b508..32ce56392 100644 --- a/moto/iam/responses.py +++ b/moto/iam/responses.py @@ -1761,6 +1761,7 @@ LIST_GROUPS_TEMPLATE = """ {{ group.name }} {{ group.id }} {{ group.arn }} + {{ group.created_iso_8601 }} {% endfor %} diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index 9f3301de4..7afe6654d 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -4594,36 +4594,30 @@ def test_list_roles_none_found_returns_empty_list(): assert len(roles) == 0 -@pytest.mark.parametrize("desc", ["", "Test Description"]) @mock_iam() -def test_list_roles_with_description(desc): +def test_list_roles(): conn = boto3.client("iam", region_name="us-east-1") - resp = conn.create_role( - RoleName="my-role", AssumeRolePolicyDocument="some policy", Description=desc - ) - assert resp["Role"]["Description"] == desc + for desc in ["", "desc"]: + resp = conn.create_role( + RoleName=f"role_{desc}", + AssumeRolePolicyDocument="some policy", + Description=desc, + ) + assert resp["Role"]["Description"] == desc + conn.create_role(RoleName="role3", AssumeRolePolicyDocument="sp") # Ensure the Description is included in role listing as well - assert conn.list_roles()["Roles"][0]["Description"] == desc + all_roles = conn.list_roles()["Roles"] + role1 = next(r for r in all_roles if r["RoleName"] == "role_") + role2 = next(r for r in all_roles if r["RoleName"] == "role_desc") + role3 = next(r for r in all_roles if r["RoleName"] == "role3") + assert role1["Description"] == "" + assert role2["Description"] == "desc" + assert "Description" not in role3 -@mock_iam() -def test_list_roles_without_description(): - conn = boto3.client("iam", region_name="us-east-1") - resp = conn.create_role(RoleName="my-role", AssumeRolePolicyDocument="some policy") - assert "Description" not in resp["Role"] - - # Ensure the Description is not included in role listing as well - assert "Description" not in conn.list_roles()["Roles"][0] - - -@mock_iam() -def test_list_roles_includes_max_session_duration(): - conn = boto3.client("iam", region_name="us-east-1") - conn.create_role(RoleName="my-role", AssumeRolePolicyDocument="some policy") - - # Ensure the MaxSessionDuration is included in the role listing - assert "MaxSessionDuration" in conn.list_roles()["Roles"][0] + assert all([role["CreateDate"] for role in all_roles]) + assert all([role["MaxSessionDuration"] for role in all_roles]) @mock_iam() diff --git a/tests/test_iam/test_iam_groups.py b/tests/test_iam/test_iam_groups.py index 0ff9a0810..0f7b040e3 100644 --- a/tests/test_iam/test_iam_groups.py +++ b/tests/test_iam/test_iam_groups.py @@ -86,6 +86,8 @@ def test_get_all_groups(): groups = conn.list_groups()["Groups"] assert len(groups) == 2 + assert all([g["CreateDate"] for g in groups]) + @mock_iam def test_add_unknown_user_to_group():