fix(apigatewayv2): honor payload format 1.0 (#5338)

* fix(apigatewayv2): honor payload format 1.0

* fix(apigatewayv2): preserve v1 stage variables

* fix(apigatewayv2): preserve v1 authorization header

* docs(apigateway): document v1 IAM identity context
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-11 09:10:07 -04:00
1 parent 80e8b7465d
commit 04621d8444
5 files changed
+175 -10

No files matched your search

@@ -620,6 +620,48 @@ class ApiGatewayExecuteControllerTest {
new byte[0], "req-1", null, null, null, null));
}
@Test
void payloadFormatOneUsesV1EventShape() throws Exception {
ApiGatewayExecuteController controller = controller(new ObjectMapper());
UriInfo uriInfo = uriInfoFor("http://localhost/echo-v1?q=1&q=2");
MultivaluedMap<String, String> query = new MultivaluedHashMap<>();
query.addAll("q", "1", "2");
when(uriInfo.getQueryParameters()).thenReturn(query);
HttpHeaders headers = emptyHeaders();
MultivaluedMap<String, String> requestHeaders = new MultivaluedHashMap<>();
requestHeaders.addAll("X-Trace", "first", "second");
when(headers.getRequestHeaders()).thenReturn(requestHeaders);
JsonNode event = new ObjectMapper().readTree(controller.buildV1ProxyEvent(
"GET", "/echo-v1", "GET /echo-v1", "api1", "us-east-1", "test",
Map.of("environment", "review"), headers, uriInfo, new byte[0], "req-1",
Map.of("sub", "user-1"), List.of("read"), null, null));
assertEquals("1.0", event.path("version").asText());
assertEquals("/echo-v1", event.path("resource").asText());
assertEquals("/echo-v1", event.path("path").asText());
assertEquals("GET", event.path("httpMethod").asText());
assertTrue(event.path("rawPath").isMissingNode());
assertTrue(event.path("pathParameters").isNull());
assertEquals("review", event.path("stageVariables").path("environment").asText());
assertTrue(event.path("requestContext").path("resourceId").isNull());
assertTrue(event.path("requestContext").path("requestTime").isTextual());
assertTrue(event.path("requestContext").path("requestTimeEpoch").asLong() > 0);
assertTrue(event.path("requestContext").path("routeKey").isMissingNode());
assertTrue(event.path("requestContext").path("time").isMissingNode());
assertTrue(event.path("requestContext").path("timeEpoch").isMissingNode());
assertEquals("user-1", event.path("requestContext").path("authorizer").path("claims")
.path("sub").asText());
assertEquals("read", event.path("requestContext").path("authorizer").path("scopes")
.path(0).asText());
assertTrue(event.path("requestContext").path("authorizer").path("jwt").isMissingNode());
assertEquals("second", event.path("headers").path("x-trace").asText());
assertTrue(event.path("headers").path("X-Trace").isMissingNode());
JsonNode queryValues = event.path("multiValueQueryStringParameters").path("q");
assertEquals("1", queryValues.path(0).asText());
assertEquals("2", queryValues.path(1).asText());
}
@Test
void v2RequestAuthorizerEventTimeIsEnglishUtcUnderNonUtcHost() throws Exception {
ApiGatewayExecuteController controller = controller(new ObjectMapper());
@@ -13,6 +13,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.net.URI;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -132,6 +133,19 @@ class ProxyEventIamIdentityTest {
"a route with no authorizer must not grow an authorizer node");
}
@Test
void httpApiPayloadOneKeepsTheSignatureHeader() throws Exception {
requestHeaders.add("Authorization", SIGV4);
JsonNode event = MAPPER.readTree(controller.buildV1ProxyEvent(
"GET", "/iam", "GET /iam", "api1", "us-east-1", "test", Map.of(),
headers, uriInfo, null, "req-v1", null, null, null, CALLER));
assertEquals(SIGV4, event.path("headers").path("authorization").asText());
assertEquals(SIGV4,
event.path("multiValueHeaders").path("authorization").path(0).asText());
}
@Test
void awsIamMethodDropsTheSignatureButKeepsTheOtherSigningHeaders() throws Exception {
requestHeaders.add("Authorization", SIGV4);
@@ -14,9 +14,8 @@ import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/**
* End to end check of the payload format 2.0 event a Lambda proxy integration receives for
* repeated query keys, repeated headers and cookies. Format 2.0 has no multi-value maps: AWS
* combines duplicates with commas and moves cookies into a {@code cookies} array.
* End to end checks of the events Lambda proxy integrations receive. Format 2.0 combines repeated
* values and moves cookies into a {@code cookies} array, while format 1.0 keeps multi-value maps.
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@@ -59,7 +58,7 @@ class HttpApiLambdaProxyEventMultiValueIntegrationTest {
given()
.contentType(ContentType.JSON)
.body("""
{"stageName":"test"}
{"stageName":"test","stageVariables":{"environment":"review"}}
""")
.when().post("/v2/apis/" + apiId + "/stages")
.then().statusCode(201);
@@ -81,6 +80,24 @@ class HttpApiLambdaProxyEventMultiValueIntegrationTest {
""".formatted(integrationId))
.when().post("/v2/apis/" + apiId + "/routes")
.then().statusCode(201);
String v1IntegrationId = given()
.contentType(ContentType.JSON)
.body("""
{"integrationType":"AWS_PROXY","integrationUri":"arn:aws:lambda:us-east-1:000000000000:function:%s/invocations","integrationMethod":"POST","payloadFormatVersion":"1.0"}
""".formatted(FUNCTION_NAME))
.when().post("/v2/apis/" + apiId + "/integrations")
.then()
.statusCode(201)
.extract().path("integrationId");
given()
.contentType(ContentType.JSON)
.body("""
{"routeKey":"GET /echo-v1","target":"integrations/%s"}
""".formatted(v1IntegrationId))
.when().post("/v2/apis/" + apiId + "/routes")
.then().statusCode(201);
}
@Test
@@ -130,6 +147,24 @@ class HttpApiLambdaProxyEventMultiValueIntegrationTest {
.body("cookies", nullValue());
}
@Test
@Order(14)
void payloadFormatOneUsesV1Event() {
given()
.queryParam("q", "1", "2")
.when().get("/execute-api/" + apiId + "/test/echo-v1")
.then()
.statusCode(200)
.body("version", equalTo("1.0"))
.body("resource", equalTo("/echo-v1"))
.body("path", equalTo("/echo-v1"))
.body("httpMethod", equalTo("GET"))
.body("rawPath", nullValue())
.body("stageVariables.environment", equalTo("review"))
.body("multiValueHeaders", notNullValue())
.body("multiValueQueryStringParameters.q", contains("1", "2"));
}
@Test
@Order(999)
void cleanup() throws Exception {