diff --git a/pom.xml b/pom.xml index 9856582a2..a62512c33 100644 --- a/pom.xml +++ b/pom.xml @@ -141,6 +141,7 @@ + core diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSLambdaUtils.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSLambdaUtils.java index ff0de1f39..025577cc6 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSLambdaUtils.java +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSLambdaUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2021 the original author or authors. + * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,6 +67,7 @@ final class AWSLambdaUtils { || typeName.equals("com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent") || typeName.equals("com.amazonaws.services.lambda.runtime.events.SNSEvent") || typeName.equals("com.amazonaws.services.lambda.runtime.events.SQSEvent") + || typeName.equals("com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent") || typeName.equals("com.amazonaws.services.lambda.runtime.events.KinesisEvent"); } diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/FunctionInvokerTests.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/FunctionInvokerTests.java index 08b2f9961..908e925f3 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/FunctionInvokerTests.java +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/FunctionInvokerTests.java @@ -27,6 +27,7 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; @@ -447,6 +448,12 @@ public class FunctionInvokerTests { " \"isBase64Encoded\": false\n" + "}"; + String gwAuthorizerEvent = "{\n" + + " \"type\":\"TOKEN\",\n" + + " \"authorizationToken\":\"allow\",\n" + + " \"methodArn\":\"arn:aws:execute-api:us-west-2:123456789012:ymy8tbxw7b/*/GET/\"\n" + + "}"; + @BeforeEach public void before() throws Exception { System.clearProperty("MAIN_CLASS"); @@ -455,6 +462,19 @@ public class FunctionInvokerTests { this.getEnvironment().clear(); } + @Test + public void testAPIGatewayCustomAuthorizerEvent() throws Exception { + System.setProperty("MAIN_CLASS", AuthorizerConfiguration.class.getName()); + System.setProperty("spring.cloud.function.definition", "acceptAuthorizerEvent"); + FunctionInvoker invoker = new FunctionInvoker(); + + InputStream targetStream = new ByteArrayInputStream(this.gwAuthorizerEvent.getBytes()); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + invoker.handleRequest(targetStream, output, null); + String result = new String(output.toByteArray(), StandardCharsets.UTF_8); + assertThat(result).contains("APIGatewayCustomAuthorizerEvent(version=null, type=TOKEN"); + } + @Test public void testCollection() throws Exception { System.setProperty("MAIN_CLASS", SampleConfiguration.class.getName()); @@ -1043,6 +1063,15 @@ public class FunctionInvokerTests { return (Map) field.get(env); } + @EnableAutoConfiguration + @Configuration + public static class AuthorizerConfiguration { + @Bean + public Function acceptAuthorizerEvent() { + return v -> v.toString(); + } + } + @EnableAutoConfiguration @Configuration public static class SampleConfiguration {