mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigatewayv2): answer an HTTP API's Lambda proxy body it cannot read with 500 (#6012)
* fix(apigatewayv2): answer an HTTP API's Lambda proxy body it cannot read with 500 Review of #5985: the catch at the end of buildProxyResponse still answered an HTTP API with 502 and the function's output, for example when isBase64Encoded is set on a body that is not base64. Measured on HTTP APIs (eu-west-1), with payload formats 1.0 and 2.0: API Gateway answers 500 with {"message":"Internal Server Error"} a body that is an object or a list, an isBase64Encoded it cannot read as a boolean, and a body said to be base64 that does not decode. It reads isBase64Encoded's text as Go's strconv.ParseBool does: "True", "TRUE", "t" and 1 are true, "F" and 0 false, and "tRuE", "yes", 2 and 1.5 are not read. Floci read true, the text "true" and any integer but 0 as true, so it relayed "True" and "t" bodies undecoded, "yes" ones as plain text, decoded a body under 2, and answered an object body 200 with an empty body. A number or a boolean body is still its text. The catch now answers an HTTP API with the same 500 for a result Floci cannot parse at all; a REST API keeps its 502. * refactor(apigatewayv2): decode an HTTP API's base64 body once Review of #6012: the readability check decoded a base64 body that the response then decoded again, a second decode and array for every encoded reply. The catch at the end of buildProxyResponse already answers an HTTP API with 500 and the generic message, so the check now looks only at the body's shape, and a body said to be base64 that does not decode fails where it is decoded and reaches that catch.
This commit is contained in:
1 parent
65e35adf54
commit
28799ed352
5 files changed
+91
-12
No files matched your search
+37
-3
@@ -256,9 +256,11 @@ class ApiGatewayExecuteControllerTest {
|
||||
/**
|
||||
* Measured on HTTP APIs (eu-west-1, 2026-10-19), for payload formats 1.0 and 2.0: a 1.0 result
|
||||
* that is not an object with a statusCode, and a statusCode that is not a whole number from 100
|
||||
* to 599, are answered with 500 and the generic message; a statusCode given as text that spells
|
||||
* one is taken, and headers that are not an object are left out. A function that raises is
|
||||
* covered below.
|
||||
* to 599, are answered with 500 and the generic message, and so are a body that is an object or a
|
||||
* list, an isBase64Encoded that strconv.ParseBool would not read, and a body said to be base64
|
||||
* that does not decode; a statusCode given as text that spells one is taken, headers that are
|
||||
* not an object are left out, and a number or a boolean body is its text. A function that raises
|
||||
* is covered below.
|
||||
*/
|
||||
@ParameterizedTest(name = "{0} payload {1}")
|
||||
@MethodSource("httpApiProxyResponses")
|
||||
@@ -288,6 +290,38 @@ class ApiGatewayExecuteControllerTest {
|
||||
Arguments.of("{\"statusCode\":\"201\",\"body\":\"x\"}", "2.0", 201, "x"),
|
||||
Arguments.of("{\"statusCode\":201,\"headers\":\"x\",\"body\":\"x\"}", "1.0", 201, "x"),
|
||||
Arguments.of("{\"statusCode\":201,\"headers\":\"x\",\"body\":\"x\"}", "2.0", 201, "x"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"not base64!\",\"isBase64Encoded\":true}", "1.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"not base64!\",\"isBase64Encoded\":true}", "2.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":{\"a\":1}}", "1.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":{\"a\":1}}", "2.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":[\"a\"]}", "1.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":[\"a\"]}", "2.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"yes\"}", "1.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"yes\"}", "2.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"tRuE\"}", "1.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"tRuE\"}", "2.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":2}", "1.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":2}", "2.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":1.5}", "1.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":1.5}", "2.0", 500, error),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":true}", "1.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":true}", "2.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"True\"}", "1.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"True\"}", "2.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"TRUE\"}", "1.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"TRUE\"}", "2.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"t\"}", "1.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"t\"}", "2.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":1}", "1.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":1}", "2.0", 200, "hello"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"F\"}", "1.0", 200, "aGVsbG8="),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":\"F\"}", "2.0", 200, "aGVsbG8="),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":0}", "1.0", 200, "aGVsbG8="),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":\"aGVsbG8=\",\"isBase64Encoded\":0}", "2.0", 200, "aGVsbG8="),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":5}", "1.0", 200, "5"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":5}", "2.0", 200, "5"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":true}", "1.0", 200, "true"),
|
||||
Arguments.of("{\"statusCode\":200,\"body\":true}", "2.0", 200, "true"),
|
||||
Arguments.of("null", "2.0", 200, "null"),
|
||||
Arguments.of("5", "2.0", 200, "5"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user