From 809ce40f1e5b29debcfbb88cbd60d65071243a4c Mon Sep 17 00:00:00 2001 From: XuJian Date: Mon, 14 Sep 2026 09:22:27 +0900 Subject: [PATCH] fix(cloudformation): identify unsupported SAM Cognito authorizers (#3535) Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com> --- .../cloudformation/SamTransformProcessor.java | 7 +++++ .../SamTransformProcessorTest.java | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/SamTransformProcessor.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/SamTransformProcessor.java index ddfd0fc57c..c06b419cd6 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/SamTransformProcessor.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/SamTransformProcessor.java @@ -566,6 +566,13 @@ class SamTransformProcessor { Map.Entry entry = it.next(); String name = entry.getKey(); JsonNode config = entry.getValue(); + if (config.has("UserPoolArn") + || "COGNITO_USER_POOLS".equals(config.path("AuthType").asText())) { + throw new AwsException("ValidationError", + "SAM implicit REST API authorizer " + name + + " configures a Cognito user pool authorizer, which Floci does not " + + "support for SAM implicit REST APIs yet.", 400); + } String payloadType = config.path("FunctionPayloadType").asText("TOKEN"); if (!"REQUEST".equals(payloadType)) { throw new AwsException("ValidationError", diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/SamTransformProcessorTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/SamTransformProcessorTest.java index c0492bbd0f..40e31da2eb 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/SamTransformProcessorTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/SamTransformProcessorTest.java @@ -937,6 +937,35 @@ class SamTransformProcessorTest { assertTrue(authPermission, "expected SAM to grant API Gateway permission to invoke the authorizer"); } + @Test + void expandSamTemplate_implicitApiCognitoAuthorizerReportsUnsupportedCapability() throws Exception { + JsonNode template = objectMapper.readTree(""" + { + "Transform": "AWS::Serverless-2016-10-31", + "Globals": {"Api": {"Auth": { + "DefaultAuthorizer": "MyCognitoAuth", + "Authorizers": {"MyCognitoAuth": { + "AuthType": "COGNITO_USER_POOLS", + "UserPoolArn": "arn:aws:cognito-idp:us-east-1:000000000000:userpool/us-east-1_example" + }} + }}}, + "Resources": { + "Fn": {"Type": "AWS::Serverless::Function", "Properties": { + "Handler": "index.handler", "Runtime": "nodejs20.x", "InlineCode": "code", + "Events": {"Get": {"Type": "Api", "Properties": {"Path": "/x", "Method": "GET"}}} + }} + } + } + """); + + AwsException error = assertThrows(AwsException.class, () -> processor.expandSamTemplate(template)); + + assertEquals("ValidationError", error.getErrorCode()); + assertEquals("SAM implicit REST API authorizer MyCognitoAuth configures a Cognito user pool " + + "authorizer, which Floci does not support for SAM implicit REST APIs yet.", error.getMessage()); + assertFalse(error.getMessage().contains("FunctionPayloadType")); + } + @Test void expandSamTemplate_implicitApiEventCanOptOutOfGlobalAuthorizer() throws Exception { JsonNode template = objectMapper.readTree("""