fix(apigateway): key stage method settings by the patch path as sent (#7977)

* fix(apigateway): key stage method settings by the patch path as sent

UpdateStage decoded the JSON Pointer escapes in a method-settings patch
path before using it as the methodSettings key, so
/~1webhook~1status/POST/logging/loglevel was stored as
webhook/status/POST. API Gateway keeps the path as written and GetStage
reports ~1webhook~1status/POST, which is the key the Terraform provider
looks up for aws_api_gateway_method_settings; on Floci the lookup found
nothing and the read failed with "empty result".

The method-settings key is now the patch path between the leading slash
and the setting name, unchanged, so the escaped and plain spellings each
round-trip under the key the client sent.

* fix(apigateway): find escaped method-settings keys at invoke time

Method settings are now stored under the patch path as sent, so a
caching patch to /~1widget/GET/caching/enabled lands under ~1widget/GET.
The invoke-time lookup only tried the decoded resource path (widget/GET)
and fell through to */*, so caching enabled that way never applied.

methodSettingFor now tries the JSON Pointer escaped resource path first,
then the plain path, then the */* wildcard.

* style(apigateway): brace single-line ifs in method-settings lookup
This commit is contained in:
Tyler Webb authored and GitHub committed 2026-11-11 08:48:24 -04:00
1 parent 8eaf5bf59c
commit 54bc8fc563
3 files changed
+38 -27

No files matched your search

@@ -8,6 +8,8 @@ import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
/**
@@ -114,7 +116,7 @@ class ApiGatewayIntegrationReadBackTest {
}
@Test
void methodSettingsAcceptTheEscapedResourcePathAwsSends() {
void methodSettingsKeepTheEscapedResourcePathAsTheKey() {
String deploymentId = given().contentType(ContentType.JSON).body("{}")
.when().post("/restapis/" + apiId + "/deployments")
.then().statusCode(201).extract().path("id");
@@ -123,21 +125,25 @@ class ApiGatewayIntegrationReadBackTest {
.when().post("/restapis/" + apiId + "/stages")
.then().statusCode(201);
// AWS escapes the resource path's slashes as ~1. That spelling previously produced the
// unusable key "~1widget/POST" instead of "widget/POST".
given().contentType(ContentType.JSON)
.body("{\"patchOperations\":[{\"op\":\"replace\","
+ "\"path\":\"/~1widget/POST/throttling/burstLimit\",\"value\":\"77\"}]}")
.body("{\"patchOperations\":["
+ "{\"op\":\"replace\",\"path\":\"/~1widget/POST/throttling/burstLimit\",\"value\":\"77\"},"
+ "{\"op\":\"replace\",\"path\":\"/~1webhook~1status/POST/logging/loglevel\",\"value\":\"INFO\"},"
+ "{\"op\":\"replace\",\"path\":\"/~1webhook~1status/POST/logging/dataTrace\",\"value\":\"true\"}]}")
.when().patch("/restapis/" + apiId + "/stages/test")
.then().statusCode(200);
given().when().get("/restapis/" + apiId + "/stages/test")
.then().statusCode(200)
.body("methodSettings.'widget/POST'.throttlingBurstLimit", equalTo(77));
.body("methodSettings.'~1widget/POST'.throttlingBurstLimit", equalTo(77))
.body("methodSettings.'~1webhook~1status/POST'.loggingLevel", equalTo("INFO"))
.body("methodSettings.'~1webhook~1status/POST'.dataTraceEnabled", equalTo(true))
.body("methodSettings", not(hasKey("widget/POST")))
.body("methodSettings", not(hasKey("webhook/status/POST")));
}
@Test
void methodSettingsUnescapeTheJsonPointerTildeEscape() {
void methodSettingsKeepTheTildeEscapeInTheKey() {
String deploymentId = given().contentType(ContentType.JSON).body("{}")
.when().post("/restapis/" + apiId + "/deployments")
.then().statusCode(201).extract().path("id");
@@ -146,9 +152,6 @@ class ApiGatewayIntegrationReadBackTest {
.when().post("/restapis/" + apiId + "/stages")
.then().statusCode(201);
// RFC 6901 escapes a literal "~" as ~0 and "/" as ~1. "/~1pets~0promo/GET/..." therefore
// addresses the resource "/pets~promo"; only ~1 used to be decoded, leaving a stray "~0".
// "~01" is an escaped literal "~1", not a slash, so decoding order matters too.
given().contentType(ContentType.JSON)
.body("{\"patchOperations\":["
+ "{\"op\":\"replace\",\"path\":\"/~1pets~0promo/GET/throttling/burstLimit\",\"value\":\"12\"},"
@@ -158,8 +161,8 @@ class ApiGatewayIntegrationReadBackTest {
given().when().get("/restapis/" + apiId + "/stages/tilde")
.then().statusCode(200)
.body("methodSettings.'pets~promo/GET'.throttlingBurstLimit", equalTo(12))
.body("methodSettings.'v~1/POST'.throttlingRateLimit", equalTo(3.5f));
.body("methodSettings.'~1pets~0promo/GET'.throttlingBurstLimit", equalTo(12))
.body("methodSettings.'~1v~01/POST'.throttlingRateLimit", equalTo(3.5f));
}
@Test