Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

feat(cognito): add TagResource, UntagResource, ListTagsForResource for user pools (#579) (#591)

iam-ssrivastav5f94b429c21a
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java
index fa21d68c66..ed7c156259 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java
@@ -47,6 +47,7 @@ public class CognitoJsonHandler {
case "DescribeUserPoolClient" -> handleDescribeUserPoolClient(request);
case "ListUserPoolClients" -> handleListUserPoolClients(request);
case "DeleteUserPoolClient" -> handleDeleteUserPoolClient(request);
+ case "UpdateUserPoolClient" -> handleUpdateUserPoolClient(request);
case "CreateResourceServer" -> handleCreateResourceServer(request);
case "DescribeResourceServer" -> handleDescribeResourceServer(request);
case "ListResourceServers" -> handleListResourceServers(request);
@@ -192,6 +193,20 @@ public class CognitoJsonHandler {
return Response.ok(objectMapper.createObjectNode()).build();
}
+ private Response handleUpdateUserPoolClient(JsonNode request) {
+ UserPoolClient client = service.updateUserPoolClient(
+ request.path("UserPoolId").asText(),
+ request.path("ClientId").asText(),
+ request.has("ClientName") ? request.path("ClientName").asText() : null,
+ request.has("AllowedOAuthFlowsUserPoolClient") ? request.path("AllowedOAuthFlowsUserPoolClient").asBoolean() : null,
+ readStringList(request.path("AllowedOAuthFlows")),
+ readStringList(request.path("AllowedOAuthScopes"))
+ );
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("UserPoolClient", clientToNode(client));
+ return Response.ok(response).build();
+ }
+
private Response handleCreateResourceServer(JsonNode request) {
ResourceServer server = service.createResourceServer(
request.path("UserPoolId").asText(),
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
index 346d10fbb1..24e6dc5cbd 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
@@ -264,6 +264,28 @@ public class CognitoService {
clientStore.delete(clientId);
}
+ public UserPoolClient updateUserPoolClient(String userPoolId, String clientId, String clientName,
+ Boolean allowedOAuthFlowsUserPoolClient,
+ List<String> allowedOAuthFlows,
+ List<String> allowedOAuthScopes) {
+ UserPoolClient client = describeUserPoolClient(userPoolId, clientId);
+ if (clientName != null) client.setClientName(clientName);
+ if (allowedOAuthFlowsUserPoolClient != null) {
+ client.setAllowedOAuthFlowsUserPoolClient(allowedOAuthFlowsUserPoolClient);
+ }
+ if (allowedOAuthFlows != null) {
+ client.setAllowedOAuthFlows(normalizeStringList(allowedOAuthFlows));
+ }
+ if (allowedOAuthScopes != null) {
+ client.setAllowedOAuthScopes(normalizeStringList(allowedOAuthScopes));
+ }
+
+ client.setLastModifiedDate(System.currentTimeMillis() / 1000L);
+ clientStore.put(clientId, client);
+ LOG.infov("Updated User Pool Client: {0} for pool {1}", clientId, userPoolId);
+ return client;
+ }
+
public List<UserPoolClientSecret> listUserPoolClientSecrets(String userPoolId, String clientId) {
UserPoolClient client = clientStore.get(clientId)
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "User pool client not found", 404));
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoIntegrationTest.java
index e7a9991922..607b539c5b 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoIntegrationTest.java
@@ -481,6 +481,53 @@ class CognitoIntegrationTest {
"DescribeUserPoolClient must include GenerateSecret");
}
+ @Test
+ @Order(36)
+ void updateUserPoolClient() throws Exception {
+ // 1. Create a client
+ JsonNode createResp = cognitoJson("CreateUserPoolClient", """
+ {
+ "UserPoolId": "%s",
+ "ClientName": "initial-name"
+ }
+ """.formatted(poolId));
+ String cid = createResp.path("UserPoolClient").path("ClientId").asText();
+
+ // 2. Update the client
+ cognitoJson("UpdateUserPoolClient", """
+ {
+ "UserPoolId": "%s",
+ "ClientId": "%s",
+ "ClientName": "updated-name",
+ "AllowedOAuthFlowsUserPoolClient": true,
+ "AllowedOAuthFlows": ["code", "implicit"],
+ "AllowedOAuthScopes": ["email", "openid"]
+ }
+ """.formatted(poolId, cid));
+
+ // 3. Verify the updates
+ JsonNode describeResp = cognitoJson("DescribeUserPoolClient", """
+ {
+ "UserPoolId": "%s",
+ "ClientId": "%s"
+ }
+ """.formatted(poolId, cid));
+ JsonNode client = describeResp.path("UserPoolClient");
+
+ assertEquals("updated-name", client.path("ClientName").asText());
+ assertEquals(true, client.path("AllowedOAuthFlowsUserPoolClient").asBoolean());
+
+ JsonNode flows = client.path("AllowedOAuthFlows");
+ assertEquals(2, flows.size());
+ assertTrue(flows.toString().contains("code"));
+ assertTrue(flows.toString().contains("implicit"));
+
+ JsonNode scopes = client.path("AllowedOAuthScopes");
+ assertEquals(2, scopes.size());
+ assertTrue(scopes.toString().contains("email"));
+ assertTrue(scopes.toString().contains("openid"));
+ }
+
// ── Issue #229: Password verification ──────────────────────────────
@Test