Light, fluffy, and always free - The AWS Local Emulator alternative
fix(cloudformation): identify unsupported SAM Cognito authorizers (#3535)
XuJian809ce40f1e5b
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.javaindex 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<String, JsonNode> 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.javaindex 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"));+ }+@Testvoid expandSamTemplate_implicitApiEventCanOptOutOfGlobalAuthorizer() throws Exception {JsonNode template = objectMapper.readTree("""