From: Casey Bodley Date: Mon, 31 Mar 2025 18:27:50 +0000 (-0400) Subject: iam: use config account_id instead of parsing ARNs X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a65eca5e30a40968eb37ee47cbcc2bcca0f61415;p=s3-tests.git iam: use config account_id instead of parsing ARNs Signed-off-by: Casey Bodley --- diff --git a/s3tests/functional/test_iam.py b/s3tests/functional/test_iam.py index da274fb1..d1c44bfd 100644 --- a/s3tests/functional/test_iam.py +++ b/s3tests/functional/test_iam.py @@ -13,9 +13,11 @@ from . import ( get_alt_client, get_iam_client, get_iam_root_client, + get_iam_root_account_id, get_iam_alt_root_client, get_iam_alt_root_user_id, get_iam_alt_root_email, + get_iam_alt_root_account_id, make_iam_name, get_iam_path_prefix, get_new_bucket, @@ -2363,8 +2365,7 @@ def test_account_role_policy_allow_create_bucket(iam_root, iam_alt_root): s3_main = get_iam_root_client(service_name='s3') response = s3_main.get_bucket_acl(Bucket=bucket_name) - main_arn = iam_root.get_user()['User']['Arn'] - account_id = main_arn.removeprefix('arn:aws:iam::').removesuffix(':root') + account_id = get_iam_root_account_id() assert response['Owner']['ID'] == account_id assert response['Grants'][0]['Grantee']['ID'] == account_id @@ -2757,9 +2758,9 @@ def test_cross_account_user_bucket_policy_allow_account_id(iam_root, iam_alt_roo roots3 = get_iam_root_client(service_name='s3') path = get_iam_path_prefix() user_name = make_iam_name('AltUser') - response = iam_alt_root.create_user(UserName=user_name, Path=path) - user_arn = response['User']['Arn'] - account_id = user_arn.removeprefix('arn:aws:iam::').removesuffix(f':user{path}{user_name}') + iam_alt_root.create_user(UserName=user_name, Path=path) + + account_id = get_iam_alt_root_account_id() _test_cross_account_user_bucket_policy(roots3, iam_alt_root, user_name, account_id) @pytest.mark.iam_account @@ -2768,9 +2769,9 @@ def test_cross_account_bucket_user_policy_allow_account_id(iam_root, iam_alt_roo roots3 = get_iam_root_client(service_name='s3') path = get_iam_path_prefix() user_name = make_iam_name('AltUser') - response = iam_alt_root.create_user(UserName=user_name, Path=path) - user_arn = response['User']['Arn'] - account_id = user_arn.removeprefix('arn:aws:iam::').removesuffix(f':user{path}{user_name}') + iam_alt_root.create_user(UserName=user_name, Path=path) + + account_id = get_iam_alt_root_account_id() _test_cross_account_bucket_user_policy(roots3, iam_alt_root, user_name, account_id) @@ -2944,8 +2945,8 @@ def test_cross_account_root_bucket_policy_allow_account_arn(iam_root, iam_alt_ro def test_cross_account_root_bucket_policy_allow_account_id(iam_root, iam_alt_root): roots3 = get_iam_root_client(service_name='s3') alts3 = get_iam_alt_root_client(service_name='s3') - alt_arn = iam_alt_root.get_user()['User']['Arn'] - account_id = alt_arn.removeprefix('arn:aws:iam::').removesuffix(':root') + + account_id = get_iam_alt_root_account_id() _test_cross_account_root_bucket_policy(roots3, alts3, account_id) # test root cross-account access with bucket acls