GH-833 Add initial support for AWS APIGatewayCustomAuthorizerEvent
Resolves #833
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -141,6 +141,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>core</id>
|
<id>core</id>
|
||||||
<modules>
|
<modules>
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.APIGatewayProxyRequestEvent")
|
||||||
|| typeName.equals("com.amazonaws.services.lambda.runtime.events.SNSEvent")
|
|| 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.SQSEvent")
|
||||||
|
|| typeName.equals("com.amazonaws.services.lambda.runtime.events.APIGatewayCustomAuthorizerEvent")
|
||||||
|| typeName.equals("com.amazonaws.services.lambda.runtime.events.KinesisEvent");
|
|| typeName.equals("com.amazonaws.services.lambda.runtime.events.KinesisEvent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import java.util.function.Consumer;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
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.APIGatewayProxyRequestEvent;
|
||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent;
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent;
|
||||||
@@ -447,6 +448,12 @@ public class FunctionInvokerTests {
|
|||||||
" \"isBase64Encoded\": false\n" +
|
" \"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
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
public void before() throws Exception {
|
||||||
System.clearProperty("MAIN_CLASS");
|
System.clearProperty("MAIN_CLASS");
|
||||||
@@ -455,6 +462,19 @@ public class FunctionInvokerTests {
|
|||||||
this.getEnvironment().clear();
|
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
|
@Test
|
||||||
public void testCollection() throws Exception {
|
public void testCollection() throws Exception {
|
||||||
System.setProperty("MAIN_CLASS", SampleConfiguration.class.getName());
|
System.setProperty("MAIN_CLASS", SampleConfiguration.class.getName());
|
||||||
@@ -1043,6 +1063,15 @@ public class FunctionInvokerTests {
|
|||||||
return (Map<String, String>) field.get(env);
|
return (Map<String, String>) field.get(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@Configuration
|
||||||
|
public static class AuthorizerConfiguration {
|
||||||
|
@Bean
|
||||||
|
public Function<APIGatewayCustomAuthorizerEvent, String> acceptAuthorizerEvent() {
|
||||||
|
return v -> v.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@Configuration
|
@Configuration
|
||||||
public static class SampleConfiguration {
|
public static class SampleConfiguration {
|
||||||
|
|||||||
Reference in New Issue
Block a user