mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): enforce case-insensitive resource names (#3986)
* fix(iam): enforce case-insensitive resource names Reject duplicate IAM user, group, role, and managed policy names that differ only by case. Signed-off-by: XuJian <265865031+xujiantop-crypto@users.noreply.github.com> * test(iam): cover case-insensitive resource names Signed-off-by: XuJian <265865031+xujiantop-crypto@users.noreply.github.com> * test(iam): verify case-insensitive names end to end Signed-off-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com> * fix(iam): enforce instance profile name uniqueness * fix(iam): preserve name uniqueness on group rename and legacy data * fix(iam): exclude managed catalog mirrors from name conflicts --------- Signed-off-by: XuJian <265865031+xujiantop-crypto@users.noreply.github.com> Signed-off-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
1 parent
133ef62d27
commit
d8a4f5e58e
4 files changed
+598
-127
No files matched your search
+182
@@ -0,0 +1,182 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.RequestContext;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamGroup;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamPolicy;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamRole;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamUser;
|
||||
import io.github.hectorvent.floci.services.iam.model.InstanceProfile;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class IamCaseInsensitiveLegacyNamesTest {
|
||||
|
||||
private static final String DEFAULT_ACCOUNT = "000000000000";
|
||||
private static final String OTHER_ACCOUNT = "111111111111";
|
||||
private static final String LEGACY_NAME = "LegacyName";
|
||||
private static final String LEGACY_POLICY_ARN =
|
||||
"arn:aws:iam::000000000000:policy/legacy/LegacyName";
|
||||
|
||||
private final StorageBackend<String, IamUser> users = new InMemoryStorage<>();
|
||||
private final StorageBackend<String, IamGroup> groups = new InMemoryStorage<>();
|
||||
private final StorageBackend<String, IamRole> roles = new InMemoryStorage<>();
|
||||
private final StorageBackend<String, IamPolicy> policies = new InMemoryStorage<>();
|
||||
private final StorageBackend<String, InstanceProfile> profiles = new InMemoryStorage<>();
|
||||
|
||||
enum ResourceType { USER, GROUP, ROLE, POLICY, INSTANCE_PROFILE }
|
||||
|
||||
@BeforeEach
|
||||
void seedUnprefixedLegacyResources() {
|
||||
IamService legacyService = new IamService(users, groups, roles, policies,
|
||||
new InMemoryStorage<>(), profiles, new InMemoryStorage<>(),
|
||||
new RegionResolver("us-east-1", DEFAULT_ACCOUNT));
|
||||
for (ResourceType type : ResourceType.values()) {
|
||||
create(legacyService, type, LEGACY_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(ResourceType.class)
|
||||
void createRejectsExactAndCaseVariantOfUnmigratedLegacyName(ResourceType type) {
|
||||
IamService service = serviceFor(DEFAULT_ACCOUNT);
|
||||
String originalId = legacyId(type);
|
||||
|
||||
assertAlreadyExists(() -> create(service, type, LEGACY_NAME));
|
||||
assertAlreadyExists(() -> create(service, type, "legacyname"));
|
||||
|
||||
assertEquals(originalId, legacyId(type));
|
||||
assertEquals(originalId, readId(service, type, DEFAULT_ACCOUNT));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(ResourceType.class)
|
||||
void anotherAccountCanReuseLegacyNameWithoutClaimingLegacyResource(ResourceType type) {
|
||||
String originalId = legacyId(type);
|
||||
IamService otherService = serviceFor(OTHER_ACCOUNT);
|
||||
|
||||
String otherId = create(otherService, type, LEGACY_NAME);
|
||||
|
||||
assertNotEquals(originalId, otherId);
|
||||
assertEquals(originalId, legacyId(type));
|
||||
assertEquals(otherId, readId(otherService, type, OTHER_ACCOUNT));
|
||||
IamService defaultService = serviceFor(DEFAULT_ACCOUNT);
|
||||
assertAlreadyExists(() -> create(defaultService, type, "legacyname"));
|
||||
assertEquals(originalId, readId(defaultService, type, DEFAULT_ACCOUNT));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserRejectsUnmigratedLegacyNameAndPreservesSource() {
|
||||
IamService service = serviceFor(DEFAULT_ACCOUNT);
|
||||
IamUser source = service.createUser("RenameSource", "/source/");
|
||||
String originalId = legacyId(ResourceType.USER);
|
||||
|
||||
assertAlreadyExists(() -> service.updateUser("RenameSource", LEGACY_NAME, null));
|
||||
assertAlreadyExists(() -> service.updateUser("RenameSource", "legacyname", null));
|
||||
|
||||
assertEquals(source.getUserId(), service.getUser("RenameSource").getUserId());
|
||||
assertEquals("RenameSource", source.getUserName());
|
||||
assertEquals("/source/", source.getPath());
|
||||
assertEquals(originalId, legacyId(ResourceType.USER));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void awsManagedPolicyMirrorsDoNotReserveCustomerPolicyNames(boolean accountPrefixed) {
|
||||
String managedArn = AwsManagedPolicies.ARN_PREFIX + "/AdministratorAccess";
|
||||
String mirrorKey = accountPrefixed ? DEFAULT_ACCOUNT + "/" + managedArn : managedArn;
|
||||
IamPolicy mirror = new IamPolicy("ANPALEGACYAWS", "AdministratorAccess", "/", managedArn,
|
||||
null, "{}");
|
||||
policies.put(mirrorKey, mirror);
|
||||
IamService service = serviceFor(DEFAULT_ACCOUNT);
|
||||
|
||||
IamPolicy customerPolicy = service.createPolicy("AdministratorAccess", "/customer/", null, "{}", null);
|
||||
|
||||
assertEquals("arn:aws:iam::000000000000:policy/customer/AdministratorAccess", customerPolicy.getArn());
|
||||
assertEquals("ANPALEGACYAWS", policies.get(mirrorKey).orElseThrow().getPolicyId());
|
||||
assertAlreadyExists(() -> service.createPolicy("administratoraccess", "/other/", null, "{}", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateGroupRejectsUnmigratedLegacyNameAndPreservesSource() {
|
||||
IamService service = serviceFor(DEFAULT_ACCOUNT);
|
||||
IamGroup source = service.createGroup("RenameSource", "/source/");
|
||||
String originalId = legacyId(ResourceType.GROUP);
|
||||
|
||||
assertAlreadyExists(() -> service.updateGroup("RenameSource", LEGACY_NAME, null));
|
||||
assertAlreadyExists(() -> service.updateGroup("RenameSource", "legacyname", null));
|
||||
|
||||
assertEquals(source.getGroupId(), service.getGroup("RenameSource").getGroupId());
|
||||
assertEquals("RenameSource", source.getGroupName());
|
||||
assertEquals("/source/", source.getPath());
|
||||
assertEquals(originalId, legacyId(ResourceType.GROUP));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private IamService serviceFor(String accountId) {
|
||||
RequestContext context = new RequestContext();
|
||||
context.setAccountId(accountId);
|
||||
Instance<RequestContext> contexts = mock(Instance.class);
|
||||
when(contexts.get()).thenReturn(context);
|
||||
return new IamService(scoped(users, contexts), scoped(groups, contexts), scoped(roles, contexts),
|
||||
scoped(policies, contexts), new InMemoryStorage<>(), scoped(profiles, contexts),
|
||||
new InMemoryStorage<>(), new RegionResolver("us-east-1", accountId));
|
||||
}
|
||||
|
||||
private static <T> AccountAwareStorageBackend<T> scoped(StorageBackend<String, T> raw,
|
||||
Instance<RequestContext> contexts) {
|
||||
return new AccountAwareStorageBackend<>(raw, contexts, DEFAULT_ACCOUNT);
|
||||
}
|
||||
|
||||
private static String create(IamService service, ResourceType type, String name) {
|
||||
return switch (type) {
|
||||
case USER -> service.createUser(name, "/legacy/").getUserId();
|
||||
case GROUP -> service.createGroup(name, "/legacy/").getGroupId();
|
||||
case ROLE -> service.createRole(name, "/legacy/", "{}", null, 3600, null).getRoleId();
|
||||
case POLICY -> service.createPolicy(name, "/legacy/", null, "{}", null).getPolicyId();
|
||||
case INSTANCE_PROFILE -> service.createInstanceProfile(name, "/legacy/").getInstanceProfileId();
|
||||
};
|
||||
}
|
||||
|
||||
private String legacyId(ResourceType type) {
|
||||
return switch (type) {
|
||||
case USER -> users.get(LEGACY_NAME).orElseThrow().getUserId();
|
||||
case GROUP -> groups.get(LEGACY_NAME).orElseThrow().getGroupId();
|
||||
case ROLE -> roles.get(LEGACY_NAME).orElseThrow().getRoleId();
|
||||
case POLICY -> policies.get(LEGACY_POLICY_ARN).orElseThrow().getPolicyId();
|
||||
case INSTANCE_PROFILE -> profiles.get(LEGACY_NAME).orElseThrow().getInstanceProfileId();
|
||||
};
|
||||
}
|
||||
|
||||
private static String readId(IamService service, ResourceType type, String accountId) {
|
||||
return switch (type) {
|
||||
case USER -> service.getUser(LEGACY_NAME).getUserId();
|
||||
case GROUP -> service.getGroup(LEGACY_NAME).getGroupId();
|
||||
case ROLE -> service.getRole(LEGACY_NAME).getRoleId();
|
||||
case POLICY -> service.getPolicy("arn:aws:iam::" + accountId + ":policy/legacy/" + LEGACY_NAME)
|
||||
.getPolicyId();
|
||||
case INSTANCE_PROFILE -> service.getInstanceProfile(LEGACY_NAME).getInstanceProfileId();
|
||||
};
|
||||
}
|
||||
|
||||
private static void assertAlreadyExists(Executable operation) {
|
||||
AwsException exception = assertThrows(AwsException.class, operation);
|
||||
assertEquals("EntityAlreadyExists", exception.getErrorCode());
|
||||
assertEquals(409, exception.getHttpStatus());
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class IamCaseInsensitiveNamesIntegrationTest {
|
||||
|
||||
private static final String AUTHORIZATION =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260920/us-east-1/iam/aws4_request";
|
||||
private static final String ACCOUNT_A_AUTHORIZATION =
|
||||
"AWS4-HMAC-SHA256 Credential=111111111111/20260920/us-east-1/iam/aws4_request";
|
||||
private static final String ACCOUNT_B_AUTHORIZATION =
|
||||
"AWS4-HMAC-SHA256 Credential=222222222222/20260920/us-east-1/iam/aws4_request";
|
||||
private static final String TRUST_POLICY =
|
||||
"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},"
|
||||
+ "\"Action\":\"sts:AssumeRole\"}]}";
|
||||
private static final String POLICY_DOCUMENT =
|
||||
"{\"Version\":\"2012-10-17\",\"Statement\":[]}";
|
||||
|
||||
@Test
|
||||
void createActionsRejectNamesThatDifferOnlyByCase() {
|
||||
iam("CreateUser", Map.of("UserName", "CaseCollisionUser")).statusCode(200);
|
||||
assertAlreadyExists("CreateUser", Map.of("UserName", "casecollisionuser"));
|
||||
|
||||
iam("CreateGroup", Map.of("GroupName", "CaseCollisionGroup")).statusCode(200);
|
||||
assertAlreadyExists("CreateGroup", Map.of("GroupName", "casecollisiongroup"));
|
||||
|
||||
iam("CreateRole", Map.of(
|
||||
"RoleName", "CaseCollisionRole",
|
||||
"AssumeRolePolicyDocument", TRUST_POLICY)).statusCode(200);
|
||||
assertAlreadyExists("CreateRole", Map.of(
|
||||
"RoleName", "casecollisionrole",
|
||||
"AssumeRolePolicyDocument", TRUST_POLICY));
|
||||
|
||||
iam("CreatePolicy", Map.of(
|
||||
"PolicyName", "CaseCollisionPolicy",
|
||||
"Path", "/first/",
|
||||
"PolicyDocument", POLICY_DOCUMENT)).statusCode(200);
|
||||
assertAlreadyExists("CreatePolicy", Map.of(
|
||||
"PolicyName", "casecollisionpolicy",
|
||||
"Path", "/second/",
|
||||
"PolicyDocument", POLICY_DOCUMENT));
|
||||
|
||||
iam("CreateInstanceProfile", Map.of("InstanceProfileName", "CaseCollisionProfile"))
|
||||
.statusCode(200);
|
||||
assertAlreadyExists(
|
||||
"CreateInstanceProfile", Map.of("InstanceProfileName", "casecollisionprofile"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void caseInsensitiveUniquenessRemainsScopedToTheAccount() {
|
||||
Map<String, String> parameters = Map.of("UserName", "AccountScopedCaseName");
|
||||
|
||||
iam(ACCOUNT_A_AUTHORIZATION, "CreateUser", parameters).statusCode(200);
|
||||
iam(ACCOUNT_B_AUTHORIZATION, "CreateUser", parameters).statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserRejectsAnotherUserNameThatDiffersOnlyByCase() {
|
||||
iam("CreateUser", Map.of("UserName", "CaseRenameTarget")).statusCode(200);
|
||||
iam("CreateUser", Map.of("UserName", "CaseRenameSource")).statusCode(200);
|
||||
|
||||
assertAlreadyExists("UpdateUser", Map.of(
|
||||
"UserName", "CaseRenameSource",
|
||||
"NewUserName", "CASERENAMETARGET"));
|
||||
|
||||
iam("GetUser", Map.of("UserName", "CaseRenameSource"))
|
||||
.statusCode(200)
|
||||
.body("GetUserResponse.GetUserResult.User.UserName", equalTo("CaseRenameSource"));
|
||||
}
|
||||
|
||||
private static void assertAlreadyExists(String action, Map<String, String> parameters) {
|
||||
iam(action, parameters)
|
||||
.statusCode(409)
|
||||
.body("ErrorResponse.Error.Code", equalTo("EntityAlreadyExists"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateGroupRejectsCaseCollisionWithoutChangingTheSourceGroup() {
|
||||
iam("CreateGroup", Map.of("GroupName", "CaseGroupRenameTarget")).statusCode(200);
|
||||
iam("CreateGroup", Map.of("GroupName", "CaseGroupRenameSource", "Path", "/original/"))
|
||||
.statusCode(200);
|
||||
|
||||
assertAlreadyExists("UpdateGroup", Map.of(
|
||||
"GroupName", "CaseGroupRenameSource",
|
||||
"NewGroupName", "casegrouprenametarget",
|
||||
"NewPath", "/changed/"));
|
||||
|
||||
iam("GetGroup", Map.of("GroupName", "CaseGroupRenameSource"))
|
||||
.statusCode(200)
|
||||
.body("GetGroupResponse.GetGroupResult.Group.GroupName", equalTo("CaseGroupRenameSource"))
|
||||
.body("GetGroupResponse.GetGroupResult.Group.Path", equalTo("/original/"));
|
||||
}
|
||||
|
||||
private static ValidatableResponse iam(String action, Map<String, String> parameters) {
|
||||
return iam(AUTHORIZATION, action, parameters);
|
||||
}
|
||||
|
||||
private static ValidatableResponse iam(String authorization, String action, Map<String, String> parameters) {
|
||||
return given()
|
||||
.formParam("Action", action)
|
||||
.formParams(parameters)
|
||||
.header("Authorization", authorization)
|
||||
.when()
|
||||
.post("/")
|
||||
.then();
|
||||
}
|
||||
}
|
||||
@@ -186,6 +186,17 @@ class IamServiceTest {
|
||||
assertThrows(AwsException.class, () -> iamService.createUser("alice", "/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createUserRejectsNameThatDiffersOnlyByCase() {
|
||||
iamService.createUser("CaseUser", "/");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> iamService.createUser("caseuser", "/"));
|
||||
|
||||
assertEquals("EntityAlreadyExists", error.getErrorCode());
|
||||
assertEquals(409, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getUserNotFoundThrows() {
|
||||
assertThrows(AwsException.class, () -> iamService.getUser("nonexistent"));
|
||||
@@ -231,6 +242,29 @@ class IamServiceTest {
|
||||
assertEquals("/new/", renamed.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserRejectsAnotherUserNameThatDiffersOnlyByCase() {
|
||||
iamService.createUser("CaseUser", "/");
|
||||
iamService.createUser("Other", "/");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> iamService.updateUser("Other", "CASEUSER", null));
|
||||
|
||||
assertEquals("EntityAlreadyExists", error.getErrorCode());
|
||||
assertEquals(409, error.getHttpStatus());
|
||||
assertEquals("Other", iamService.getUser("Other").getUserName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserAllowsChangingOnlyItsOwnNameCase() {
|
||||
iamService.createUser("CaseUser", "/");
|
||||
|
||||
iamService.updateUser("CaseUser", "caseuser", null);
|
||||
|
||||
assertEquals("caseuser", iamService.getUser("caseuser").getUserName());
|
||||
assertThrows(AwsException.class, () -> iamService.getUser("CaseUser"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagAndUntagUser() {
|
||||
iamService.createUser("alice", "/");
|
||||
@@ -463,6 +497,17 @@ class IamServiceTest {
|
||||
assertEquals("arn:aws:iam::000000000000:group/developers", group.getArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGroupRejectsNameThatDiffersOnlyByCase() {
|
||||
iamService.createGroup("CaseGroup", "/");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> iamService.createGroup("casegroup", "/"));
|
||||
|
||||
assertEquals("EntityAlreadyExists", error.getErrorCode());
|
||||
assertEquals(409, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addAndRemoveUserFromGroup() {
|
||||
iamService.createUser("alice", "/");
|
||||
@@ -541,6 +586,17 @@ class IamServiceTest {
|
||||
assertEquals("Lambda role", role.getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRoleRejectsNameThatDiffersOnlyByCase() {
|
||||
iamService.createRole("CaseRole", "/", "{}", null, 3600, null);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> iamService.createRole("caserole", "/", "{}", null, 3600, null));
|
||||
|
||||
assertEquals("EntityAlreadyExists", error.getErrorCode());
|
||||
assertEquals(409, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAssumeRolePolicyWithMatchingExpectedIdApplies() {
|
||||
IamRole role = iamService.createRole("LambdaExec", "/", "{}", null, 3600, null);
|
||||
@@ -600,6 +656,17 @@ class IamServiceTest {
|
||||
assertEquals("AWSServiceRoleForAccessAnalyzer_myapp", role.getRoleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createServiceLinkedRoleRejectsCaseInsensitiveRoleNameCollisionAsInvalidInput() {
|
||||
iamService.createRole("awsserviceroleforaccessanalyzer", "/", "{}", null, 0, null);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> iamService.createServiceLinkedRole("access-analyzer.amazonaws.com", null, null));
|
||||
|
||||
assertEquals("InvalidInput", error.getErrorCode());
|
||||
assertEquals(400, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRoleWithAttachedPolicyFails() {
|
||||
iamService.createRole("LambdaExec", "/", "{}", null, 0, null);
|
||||
@@ -637,6 +704,17 @@ class IamServiceTest {
|
||||
assertEquals(doc, policy.getDefaultDocument());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createPolicyRejectsCaseInsensitiveNameAcrossPaths() {
|
||||
iamService.createPolicy("CasePolicy", "/first/", null, "{}", null);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> iamService.createPolicy("casepolicy", "/second/", null, "{}", null));
|
||||
|
||||
assertEquals("EntityAlreadyExists", error.getErrorCode());
|
||||
assertEquals(409, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsManagedReadOnlyPolicyAllowsReadsButDeniesWrites() {
|
||||
String arn = AwsManagedPolicies.ARN_PREFIX + "/AmazonS3ReadOnlyAccess";
|
||||
@@ -801,6 +879,36 @@ class IamServiceTest {
|
||||
"a legacy-rehydrated policy must not reissue the id of a version deleted before upgrade");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateGroupRejectsAnotherGroupNameThatDiffersOnlyByCase() {
|
||||
IamGroup target = iamService.createGroup("CaseGroup", "/");
|
||||
IamGroup source = iamService.createGroup("OtherGroup", "/original/");
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> iamService.updateGroup("OtherGroup", "casegroup", "/changed/"));
|
||||
|
||||
assertEquals("EntityAlreadyExists", exception.getErrorCode());
|
||||
assertEquals(source.getGroupId(), iamService.getGroup("OtherGroup").getGroupId());
|
||||
assertEquals("/original/", iamService.getGroup("OtherGroup").getPath());
|
||||
assertEquals(target.getGroupId(), iamService.getGroup("CaseGroup").getGroupId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateGroupAllowsChangingOnlyItsOwnNameCaseAndPreservesMembers() {
|
||||
IamGroup original = iamService.createGroup("CaseGroup", "/original/");
|
||||
iamService.createUser("case-group-member", "/");
|
||||
iamService.addUserToGroup("CaseGroup", "case-group-member");
|
||||
|
||||
iamService.updateGroup("CaseGroup", "casegroup", "/changed/");
|
||||
|
||||
IamGroup renamed = iamService.getGroup("casegroup");
|
||||
assertEquals(original.getGroupId(), renamed.getGroupId());
|
||||
assertEquals("/changed/", renamed.getPath());
|
||||
assertEquals(List.of("case-group-member"), renamed.getUserNames());
|
||||
assertEquals(List.of("casegroup"), iamService.getUser("case-group-member").getGroupNames());
|
||||
assertThrows(AwsException.class, () -> iamService.getGroup("CaseGroup"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateGroupMalformedNewGroupNameIsRejected() {
|
||||
iamService.createGroup("orig-group", "/");
|
||||
@@ -1202,6 +1310,17 @@ class IamServiceTest {
|
||||
assertEquals("arn:aws:iam::000000000000:instance-profile/MyProfile", profile.getArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createInstanceProfileRejectsNameThatDiffersOnlyByCase() {
|
||||
iamService.createInstanceProfile("CaseProfile", "/");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> iamService.createInstanceProfile("caseprofile", "/"));
|
||||
|
||||
assertEquals("EntityAlreadyExists", error.getErrorCode());
|
||||
assertEquals(409, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addAndRemoveRoleFromInstanceProfile() {
|
||||
iamService.createRole("LambdaExec", "/", "{}", null, 0, null);
|
||||
|
||||
Reference in new issue
Block a user