]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
iam: use config account_id instead of parsing ARNs
authorCasey Bodley <cbodley@redhat.com>
Mon, 31 Mar 2025 18:27:50 +0000 (14:27 -0400)
committerCasey Bodley <cbodley@redhat.com>
Mon, 11 May 2026 13:58:12 +0000 (09:58 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
s3tests/functional/test_iam.py

index da274fb1e8e02b4f55b6233f7efd692c63cc05f9..d1c44bfdb624b48e3b4130e1104fe67f95cf9d88 100644 (file)
@@ -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