mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(apigateway): send x-amzn-ErrorType on REST gateway responses (#6687)
* fix(apigateway): send x-amzn-ErrorType on the API key 403 * fix(apigateway): send x-amzn-ErrorType on every REST gateway response Authorizer, validation, media-type, configuration and Lambda proxy failures now carry the error type AWS pairs with their gateway response type, customised or not, measured on a REST API in eu-west-1. * fix(apigateway): keep a gateway response's own x-amzn-ErrorType where AWS does A gateway response that maps gatewayresponse.header.x-amzn-ErrorType sends only that value for the validation, media type, configuration and integration types, and sends it ahead of the default for the authorizer and API key types, as measured on AWS.
This commit is contained in:
1 parent
64069f9ccd
commit
3f294c3529
9 files changed
+162
-35
No files matched your search
@@ -171,10 +171,10 @@ stores its own copy of the key value, so without that sweep a deleted key would
|
||||
exists and has `enabled` set to `true`, so disabling a key through `UpdateApiKey` takes effect
|
||||
immediately.
|
||||
|
||||
> [!NOTE]
|
||||
> Floci does not implement the `apiKeyRequired` gate on methods, so a request carrying an unknown,
|
||||
> disabled, or deleted key is still executed — it simply arrives with a null `identity.apiKey` rather
|
||||
> than being rejected with `403`.
|
||||
A method with `apiKeyRequired` rejects a request whose `x-api-key` is missing, unknown, disabled,
|
||||
deleted, or not bound to the stage by a usage plan, with `403` `{"message":"Forbidden"}` and
|
||||
`x-amzn-ErrorType: ForbiddenException`, as AWS does. The header stays when the API customises its
|
||||
`INVALID_API_KEY` gateway response.
|
||||
|
||||
### REST Lambda Authorizers
|
||||
|
||||
@@ -341,23 +341,27 @@ then for `DEFAULT_4XX` / `DEFAULT_5XX`, and applies the configured `statusCode`,
|
||||
This is what lets a browser read a `401`/`403`/`400` as such instead of as a CORS failure once
|
||||
`DEFAULT_4XX` maps `Access-Control-Allow-Origin`, exactly as the console's "Enable CORS" does.
|
||||
|
||||
| Gateway-generated answer | `responseType` |
|
||||
|---|---|
|
||||
| No resource matches the path, or none declares the method (`403 Missing Authentication Token`) | `MISSING_AUTHENTICATION_TOKEN` |
|
||||
| `AWS_IAM` method without a signature | `MISSING_AUTHENTICATION_TOKEN` |
|
||||
| `AWS_IAM` signature malformed or mismatching | `INVALID_SIGNATURE` |
|
||||
| `AWS_IAM` signature outside the 5-minute window, or a presigned URL past its expiry | `EXPIRED_TOKEN` |
|
||||
| `AWS_IAM` access key the emulator never issued | `ACCESS_DENIED` |
|
||||
| Lambda authorizer returns `Deny` | `ACCESS_DENIED` |
|
||||
| Lambda authorizer fails or throws | `AUTHORIZER_FAILURE` |
|
||||
| Cognito authorizer gets no token, an invalid one, one from another pool, or one claiming none of the method's authorization scopes (`401 Unauthorized`) | `UNAUTHORIZED` |
|
||||
| Method with `apiKeyRequired` and no usable `x-api-key` (`403 Forbidden`) | `INVALID_API_KEY` |
|
||||
| Request validator rejects a parameter / the body | `BAD_REQUEST_PARAMETERS` / `BAD_REQUEST_BODY` |
|
||||
| `passthroughBehavior` rejects the request `Content-Type` (`415`) | `UNSUPPORTED_MEDIA_TYPE` |
|
||||
| Missing or unresolvable integration or URI, MOCK template that does not render | `API_CONFIGURATION_ERROR` |
|
||||
| Lambda proxy function error, malformed proxy payload, or missing function | `INTEGRATION_FAILURE` |
|
||||
| Gateway-generated answer | `responseType` | `x-amzn-ErrorType` |
|
||||
|---|---|---|
|
||||
| No resource matches the path, or none declares the method (`403 Missing Authentication Token`) | `MISSING_AUTHENTICATION_TOKEN` | `MissingAuthenticationTokenException` |
|
||||
| `AWS_IAM` method without a signature | `MISSING_AUTHENTICATION_TOKEN` | `MissingAuthenticationTokenException` |
|
||||
| `AWS_IAM` signature malformed or mismatching | `INVALID_SIGNATURE` | `IncompleteSignatureException` / `InvalidSignatureException` |
|
||||
| `AWS_IAM` signature outside the 5-minute window, or a presigned URL past its expiry | `EXPIRED_TOKEN` | `InvalidSignatureException` |
|
||||
| `AWS_IAM` access key the emulator never issued | `ACCESS_DENIED` | `UnrecognizedClientException` |
|
||||
| Lambda authorizer returns `Deny` | `ACCESS_DENIED` | `AccessDeniedException` |
|
||||
| Lambda authorizer fails or throws | `AUTHORIZER_FAILURE` | `AuthorizerConfigurationException` |
|
||||
| Cognito authorizer gets no token, an invalid one, one from another pool, or one claiming none of the method's authorization scopes (`401 Unauthorized`) | `UNAUTHORIZED` | `UnauthorizedException` |
|
||||
| Method with `apiKeyRequired` and no usable `x-api-key` (`403 Forbidden`) | `INVALID_API_KEY` | `ForbiddenException` |
|
||||
| Request validator rejects a parameter / the body | `BAD_REQUEST_PARAMETERS` / `BAD_REQUEST_BODY` | `BadRequestException` |
|
||||
| `passthroughBehavior` rejects the request `Content-Type` (`415`) | `UNSUPPORTED_MEDIA_TYPE` | `BadRequestException` |
|
||||
| Missing or unresolvable integration or URI, MOCK template that does not render | `API_CONFIGURATION_ERROR` | `InternalServerErrorException` |
|
||||
| Lambda proxy function error, malformed proxy payload, or missing function | `INTEGRATION_FAILURE` | `InternalServerErrorException` |
|
||||
|
||||
A customised `statusCode` overrides the status Floci would otherwise send. Throttling, quota, request size and WAF answers are not produced on the execute plane, so
|
||||
A customised `statusCode` overrides the status Floci would otherwise send; the `x-amzn-ErrorType` stays, as on AWS.
|
||||
A gateway response that maps its own `gatewayresponse.header.x-amzn-ErrorType` (that exact key) replaces it for
|
||||
`BAD_REQUEST_PARAMETERS`, `BAD_REQUEST_BODY`, `UNSUPPORTED_MEDIA_TYPE`, `API_CONFIGURATION_ERROR` and
|
||||
`INTEGRATION_FAILURE`, and is sent ahead of it for the other types, as AWS does. Throttling, quota, request
|
||||
size and WAF answers are not produced on the execute plane, so
|
||||
`THROTTLED`, `QUOTA_EXCEEDED`, `REQUEST_TOO_LARGE` and `WAF_FILTERED` can be configured but never
|
||||
fire, and an `HTTP`/`HTTP_PROXY` backend's own status is relayed rather than treated as a gateway
|
||||
response.
|
||||
|
||||
+40
-9
@@ -72,6 +72,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -579,7 +580,7 @@ public class ApiGatewayExecuteController {
|
||||
// A function error or a payload that is not a proxy response is answered by the
|
||||
// gateway itself, so a configured INTEGRATION_FAILURE / DEFAULT_5XX shapes it.
|
||||
return gatewayResponseOr(response, scope, GatewayResponseType.INTEGRATION_FAILURE,
|
||||
"Internal server error");
|
||||
"Internal server error", null);
|
||||
}
|
||||
return response;
|
||||
} catch (AwsException e) {
|
||||
@@ -3969,7 +3970,35 @@ public class ApiGatewayExecuteController {
|
||||
|
||||
private Response gatewayResponse(GatewayResponseScope scope, GatewayResponseType type, int status,
|
||||
String message, String validationError) {
|
||||
return gatewayResponseBuilder(scope, type, status, message, validationError).build();
|
||||
Response fallback = Response.status(status).entity(jsonMessage(message)).type(MediaType.APPLICATION_JSON)
|
||||
.build();
|
||||
return gatewayResponseOr(fallback, scope, type, message, validationError);
|
||||
}
|
||||
|
||||
/**
|
||||
* The types whose gateway response sends only its own {@code x-amzn-ErrorType} when it maps one
|
||||
* (that exact key); the others send the mapped value ahead of theirs (measured on a REST API,
|
||||
* eu-west-1, 2026-10-26).
|
||||
*/
|
||||
private static final Set<GatewayResponseType> MAPPED_ERROR_TYPE_REPLACES = EnumSet.of(
|
||||
GatewayResponseType.BAD_REQUEST_PARAMETERS, GatewayResponseType.BAD_REQUEST_BODY,
|
||||
GatewayResponseType.UNSUPPORTED_MEDIA_TYPE, GatewayResponseType.API_CONFIGURATION_ERROR,
|
||||
GatewayResponseType.INTEGRATION_FAILURE);
|
||||
|
||||
/**
|
||||
* The {@code x-amzn-ErrorType} AWS sends with a gateway response of {@code type}, customised or
|
||||
* not (measured on a REST API, eu-west-1, 2026-10-26). Null for the types these sites never emit.
|
||||
*/
|
||||
private static String gatewayErrorType(GatewayResponseType type) {
|
||||
return switch (type) {
|
||||
case INVALID_API_KEY -> "ForbiddenException";
|
||||
case UNAUTHORIZED -> "UnauthorizedException";
|
||||
case ACCESS_DENIED -> "AccessDeniedException";
|
||||
case AUTHORIZER_FAILURE, AUTHORIZER_CONFIGURATION_ERROR -> "AuthorizerConfigurationException";
|
||||
case BAD_REQUEST_PARAMETERS, BAD_REQUEST_BODY, UNSUPPORTED_MEDIA_TYPE -> "BadRequestException";
|
||||
case API_CONFIGURATION_ERROR, INTEGRATION_FAILURE -> "InternalServerErrorException";
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private Response.ResponseBuilder gatewayResponseBuilder(GatewayResponseScope scope, GatewayResponseType type,
|
||||
@@ -3983,18 +4012,20 @@ public class ApiGatewayExecuteController {
|
||||
}
|
||||
|
||||
/**
|
||||
* For the sites whose uncustomised answer is not the {@code {"message"}} body (a bare status,
|
||||
* or the Lambda payload passed through): the answer stays as it was unless the API customised
|
||||
* a gateway response for it.
|
||||
* The {@code fallback} answer stays as it was (a {@code {"message"}} body, a bare status, or the
|
||||
* Lambda payload passed through) unless the API customised a gateway response for it.
|
||||
*/
|
||||
private Response gatewayResponseOr(Response fallback, GatewayResponseScope scope, GatewayResponseType type,
|
||||
String message) {
|
||||
String message, String validationError) {
|
||||
GatewayResponse configured = apiGatewayService.resolveGatewayResponse(scope.region(), scope.apiId(),
|
||||
type, fallback.getStatus());
|
||||
if (configured == null) {
|
||||
return fallback;
|
||||
Response.ResponseBuilder builder = configured == null ? Response.fromResponse(fallback)
|
||||
: renderGatewayResponse(scope, configured, type, fallback.getStatus(), message, validationError);
|
||||
if (configured != null && MAPPED_ERROR_TYPE_REPLACES.contains(type)
|
||||
&& configured.getResponseParameters().containsKey(GATEWAY_RESPONSE_HEADER_PREFIX + "x-amzn-ErrorType")) {
|
||||
return builder.build();
|
||||
}
|
||||
return renderGatewayResponse(scope, configured, type, fallback.getStatus(), message, null).build();
|
||||
return builder.header("x-amzn-ErrorType", gatewayErrorType(type)).build();
|
||||
}
|
||||
|
||||
private Response.ResponseBuilder renderGatewayResponse(GatewayResponseScope scope, GatewayResponse configured,
|
||||
|
||||
+39
-1
@@ -15,6 +15,7 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Integration tests for {@code AWS::ApiGateway::Method.ApiKeyRequired} enforcement on the
|
||||
@@ -36,6 +37,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest {
|
||||
private static String protectedResourceId;
|
||||
private static String openResourceId;
|
||||
private static String keyValue;
|
||||
private static String planId;
|
||||
|
||||
@Test @Order(1)
|
||||
void createEchoLambda() throws Exception {
|
||||
@@ -143,7 +145,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest {
|
||||
.then().statusCode(200)
|
||||
.extract().path("value");
|
||||
|
||||
String planId = given()
|
||||
planId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"apikeyrequired-plan","apiStages":[{"apiId":"%s","stage":"prod"}]}
|
||||
@@ -166,6 +168,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest {
|
||||
given()
|
||||
.when().get("/execute-api/" + apiId + "/prod/secret")
|
||||
.then().statusCode(403)
|
||||
.header("x-amzn-ErrorType", equalTo("ForbiddenException"))
|
||||
.body("message", org.hamcrest.Matchers.is("Forbidden"));
|
||||
}
|
||||
|
||||
@@ -175,6 +178,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest {
|
||||
.header("x-api-key", "not-a-real-key")
|
||||
.when().get("/execute-api/" + apiId + "/prod/secret")
|
||||
.then().statusCode(403)
|
||||
.header("x-amzn-ErrorType", equalTo("ForbiddenException"))
|
||||
.body("message", org.hamcrest.Matchers.is("Forbidden"));
|
||||
}
|
||||
|
||||
@@ -254,6 +258,40 @@ class ApiGatewayApiKeyRequiredIntegrationTest {
|
||||
.body("apiKeyRequired", org.hamcrest.Matchers.is(true));
|
||||
}
|
||||
|
||||
@Test @Order(11)
|
||||
void protectedMethodRejectsDisabledAndUnboundApiKeys() {
|
||||
String disabledKeyId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"apikeyrequired-disabled\",\"enabled\":false}")
|
||||
.when().post("/apikeys")
|
||||
.then().statusCode(201)
|
||||
.extract().path("id");
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"keyId\":\"%s\",\"keyType\":\"API_KEY\"}".formatted(disabledKeyId))
|
||||
.when().post("/usageplans/" + planId + "/keys")
|
||||
.then().statusCode(201);
|
||||
String unboundKeyId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"apikeyrequired-unbound\",\"enabled\":true}")
|
||||
.when().post("/apikeys")
|
||||
.then().statusCode(201)
|
||||
.extract().path("id");
|
||||
|
||||
for (String keyId : new String[] {disabledKeyId, unboundKeyId}) {
|
||||
String value = given()
|
||||
.when().get("/apikeys/" + keyId + "?includeValue=true")
|
||||
.then().statusCode(200)
|
||||
.extract().path("value");
|
||||
given()
|
||||
.header("x-api-key", value)
|
||||
.when().get("/execute-api/" + apiId + "/prod/secret")
|
||||
.then().statusCode(403)
|
||||
.header("x-amzn-ErrorType", equalTo("ForbiddenException"))
|
||||
.body("message", equalTo("Forbidden"));
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] zipEntries(Map<String, String> entries) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
|
||||
+1
@@ -74,6 +74,7 @@ class ApiGatewayCognitoAuthorizerIntegrationTest {
|
||||
.when().get(base + "secured").then().statusCode(401);
|
||||
given().header("X-Id-Token", "Bearer " + idToken)
|
||||
.when().get(base + "secured").then().statusCode(401)
|
||||
.header("x-amzn-ErrorType", equalTo("UnauthorizedException"))
|
||||
.body("message", equalTo("Unauthorized"));
|
||||
given().header("X-Id-Token", "Bearer " + accessToken)
|
||||
.when().get(base + "missing-scope").then().statusCode(401)
|
||||
|
||||
+26
@@ -13,6 +13,8 @@ import java.time.temporal.ChronoUnit;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
@@ -377,6 +379,7 @@ class ApiGatewayGatewayResponseIntegrationTest {
|
||||
.when().get("/execute-api/" + apiId + "/api/validated")
|
||||
.then().statusCode(400)
|
||||
.header("Access-Control-Allow-Origin", equalTo("*"))
|
||||
.header("x-amzn-ErrorType", equalTo("BadRequestException"))
|
||||
.body("type", equalTo("BAD_REQUEST_PARAMETERS"))
|
||||
.body("message", equalTo("Missing required request parameter in QUERY_STRING: 'q'"));
|
||||
|
||||
@@ -398,6 +401,7 @@ class ApiGatewayGatewayResponseIntegrationTest {
|
||||
.when().get("/execute-api/" + apiId + "/api/keyed")
|
||||
.then().statusCode(401)
|
||||
.header("Access-Control-Allow-Origin", nullValue())
|
||||
.header("x-amzn-ErrorType", equalTo("ForbiddenException"))
|
||||
.body("type", equalTo("INVALID_API_KEY"))
|
||||
.body("message", equalTo("Forbidden"));
|
||||
}
|
||||
@@ -468,9 +472,31 @@ class ApiGatewayGatewayResponseIntegrationTest {
|
||||
.when().get("/execute-api/" + apiId + "/api/broken")
|
||||
.then().statusCode(500)
|
||||
.header("Access-Control-Allow-Origin", equalTo("*"))
|
||||
.header("x-amzn-ErrorType", equalTo("InternalServerErrorException"))
|
||||
.body("message", equalTo("Internal server error"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMappedErrorTypeReplacesTheDefaultOnlyWhereAwsDoes() {
|
||||
deployMockApi();
|
||||
putGatewayResponse("DEFAULT_4XX", "{\"responseParameters\":{"
|
||||
+ "\"gatewayresponse.header.x-amzn-ErrorType\":\"'Mapped4xx'\"}}");
|
||||
putGatewayResponse("DEFAULT_5XX", "{\"responseParameters\":{"
|
||||
+ "\"gatewayresponse.header.x-amzn-ErrorType\":\"'Mapped5xx'\"}}");
|
||||
|
||||
// Measured (eu-west-1, 2026-10-26): validation and configuration failures send only the
|
||||
// mapped value, an API key rejection sends it ahead of its own.
|
||||
assertThat(given().when().get("/execute-api/" + apiId + "/api/validated")
|
||||
.then().statusCode(400).extract().headers().getValues("x-amzn-ErrorType"),
|
||||
contains("Mapped4xx"));
|
||||
assertThat(given().when().get("/execute-api/" + apiId + "/api/broken")
|
||||
.then().statusCode(500).extract().headers().getValues("x-amzn-ErrorType"),
|
||||
contains("Mapped5xx"));
|
||||
assertThat(given().when().get("/execute-api/" + apiId + "/api/keyed")
|
||||
.then().statusCode(403).extract().headers().getValues("x-amzn-ErrorType"),
|
||||
contains("Mapped4xx", "ForbiddenException"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── fixtures ────────────────────────────
|
||||
|
||||
private void putGatewayResponse(String responseType, String body) {
|
||||
|
||||
+2
-1
@@ -276,7 +276,8 @@ class ApiGatewayHttpNonProxyIntegrationTest {
|
||||
|
||||
given().contentType(ContentType.JSON).body("{}")
|
||||
.when().post("/execute-api/" + apiId + "/test/widget")
|
||||
.then().statusCode(415);
|
||||
.then().statusCode(415)
|
||||
.header("x-amzn-ErrorType", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
@@ -99,6 +99,7 @@ class ApiGatewayMockAuthorizerIntegrationTest {
|
||||
given().header("Authorization", "Bearer denied")
|
||||
.get("/execute-api/" + apiId + "/test/claims")
|
||||
.then().statusCode(403)
|
||||
.header("x-amzn-ErrorType", equalTo("AccessDeniedException"))
|
||||
.body(equalTo("{\"message\":\"User is not authorized to access this resource\"}"));
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1272,7 +1272,8 @@ class ApiGatewayOpenApiImportTest {
|
||||
AtomicInteger integrationCalls) {
|
||||
int calls = integrationCalls.get();
|
||||
given().spec(request).contentType(ContentType.JSON).body(body).post(endpoint)
|
||||
.then().statusCode(400).body("message", equalTo("Invalid request body"));
|
||||
.then().statusCode(400).body("message", equalTo("Invalid request body"))
|
||||
.header("x-amzn-ErrorType", equalTo("BadRequestException"));
|
||||
assertEquals(calls, integrationCalls.get(), "Rejected requests must not reach the integration");
|
||||
}
|
||||
|
||||
|
||||
+27
-3
@@ -97,7 +97,8 @@ class RestLambdaAuthorizerIntegrationTest {
|
||||
default -> output.put("policyDocument", Map.of("Statement", List.of(Map.of("Effect", "Allow"))));
|
||||
}
|
||||
respond(output);
|
||||
given().header("Authorization", "token").get(execute("allowed")).then().statusCode(500);
|
||||
given().header("Authorization", "token").get(execute("allowed")).then().statusCode(500)
|
||||
.header("x-amzn-ErrorType", equalTo("AuthorizerConfigurationException"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -182,7 +183,8 @@ class RestLambdaAuthorizerIntegrationTest {
|
||||
void missingTokenIsUnauthorizedWithoutInvokingLambda() throws Exception {
|
||||
configure("TOKEN", 0, "method.request.header.Authorization");
|
||||
allowAll();
|
||||
given().get(execute("allowed")).then().statusCode(401);
|
||||
given().get(execute("allowed")).then().statusCode(401)
|
||||
.header("x-amzn-ErrorType", equalTo("UnauthorizedException"));
|
||||
verifyInvocation(0);
|
||||
}
|
||||
|
||||
@@ -312,11 +314,33 @@ class RestLambdaAuthorizerIntegrationTest {
|
||||
.thenReturn(new InvokeResult(200, "Unhandled", payload, null, "lambda-error"));
|
||||
for (int i = 0; i < 2; i++) {
|
||||
given().header("Authorization", "token").get(execute("allowed"))
|
||||
.then().statusCode("Unauthorized".equals(message) ? 401 : 500);
|
||||
.then().statusCode("Unauthorized".equals(message) ? 401 : 500)
|
||||
.header("x-amzn-ErrorType", equalTo("Unauthorized".equals(message)
|
||||
? "UnauthorizedException" : "AuthorizerConfigurationException"));
|
||||
}
|
||||
verifyInvocation(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lambdaProxyFunctionErrorIsAnInternalServerError() throws Exception {
|
||||
configure("TOKEN", 0, "method.request.header.Authorization");
|
||||
allowAll();
|
||||
String resourceId = given().get("/restapis/" + apiId + "/resources").then().extract()
|
||||
.path("item.find { it.path == '/allowed' }.id");
|
||||
given().contentType(ContentType.JSON).body(Map.of("type", "AWS_PROXY", "httpMethod", "POST",
|
||||
"uri", AUTHORIZER_URI.replace(FUNCTION, "failing-proxy")))
|
||||
.put(methodPath(resourceId) + "/integration").then().statusCode(201);
|
||||
when(lambdaService.invokeTarget(eq("us-east-1"), eq("arn:aws:lambda:us-east-1:000000000000:function:failing-proxy"),
|
||||
any(byte[].class), eq(InvocationType.RequestResponse)))
|
||||
.thenReturn(new InvokeResult(200, "Unhandled",
|
||||
new ObjectMapper().writeValueAsBytes(Map.of("errorMessage", "boom")), null, "proxy-error"));
|
||||
deploy("test");
|
||||
|
||||
given().header("Authorization", "token").get(execute("allowed"))
|
||||
.then().statusCode(502)
|
||||
.header("x-amzn-ErrorType", equalTo("InternalServerErrorException"));
|
||||
}
|
||||
|
||||
private void configure(String type, int ttl, String identitySource) {
|
||||
Map<String, Object> request = new LinkedHashMap<>(Map.of("name", "contract", "type", type,
|
||||
"authorizerUri", AUTHORIZER_URI, "authorizerResultTtlInSeconds", ttl));
|
||||
|
||||
Reference in new issue
Block a user