Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(cfn): support oauth and callback configurations in UserPoolClient (#1458)

MAN$I VERMA4bd43020d5e0
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java
index 19b203883a..b83bdf3909 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java
@@ -2827,13 +2827,39 @@ public class CloudFormationResourceProvisioner {
List<String> allowedOAuthFlows = resolveStringListOrEmpty(props, "AllowedOAuthFlows", engine);
List<String> allowedOAuthScopes = resolveStringListOrEmpty(props, "AllowedOAuthScopes", engine);
+ Map<String, Object> analyticsConfiguration = resolveMapOrDefault(props, "AnalyticsConfiguration", engine, null);
+ List<String> callbackURLs = resolveStringListOrEmpty(props, "CallbackURLs", engine);
+ String defaultRedirectURI = resolveOptional(props, "DefaultRedirectURI", engine);
+ List<String> explicitAuthFlows = resolveStringListOrEmpty(props, "ExplicitAuthFlows", engine);
+ Integer accessTokenValidity = parseIntegerPropOrNull(props, "AccessTokenValidity", engine);
+ Integer idTokenValidity = parseIntegerPropOrNull(props, "IdTokenValidity", engine);
+ List<String> logoutURLs = resolveStringListOrEmpty(props, "LogoutURLs", engine);
+ String preventUserExistenceErrors = resolveOptional(props, "PreventUserExistenceErrors", engine);
+ List<String> readAttributes = resolveStringListOrEmpty(props, "ReadAttributes", engine);
+ Integer refreshTokenValidity = parseIntegerPropOrNull(props, "RefreshTokenValidity", engine);
+ List<String> supportedIdentityProviders = resolveStringListOrEmpty(props, "SupportedIdentityProviders", engine);
+ Map<String, String> tokenValidityUnits = resolveStringMapOrNull(props, "TokenValidityUnits", engine);
+ List<String> writeAttributes = resolveStringListOrEmpty(props, "WriteAttributes", engine);
+ Map<String, Object> refreshTokenRotation = resolveMapOrDefault(props, "RefreshTokenRotation", engine, null);
+ Boolean enableTokenRevocation = parseBooleanOrNull(resolveOptional(props, "EnableTokenRevocation", engine));
+
UserPoolClient client;
if (r.getPhysicalId() == null) {
- client = cognitoService.createUserPoolClient(userPoolId, clientName, generateSecret,
- allowedOAuthFlowsUserPoolClient, allowedOAuthFlows, allowedOAuthScopes);
+ client = cognitoService.createUserPoolClient(
+ userPoolId, clientName, generateSecret, allowedOAuthFlowsUserPoolClient,
+ allowedOAuthFlows, allowedOAuthScopes, analyticsConfiguration, callbackURLs,
+ defaultRedirectURI, explicitAuthFlows, accessTokenValidity, idTokenValidity,
+ logoutURLs, preventUserExistenceErrors, readAttributes, refreshTokenValidity,
+ supportedIdentityProviders, tokenValidityUnits, writeAttributes,
+ refreshTokenRotation, enableTokenRevocation);
} else {
- client = cognitoService.updateUserPoolClient(userPoolId, r.getPhysicalId(), clientName,
- allowedOAuthFlowsUserPoolClient, allowedOAuthFlows, allowedOAuthScopes);
+ client = cognitoService.updateUserPoolClient(
+ userPoolId, r.getPhysicalId(), clientName, allowedOAuthFlowsUserPoolClient,
+ allowedOAuthFlows, allowedOAuthScopes, analyticsConfiguration, callbackURLs,
+ defaultRedirectURI, explicitAuthFlows, accessTokenValidity, idTokenValidity,
+ logoutURLs, preventUserExistenceErrors, readAttributes, refreshTokenValidity,
+ supportedIdentityProviders, tokenValidityUnits, writeAttributes,
+ refreshTokenRotation, enableTokenRevocation);
}
r.setPhysicalId(client.getClientId());
@@ -2844,6 +2870,31 @@ public class CloudFormationResourceProvisioner {
}
}
+ private Integer parseIntegerPropOrNull(JsonNode props, String name, CloudFormationTemplateEngine engine) {
+ String value = resolveOptional(props, name, engine);
+ if (value == null || value.isBlank()) {
+ return null;
+ }
+ try {
+ return Integer.valueOf(value.trim());
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ private Map<String, String> resolveStringMapOrNull(JsonNode props, String source, CloudFormationTemplateEngine engine) {
+ if (props == null || !props.has(source) || props.get(source).isNull()) {
+ return null;
+ }
+ JsonNode resolved = engine.resolveNode(props.get(source));
+ if (resolved == null || !resolved.isObject()) {
+ return null;
+ }
+ Map<String, String> out = new LinkedHashMap<>();
+ resolved.fields().forEachRemaining(e -> out.put(e.getKey(), e.getValue().asText()));
+ return out;
+ }
+
// ── Lambda LayerVersion ──────────────────────────────────────────────────
//
// Without this, layer versions (e.g. CDK's AwsCliLayer) fall through to the stub, so the
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java
index 60de055cf6..f3505082b9 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java
@@ -23,6 +23,7 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.matchesRegex;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
@@ -4717,6 +4718,107 @@ class CloudFormationIntegrationTest {
.statusCode(404);
}
+ @Test
+ void createStack_withCognitoUserPoolClientOAuthFlowsAndCallbacks() {
+ String template = """
+ {
+ "Resources": {
+ "Pool": {
+ "Type": "AWS::Cognito::UserPool",
+ "Properties": {
+ "UserPoolName": "cfn-oauth-test-pool"
+ }
+ },
+ "Client": {
+ "Type": "AWS::Cognito::UserPoolClient",
+ "Properties": {
+ "ClientName": "web-client",
+ "UserPoolId": {"Ref": "Pool"},
+ "AllowedOAuthFlows": ["implicit", "code"],
+ "AllowedOAuthFlowsUserPoolClient": true,
+ "AllowedOAuthScopes": ["openid", "profile", "email"],
+ "CallbackURLs": ["https://example.local/signin-redirect"],
+ "LogoutURLs": ["https://example.local"],
+ "SupportedIdentityProviders": ["COGNITO"],
+ "GenerateSecret": false
+ }
+ }
+ },
+ "Outputs": {
+ "PoolId": { "Value": { "Ref": "Pool" } },
+ "ClientId": { "Value": { "Ref": "Client" } }
+ }
+ }
+ """;
+
+ String stackName = "cognito-oauth-stack";
+
+ // 1. Create Stack
+ given()
+ .contentType("application/x-www-form-urlencoded")
+ .formParam("Action", "CreateStack")
+ .formParam("StackName", stackName)
+ .formParam("TemplateBody", template)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body(containsString("<StackId>"));
+
+ // 2. Describe Stacks and capture outputs
+ String describeXml = given()
+ .contentType("application/x-www-form-urlencoded")
+ .formParam("Action", "DescribeStacks")
+ .formParam("StackName", stackName)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"))
+ .extract().asString();
+
+ String poolId = describeXml.split("<OutputKey>PoolId</OutputKey>")[1].split("<OutputValue>")[1].split("</OutputValue>")[0];
+ String clientId = describeXml.split("<OutputKey>ClientId</OutputKey>")[1].split("<OutputValue>")[1].split("</OutputValue>")[0];
+
+ // 3. Verify UserPoolClient via Cognito API
+ given()
+ .header("X-Amz-Target", "AWSCognitoIdentityProviderService.DescribeUserPoolClient")
+ .contentType(COGNITO_CONTENT_TYPE)
+ .body("{\"UserPoolId\": \"" + poolId + "\", \"ClientId\": \"" + clientId + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("UserPoolClient.ClientName", equalTo("web-client"))
+ .body("UserPoolClient.UserPoolId", equalTo(poolId))
+ .body("UserPoolClient.AllowedOAuthFlowsUserPoolClient", equalTo(true))
+ .body("UserPoolClient.AllowedOAuthFlows", hasItems("implicit", "code"))
+ .body("UserPoolClient.AllowedOAuthScopes", hasItems("openid", "profile", "email"))
+ .body("UserPoolClient.CallbackURLs", hasItems("https://example.local/signin-redirect"))
+ .body("UserPoolClient.LogoutURLs", hasItems("https://example.local"))
+ .body("UserPoolClient.SupportedIdentityProviders", hasItems("COGNITO"));
+
+ // 4. Delete Stack
+ given()
+ .contentType("application/x-www-form-urlencoded")
+ .formParam("Action", "DeleteStack")
+ .formParam("StackName", stackName)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ // 5. Verify resources are deleted
+ given()
+ .header("X-Amz-Target", "AWSCognitoIdentityProviderService.DescribeUserPoolClient")
+ .contentType(COGNITO_CONTENT_TYPE)
+ .body("{\"UserPoolId\": \"" + poolId + "\", \"ClientId\": \"" + clientId + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(404);
+ }
+
@Test
void createStack_withNestedStack_resourcesAreProvisioned() {
String childTemplate = """