Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Migrate moto IAM role tests#13749

Merged
dfangl merged 5 commits into
iam/moto-migrationfrom
daniel/unc-216
Feb 12, 2026
Merged

Migrate moto IAM role tests#13749
dfangl merged 5 commits into
iam/moto-migrationfrom
daniel/unc-216

Conversation

@dfangl

@dfangl dfangl commented Feb 12, 2026

Copy link
Copy Markdown
Member

Motivation

For our migration of IAM from moto into the LS codebase, we need to cover the same behvaior in our tests.
This PR migrates the tests for IAM roles (and their interactions with policies, etc.)

Changes

Migration Summary

LocalStack Class LocalStack Test Moto Tests Migrated
TestRoleLifecycle test_role_errors test_get_role__should_throw__when_role_does_not_exist, test_create_role_with_same_name_should_fail
test_create_role_defaults test_create_role_defaults, test_create_role_no_path
test_delete_role_with_attached_policy test_delete_role (managed policy section)
test_delete_role_with_inline_policy test_delete_role (inline policy section)
test_update_role test_update_role, test_update_role_description, test_update_role_defaults
test_update_assume_role_policy_errors test_update_assume_role_invalid_policy, test_update_assume_role_invalid_policy_bad_action, test_update_assume_role_invalid_policy_with_resource
test_list_roles_path_prefix test_list_roles_path_prefix_value_adhered, test_list_roles_none_found_returns_empty_list
TestRolePermissionsBoundary test_role_permissions_boundary test_create_role_with_permissions_boundary (create, get, put, delete boundary)
test_role_permissions_boundary_errors test_create_role_with_permissions_boundary (error cases)
TestRoleInlinePolicies test_role_inline_policy_lifecycle test_list_role_policies, test_put_role_policy, test_get_role_policy
TestRoleManagedPolicies test_role_managed_policy_lifecycle test_attach_detach_role_policy
test_role_managed_policy_errors test_only_detach_role_policy
TestRoleTags test_role_with_tags test_create_role_with_tags (partial)
test_role_tag_operations test_tag_role, test_untag_role
test_role_tag_errors test_tag_role (error cases), test_untag_role (error cases)
TestRolePagination test_list_roles_pagination test_list_roles_max_item_and_marker_values_adhered, test_list_roles_path_prefix_value_adhered, test_list_roles_none_found_returns_empty_list, test_list_roles

Detailed Mapping

TestRoleLifecycle

LocalStack Test Moto Test(s) Description
test_role_errors test_get_role__should_throw__when_role_does_not_exist (line 167), test_create_role_with_same_name_should_fail (line 3345) NoSuchEntity errors for get_role, update_role, delete_role; EntityAlreadyExists for duplicate role
test_create_role_defaults test_create_role_defaults (line 2721), test_create_role_no_path (line 3193) RoleId starts with AROA, MaxSessionDuration=3600, no Description/PermissionsBoundary
test_delete_role_with_attached_policy test_delete_role (line 352, managed policy section) DeleteConflict when managed policy attached
test_delete_role_with_inline_policy test_delete_role (line 352, inline policy section) DeleteConflict when inline policy exists
test_update_role test_update_role (line 3044), test_update_role_description (line 3029), test_update_role_defaults (line 3058) update_role and update_role_description operations; update with no params leaves values unchanged
test_update_assume_role_policy_errors test_update_assume_role_invalid_policy (line 528), test_update_assume_role_invalid_policy_bad_action (line 556), test_update_assume_role_invalid_policy_with_resource (line 589) Invalid JSON, invalid STS action, prohibited Resource field
test_list_roles_path_prefix test_list_roles_path_prefix_value_adhered (line 4727), test_list_roles_none_found_returns_empty_list (line 4746) PathPrefix filtering, empty result for non-matching prefix

TestRolePermissionsBoundary

LocalStack Test Moto Test(s) Description
test_role_permissions_boundary_lifecycle test_create_role_with_permissions_boundary (line 3301) Create role with boundary, get/put/delete permissions boundary lifecycle
test_role_permissions_boundary_errors test_create_role_with_permissions_boundary (line 3301, error section) Invalid ARN format, non-existent policy, non-existent role errors

TestRoleInlinePolicies

LocalStack Test Moto Test(s) Description
test_role_inline_policy_lifecycle test_list_role_policies (line 474), test_put_role_policy (line 504), test_get_role_policy (line 518) Put, get, list, delete inline policies

TestRoleManagedPolicies

LocalStack Test Moto Test(s) Description
test_role_managed_policy_lifecycle test_attach_detach_role_policy (line 2184) Attach, list, detach managed policies
test_role_managed_policy_errors test_only_detach_role_policy (line 2274) Detach non-attached policy error

TestRoleTags

LocalStack Test Moto Test(s) Description
test_role_with_tags test_create_role_with_tags (line 2734, partial) Create role with tags
test_role_tag_operations test_tag_role (line 2841), test_untag_role (line 2970) tag_role, list_role_tags, untag_role
test_role_tag_errors test_create_role_with_tags (line 2734, error section), test_tag_role (line 2841, error section), test_untag_role (line 2970, error section) NoSuchEntity, too many tags, duplicate keys, key/value length, invalid chars

TestRolePagination

LocalStack Test Moto Test(s) Description
test_list_roles_pagination test_list_roles_max_item_and_marker_values_adhered (line 4707), test_list_roles_path_prefix_value_adhered (line 4727), test_list_roles_none_found_returns_empty_list (line 4746), test_list_roles (line 4767) MaxItems, Marker, PathPrefix filtering

Tests NOT Migrated (Already Exist or Excluded)

Already Exist in test_iam.py

Existing Test Location Reason
test_create_role_with_malformed_assume_role_policy_document test_iam.py:149 Already exists
test_role_with_path_lifecycle test_iam.py:174 Already exists
test_recreate_iam_role test_iam.py:253 Already exists (covers test_create_role_with_same_name_should_fail)
test_update_assume_role_policy test_iam.py:603 Success case already exists
test_create_describe_role test_iam.py:636 Already exists
test_list_roles_with_permission_boundary test_iam.py:667 Partial coverage (put + list)
test_attach_detach_role_policy test_iam.py:383 Already exists
test_role_attach_policy test_iam.py:718 Already exists
test_put_role_policy_encoding test_iam.py:847 URL encoding edge case

Not Applicable

Moto Test Reason
test_get_role__should_contain_last_used Moto internal state test, not real AWS behavior
test_role_list_config_discovered_resources AWS Config, not IAM role API
test_role_config_dict AWS Config
test_role_config_client AWS Config
test_list_roles_with_more_than_100_roles_no_max_items_defaults_to_100 Scale test (100+ roles), basic pagination covered

Overall counts

Category Moto Tests LocalStack Tests
Role Lifecycle 8 7
Permissions Boundary 1 2
Inline Policies 3 2
Managed Policies 2 2
Role Tags 3 3
Pagination 4 1
Total ~21 17

Tests

All tests have been manually checked to cover the same behavior as moto does

Related

Closes UNC-216

@dfangl dfangl added semver: patch Non-breaking changes which can be included in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Feb 12, 2026
@github-actions

github-actions Bot commented Feb 12, 2026

Copy link
Copy Markdown

Test Results - Preflight, Unit

23 099 tests   21 237 ✅  6m 7s ⏱️
     1 suites   1 862 💤
     1 files         0 ❌

Results for commit 7c04148.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Feb 12, 2026

Copy link
Copy Markdown

Test Results (amd64) - Acceptance

7 tests   5 ✅  3m 2s ⏱️
1 suites  2 💤
1 files    0 ❌

Results for commit 7c04148.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Feb 12, 2026

Copy link
Copy Markdown

Test Results (amd64) - Integration, Bootstrap

  5 files    5 suites   9m 26s ⏱️
402 tests 215 ✅ 187 💤 0 ❌
408 runs  215 ✅ 193 💤 0 ❌

Results for commit 7c04148.

♻️ This comment has been updated with latest results.

@pinzon pinzon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR. 💯

@dfangl dfangl merged commit 5560ec8 into iam/moto-migration Feb 12, 2026
29 of 32 checks passed
@dfangl dfangl deleted the daniel/unc-216 branch February 12, 2026 16:25
dfangl added a commit that referenced this pull request Feb 16, 2026
dfangl added a commit that referenced this pull request Feb 17, 2026
dfangl added a commit that referenced this pull request Feb 19, 2026
dfangl added a commit that referenced this pull request Feb 26, 2026
dfangl added a commit that referenced this pull request Feb 26, 2026
dfangl added a commit that referenced this pull request Mar 4, 2026
dfangl added a commit that referenced this pull request Mar 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes semver: patch Non-breaking changes which can be included in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants