mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 09:22:49 -05:00
feat(cognito): add TagResource, UntagResource, ListTagsForResource for user pools (#579)
* feat(cognito): add TagResource, UntagResource, ListTagsForResource for user pools Dispatch the three Cognito IDP tag operations through CognitoJsonHandler and resolve user pools by parsing the resource ARN (O(1) pool-store lookup, not a full scan). Malformed ARNs now surface as InvalidParameterException rather than a swallowed ResourceNotFoundException. Reject reserved floci:* keys on standalone TagResource via ReservedTags.rejectReservedTagsOnUpdate, matching the existing strip-on-write behavior on CreateUserPool / UpdateUserPool. Mutations are synchronized on the pool instance to match the ensureJwtSigningKeys pattern. Covered by new unit tests (CognitoServiceTest, CognitoJsonHandlerTest), AWS CLI bats (cognito.bats), and Java SDK compat tests (CognitoFeaturesTest). * chore: retrigger CI
This commit is contained in:
9 files changed
+305
-4
No files matched your search
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.ReservedTags;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
@@ -151,4 +152,59 @@ class CognitoJsonHandlerTest {
|
||||
assertEquals("test", describedPool.get("UserPoolTags").get("env").asText());
|
||||
assertFalse(describedPool.get("UserPoolTags").has(ReservedTags.OVERRIDE_ID_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagListAndUntagResourceRoundTrip() {
|
||||
ObjectNode createRequest = mapper.createObjectNode();
|
||||
createRequest.put("PoolName", "tag-pool");
|
||||
JsonNode createBody = (JsonNode) handler.handle("CreateUserPool", createRequest, "us-east-1").getEntity();
|
||||
JsonNode createdPool = createBody.get("UserPool");
|
||||
String resourceArn = createdPool.get("Arn").asText();
|
||||
|
||||
ObjectNode tagRequest = mapper.createObjectNode();
|
||||
tagRequest.put("ResourceArn", resourceArn);
|
||||
ObjectNode tags = tagRequest.putObject("Tags");
|
||||
tags.put("env", "test");
|
||||
tags.put("team", "platform");
|
||||
|
||||
Response tagResponse = handler.handle("TagResource", tagRequest, "us-east-1");
|
||||
assertEquals(200, tagResponse.getStatus());
|
||||
|
||||
ObjectNode listRequest = mapper.createObjectNode();
|
||||
listRequest.put("ResourceArn", resourceArn);
|
||||
Response listResponse = handler.handle("ListTagsForResource", listRequest, "us-east-1");
|
||||
assertEquals(200, listResponse.getStatus());
|
||||
JsonNode listedTags = ((JsonNode) listResponse.getEntity()).get("Tags");
|
||||
assertEquals("test", listedTags.get("env").asText());
|
||||
assertEquals("platform", listedTags.get("team").asText());
|
||||
|
||||
ObjectNode untagRequest = mapper.createObjectNode();
|
||||
untagRequest.put("ResourceArn", resourceArn);
|
||||
untagRequest.putArray("TagKeys").add("team");
|
||||
|
||||
Response untagResponse = handler.handle("UntagResource", untagRequest, "us-east-1");
|
||||
assertEquals(200, untagResponse.getStatus());
|
||||
|
||||
JsonNode afterUntag = ((JsonNode) handler.handle("ListTagsForResource", listRequest, "us-east-1").getEntity()).get("Tags");
|
||||
assertEquals("test", afterUntag.get("env").asText());
|
||||
assertFalse(afterUntag.has("team"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceRejectsReservedKey() {
|
||||
ObjectNode createRequest = mapper.createObjectNode();
|
||||
createRequest.put("PoolName", "tag-pool");
|
||||
JsonNode createBody = (JsonNode) handler.handle("CreateUserPool", createRequest, "us-east-1").getEntity();
|
||||
String resourceArn = createBody.get("UserPool").get("Arn").asText();
|
||||
|
||||
ObjectNode tagRequest = mapper.createObjectNode();
|
||||
tagRequest.put("ResourceArn", resourceArn);
|
||||
tagRequest.putObject("Tags").put(ReservedTags.OVERRIDE_ID_KEY, "late-id");
|
||||
|
||||
AwsException exception = assertThrows(
|
||||
AwsException.class,
|
||||
() -> handler.handle("TagResource", tagRequest, "us-east-1")
|
||||
);
|
||||
assertEquals("ValidationException", exception.getErrorCode());
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,90 @@ class CognitoServiceTest {
|
||||
assertEquals(Map.of("env", "test"), updated.getUserPoolTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceAddsAndOverwritesTags() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TaggedPool", "UserPoolTags", Map.of("env", "dev")),
|
||||
"us-east-1"
|
||||
);
|
||||
|
||||
service.tagResource(pool.getArn(), Map.of("team", "platform", "env", "test"));
|
||||
|
||||
assertEquals(Map.of("env", "test", "team", "platform"), service.listTagsForResource(pool.getArn()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceRejectsReservedKey() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TaggedPool"), "us-east-1");
|
||||
|
||||
AwsException exception = assertThrows(
|
||||
AwsException.class,
|
||||
() -> service.tagResource(pool.getArn(), Map.of(ReservedTags.OVERRIDE_ID_KEY, "late-id"))
|
||||
);
|
||||
|
||||
assertEquals("ValidationException", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceRejectsEmptyTags() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TaggedPool"), "us-east-1");
|
||||
|
||||
AwsException exception = assertThrows(
|
||||
AwsException.class,
|
||||
() -> service.tagResource(pool.getArn(), Map.of())
|
||||
);
|
||||
|
||||
assertEquals("InvalidParameterException", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceWithUnknownArnThrowsNotFound() {
|
||||
AwsException exception = assertThrows(
|
||||
AwsException.class,
|
||||
() -> service.tagResource("arn:aws:cognito-idp:us-east-1:000000000000:userpool/us-east-1_missing", Map.of("env", "test"))
|
||||
);
|
||||
|
||||
assertEquals("ResourceNotFoundException", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void untagResourceRemovesRequestedKeysAndAllowsReservedRemoval() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TaggedPool", "UserPoolTags", Map.of("env", "test", "team", "platform")),
|
||||
"us-east-1"
|
||||
);
|
||||
|
||||
service.untagResource(pool.getArn(), List.of("team", ReservedTags.OVERRIDE_ID_KEY));
|
||||
|
||||
assertEquals(Map.of("env", "test"), service.listTagsForResource(pool.getArn()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTagsForResourceReturnsCurrentTags() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TaggedPool", "UserPoolTags", Map.of("env", "test")),
|
||||
"us-east-1"
|
||||
);
|
||||
|
||||
assertEquals(Map.of("env", "test"), service.listTagsForResource(pool.getArn()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserPoolAndTagResourceShareConsistentVisibleTagBehavior() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TaggedPool"), "us-east-1");
|
||||
|
||||
service.updateUserPool(
|
||||
Map.of(
|
||||
"UserPoolId", pool.getId(),
|
||||
"UserPoolTags", Map.of(ReservedTags.OVERRIDE_ID_KEY, "late-id", "env", "test")
|
||||
),
|
||||
"us-east-1"
|
||||
);
|
||||
service.tagResource(pool.getArn(), Map.of("team", "platform"));
|
||||
|
||||
assertEquals(Map.of("env", "test", "team", "platform"), service.listTagsForResource(pool.getArn()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void issuerUrlForPinnedPoolResolvesAsBaseUrlSlashPoolId() {
|
||||
UserPool pool = service.createUserPool(
|
||||
|
||||
Reference in new issue
Block a user