Light, fluffy, and always free - The AWS Local Emulator alternative
fix(cloudformation): forward ProviderARNs on AWS::ApiGateway::Authorizer (#4704)
danielxoib5f053c5872c
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisioner.javaindex 019f0014f4..17777d2204 100644--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisioner.java+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisioner.java@@ -513,6 +513,9 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner {if (ttl != null) {req.put("authorizerResultTtlInSeconds", ttl);}+ if (props != null && props.has("ProviderARNs")) {+ req.put("providerARNs", ctx.resolveStringList(props, "ProviderARNs"));+ }Authorizer authorizer = apiGatewayService.createAuthorizer(ctx.region(), apiId, req);r.setPhysicalId(authorizer.getId());r.getAttributes().put("AuthorizerId", authorizer.getId());diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisionerTest.javaindex d56ff53aff..61a710b863 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisionerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisionerTest.java@@ -14,6 +14,7 @@ import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateimport io.github.hectorvent.floci.services.cloudformation.model.StackResource;import io.github.hectorvent.floci.services.s3.S3Service;import org.junit.jupiter.api.Test;+import org.mockito.ArgumentCaptor;import java.util.ArrayList;import java.util.HashMap;@@ -344,6 +345,30 @@ class ApiGatewayRestApiCfnProvisionerTest {assertEquals("auth-1", r.getAttributes().get("AuthorizerId"));}+ /**+ * A COGNITO_USER_POOLS authorizer with no provider ARNs rejects every token, so dropping the+ * property turns a correct template into a 401 on every request.+ */+ @Test+ void authorizerForwardsProviderArns() throws Exception {+ Authorizer authorizer = new Authorizer();+ authorizer.setId("auth-1");+ when(api.createAuthorizer(eq("us-east-1"), eq("api-1"), anyMap())).thenReturn(authorizer);++ StackResource r = resource("AWS::ApiGateway::Authorizer", "Auth");+ provisioner.provision(r, props("""+ {"RestApiId": "api-1", "Name": "cognito", "Type": "COGNITO_USER_POOLS",+ "IdentitySource": "method.request.header.Authorization",+ "ProviderARNs": ["arn:aws:cognito-idp:us-east-1:000000000000:userpool/us-east-1_abc"]}+ """), ctx());++ @SuppressWarnings("unchecked")+ ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.forClass(Map.class);+ verify(api).createAuthorizer(eq("us-east-1"), eq("api-1"), request.capture());+ assertEquals(List.of("arn:aws:cognito-idp:us-east-1:000000000000:userpool/us-east-1_abc"),+ request.getValue().get("providerARNs"));+ }+@Testvoid methodUsesTheCompositePhysicalIdAndProvisionsItsIntegration() throws Exception {StackResource r = resource("AWS::ApiGateway::Method", "Get");