Light, fluffy, and always free - The AWS Local Emulator alternative
fix(route53resolver): CreateResolverEndpoint reads IpAddresses, as AWS names it (#4180)
Allen Sanborndaecc6da17b6
diff --git a/docs/services/route53resolver.md b/docs/services/route53resolver.mdindex d1b9fc236c..ff378691e8 100644--- a/docs/services/route53resolver.md+++ b/docs/services/route53resolver.md@@ -63,9 +63,14 @@ resource and raise `ResourceExistsException`, which both operations model.all, so a mismatched retry still returns the original list rather than an invented errorcode. See `issues/route53resolver-firewall-domain-list-retry-conflict.md`.-For `CreateResolverEndpoint` the comparison covers the actual `IpAddressRequests` entries,+For `CreateResolverEndpoint` the comparison covers the actual `IpAddresses` entries,not just how many there are, so a retry that keeps the count but changes a subnet or-address is a conflict. Order is not significant. The modelled `ResolverEndpoint` shape has+address is a conflict. The member is `IpAddresses`, as AWS names it; its list shape is+`IpAddressesRequest` and each element is an `IpAddressRequest`, which is the name earlier+builds of this service mistook for the wire name.+That spelling is still accepted so existing callers keep working, but it is not the+documented one, and a retry that switches between the two is not a conflict because the+comparison is on contents. Order is not significant. The modelled `ResolverEndpoint` shape has`IpAddressCount` and no IP list, so the addresses are recorded in a side store rather thanon the resource and never reach the response. If that record is ever missing for a storedendpoint, the retry is reported as a conflict rather than compared on count alone — withdiff --git a/src/main/java/io/github/hectorvent/floci/services/route53resolver/Route53ResolverService.java b/src/main/java/io/github/hectorvent/floci/services/route53resolver/Route53ResolverService.javaindex d2bf4086ec..7cfd83b5e0 100644--- a/src/main/java/io/github/hectorvent/floci/services/route53resolver/Route53ResolverService.java+++ b/src/main/java/io/github/hectorvent/floci/services/route53resolver/Route53ResolverService.java@@ -176,9 +176,9 @@ public class Route53ResolverService {requireText(request, "Name", INVALID_PARAMETER);String direction = requireText(request, "Direction", INVALID_PARAMETER);String idPrefix = endpointIdPrefix(direction);- JsonNode ipAddresses = request.path("IpAddressRequests");+ JsonNode ipAddresses = ipAddressesOf(request);if (!ipAddresses.isArray() || ipAddresses.isEmpty()) {- throw new AwsException(INVALID_PARAMETER, "IpAddressRequests is required", 400);+ throw new AwsException(INVALID_PARAMETER, "IpAddresses is required", 400);}java.util.Optional<ObjectNode> replay = replayOf(endpointStore, request, region);if (replay.isPresent()) {@@ -438,6 +438,9 @@ public class Route53ResolverService {* of this branch.</p>*/private void requireSameIpRequests(ObjectNode existing, JsonNode request, JsonNode ipAddresses) {+ // The store's member name is deliberately left as IpAddressRequests: it is internal+ // state, and renaming it would make every record written by an earlier build read as+ // absent, which this method reports as a replay conflict.JsonNode recorded = endpointIpRequestStore.get(text(existing, "Id")).map(node -> node.get("IpAddressRequests")).orElse(null);@@ -445,10 +448,24 @@ public class Route53ResolverService {// written before the ordering was corrected still compares as equal.if (recorded == null|| !normalizedIpRequests(recorded).equals(normalizedIpRequests(ipAddresses))) {- throw replayConflict(request, existing, "IpAddressRequests");+ throw replayConflict(request, existing, "IpAddresses");}}+ /**+ * The IP addresses a {@code CreateResolverEndpoint} request carries.+ *+ * <p>AWS names this member {@code IpAddresses}; its list shape is+ * {@code IpAddressesRequest} and each element is an {@code IpAddressRequest}, which+ * is the name the wrong wire spelling came from. {@code IpAddressRequests} is still+ * accepted so anything written against the emulator's earlier behaviour keeps+ * working, but it is undocumented and the error message names only the AWS member.</p>+ */+ private static JsonNode ipAddressesOf(JsonNode request) {+ JsonNode aws = request.path("IpAddresses");+ return aws.isMissingNode() || aws.isNull() ? request.path("IpAddressRequests") : aws;+ }+/*** The IP requests in a stable order, so a reordered retry is not read as a change.*diff --git a/src/test/java/io/github/hectorvent/floci/services/route53resolver/Route53ResolverIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/route53resolver/Route53ResolverIntegrationTest.javaindex 5c811e8eb8..42507d408a 100644--- a/src/test/java/io/github/hectorvent/floci/services/route53resolver/Route53ResolverIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/route53resolver/Route53ResolverIntegrationTest.java@@ -86,4 +86,90 @@ class Route53ResolverIntegrationTest {.then().statusCode(400);}++ // ── CreateResolverEndpoint: the request member is IpAddresses ──────────────+ //+ // AWS names it IpAddresses; its list shape is named IpAddressRequest, which is+ // where the emulator's earlier wire name came from. Every SDK, the CLI and the+ // Terraform provider send IpAddresses, and the CLI will not send the old name at+ // all, so reading only the old one made the operation dispatch and stay+ // uncallable. These cover both spellings so the alias cannot be dropped silently.++ private static String createEndpointBody(String ipMember, String creatorRequestId) {+ return "{\"Name\":\"ep\",\"Direction\":\"INBOUND\","+ + "\"CreatorRequestId\":\"" + creatorRequestId + "\","+ + "\"SecurityGroupIds\":[\"sg-abc123\"],"+ + "\"" + ipMember + "\":[{\"SubnetId\":\"subnet-abc\",\"Ip\":\"10.0.0.10\"}]}";+ }++ @Test+ void createResolverEndpoint_acceptsTheAwsIpAddressesMember() {+ given()+ .contentType(CONTENT_TYPE)+ .header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")+ .header("Authorization", AUTH_HEADER)+ .body(createEndpointBody("IpAddresses", "aws-member-1"))+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body("ResolverEndpoint.Id", startsWith("rslvr-in-"))+ .body("ResolverEndpoint.Direction", equalTo("INBOUND"))+ .body("ResolverEndpoint.IpAddressCount", equalTo(1));+ }++ @Test+ void createResolverEndpoint_stillAcceptsTheLegacyMember() {+ given()+ .contentType(CONTENT_TYPE)+ .header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")+ .header("Authorization", AUTH_HEADER)+ .body(createEndpointBody("IpAddressRequests", "legacy-member-1"))+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body("ResolverEndpoint.IpAddressCount", equalTo(1));+ }++ @Test+ void createResolverEndpoint_replayMatchesAcrossTheTwoSpellings() {+ // A caller that created an endpoint with the old name and retries with the AWS+ // one is sending the same request. The idempotency check compares contents, so+ // it must not read the rename as a conflict.+ given()+ .contentType(CONTENT_TYPE)+ .header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")+ .header("Authorization", AUTH_HEADER)+ .body(createEndpointBody("IpAddressRequests", "replay-across-names"))+ .when().post("/").then().statusCode(200);++ given()+ .contentType(CONTENT_TYPE)+ .header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")+ .header("Authorization", AUTH_HEADER)+ .body(createEndpointBody("IpAddresses", "replay-across-names"))+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body("ResolverEndpoint.IpAddressCount", equalTo(1));+ }++ @Test+ void createResolverEndpoint_withoutAddressesNamesTheAwsMember() {+ // The message is the only hint a caller gets about which member to send, so it+ // must name the one AWS documents rather than the emulator's internal spelling.+ given()+ .contentType(CONTENT_TYPE)+ .header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")+ .header("Authorization", AUTH_HEADER)+ .body("{\"Name\":\"ep\",\"Direction\":\"INBOUND\","+ + "\"CreatorRequestId\":\"no-addresses\",\"SecurityGroupIds\":[\"sg-abc123\"]}")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body("message", equalTo("IpAddresses is required"));+ }}