mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(route53resolver): require at least two IP addresses for CreateResolverEndpoint (#5539)
* fix(route53resolver): require at least two IP addresses for CreateResolverEndpoint A resolver endpoint's IpAddresses member is modeled min 2 / max 20, but the emulator only rejected an empty list. A request carrying a single address (or more than twenty) returned HTTP 200 and created the endpoint, which real AWS refuses. Validate the count on CreateResolverEndpoint and raise the service's existing InvalidParameterException, creating no endpoint on rejection. Fixes #4774 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * refactor(route53resolver): fold the two endpoint body builders into one The request member is modeled min 2 / max 20, so phrase the code and test comments from the shape rather than the older min 1 note. Replace createEndpointBody and endpointBody with a single builder taking the member name, the creator request id and the address count. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> --------- Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
41517f3c2f
commit
4da5143456
4 files changed
+130
-30
No files matched your search
+11
@@ -185,6 +185,17 @@ public class Route53ResolverService {
|
||||
if (!ipAddresses.isArray() || ipAddresses.isEmpty()) {
|
||||
throw new AwsException(INVALID_PARAMETER, "IpAddresses is required", 400);
|
||||
}
|
||||
// IpAddresses is modeled list min 2 / max 20: a resolver endpoint needs at
|
||||
// least two addresses for redundancy.
|
||||
int ipAddressCount = ipAddresses.size();
|
||||
if (ipAddressCount < 2) {
|
||||
throw new AwsException(INVALID_PARAMETER,
|
||||
"IpAddresses must contain at least two IP addresses.", 400);
|
||||
}
|
||||
if (ipAddressCount > 20) {
|
||||
throw new AwsException(INVALID_PARAMETER,
|
||||
"IpAddresses must contain at most twenty IP addresses.", 400);
|
||||
}
|
||||
Optional<ObjectNode> replay = replayOf(endpointStore, request, region);
|
||||
if (replay.isPresent()) {
|
||||
ObjectNode existing = replay.get();
|
||||
|
||||
+14
-14
@@ -139,7 +139,7 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
void createResolverEndpoint_replayedCreatorRequestId_returnsOriginalEndpoint() {
|
||||
String body = "{\"Name\":\"ab-idem-endpoint\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"tok-idem-endpoint\"}";
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"tok-idem-endpoint\"}";
|
||||
|
||||
String first = call("CreateResolverEndpoint", body)
|
||||
.then().statusCode(200).extract().path("ResolverEndpoint.Id");
|
||||
@@ -158,7 +158,7 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
void createResolverEndpoint_withoutCreatorRequestId_createsDistinctEndpoints() {
|
||||
String body = "{\"Name\":\"ab-noidem-endpoint\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}]}";
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}]}";
|
||||
|
||||
String first = call("CreateResolverEndpoint", body)
|
||||
.then().statusCode(200).extract().path("ResolverEndpoint.Id");
|
||||
@@ -172,7 +172,7 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
void createResolverEndpoint_replayedCreatorRequestIdWithInvalidBody_stillValidates() {
|
||||
String valid = "{\"Name\":\"ab-idem-validate\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"tok-idem-validate\"}";
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"tok-idem-validate\"}";
|
||||
call("CreateResolverEndpoint", valid).then().statusCode(200);
|
||||
|
||||
// Replaying the token does not excuse a malformed request body.
|
||||
@@ -185,7 +185,7 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
// ... including an unrecognised Direction.
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-idem-validate\",\"Direction\":\"SIDEWAYS\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"tok-idem-validate\"}")
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"tok-idem-validate\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
@@ -231,14 +231,14 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
String token = "tok-conflict-endpoint";
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-conflict-endpoint\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"" + token + "\"}")
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"" + token + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
// Same token, same region, different (but individually valid) Name: AWS models
|
||||
// ResourceExistsException for this rather than silently returning the original.
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-conflict-endpoint-renamed\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"" + token + "\"}")
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"" + token + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceExistsException"));
|
||||
@@ -318,12 +318,12 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
String token = "tok-replay-endpoint-nofingerprint";
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-nofingerprint\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-aaa\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"" + token + "\"}")
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"" + token + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
// ResolverEndpoint models IpAddressCount but no IP list, so whatever we retain to
|
||||
// detect a changed IP set must not reach the wire.
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(1))
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(2))
|
||||
.body("ResolverEndpoint.any { it.key == 'IpAddressRequests' }", equalTo(false))
|
||||
.body("ResolverEndpoint.any { it.key == 'IpAddresses' }", equalTo(false));
|
||||
}
|
||||
@@ -389,7 +389,7 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
void createResolverEndpoint_sameCreatorRequestIdInAnotherRegion_createsRegionalEndpoint() {
|
||||
String body = "{\"Name\":\"ab-xregion-endpoint\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"tok-xregion-endpoint\"}";
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"tok-xregion-endpoint\"}";
|
||||
|
||||
String east = callAs(AUTH_HEADER, "CreateResolverEndpoint", body)
|
||||
.then().statusCode(200)
|
||||
@@ -439,7 +439,7 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
private static String createEndpoint(String name) {
|
||||
return call("CreateResolverEndpoint", "{\"Name\":\"" + name + "\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"tok-" + name + "\"}")
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"tok-" + name + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ResolverEndpoint.Id");
|
||||
}
|
||||
@@ -448,20 +448,20 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
void createResolverEndpoint_returnsOperationalEndpoint() {
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-endpoint-create\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"tok-endpoint-create\"}")
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"tok-endpoint-create\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Name", equalTo("ab-endpoint-create"))
|
||||
.body("ResolverEndpoint.Direction", equalTo("INBOUND"))
|
||||
.body("ResolverEndpoint.Status", equalTo("OPERATIONAL"))
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(1));
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_inboundGetsInboundIdPrefix() {
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-endpoint-inbound\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}],\"CreatorRequestId\":\"tok-endpoint-inbound\"}")
|
||||
+ "\"Ip\":\"10.0.0.5\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"tok-endpoint-inbound\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Direction", equalTo("INBOUND"))
|
||||
@@ -472,7 +472,7 @@ class Route53ResolverCustomResourcesConsumerTest {
|
||||
void createResolverEndpoint_outboundGetsOutboundIdPrefix() {
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-endpoint-outbound\",\"Direction\":\"OUTBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.6\"}],\"CreatorRequestId\":\"tok-endpoint-outbound\"}")
|
||||
+ "\"Ip\":\"10.0.0.6\"},{\"SubnetId\":\"subnet-def\",\"Ip\":\"10.0.0.7\"}],\"CreatorRequestId\":\"tok-endpoint-outbound\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Direction", equalTo("OUTBOUND"))
|
||||
|
||||
+99
-15
@@ -93,14 +93,7 @@ class Route53ResolverIntegrationTest {
|
||||
// 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\"}]}";
|
||||
}
|
||||
// uncallable. These cover both spellings so the alias cannot be dropped silently.
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_acceptsTheAwsIpAddressesMember() {
|
||||
@@ -108,14 +101,14 @@ class Route53ResolverIntegrationTest {
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(createEndpointBody("IpAddresses", "aws-member-1"))
|
||||
.body(endpointBody("IpAddresses", "aws-member-1", 2))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Id", startsWith("rslvr-in-"))
|
||||
.body("ResolverEndpoint.Direction", equalTo("INBOUND"))
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(1));
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,12 +117,12 @@ class Route53ResolverIntegrationTest {
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(createEndpointBody("IpAddressRequests", "legacy-member-1"))
|
||||
.body(endpointBody("IpAddressRequests", "legacy-member-1", 2))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(1));
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,19 +134,19 @@ class Route53ResolverIntegrationTest {
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(createEndpointBody("IpAddressRequests", "replay-across-names"))
|
||||
.body(endpointBody("IpAddressRequests", "replay-across-names", 2))
|
||||
.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"))
|
||||
.body(endpointBody("IpAddresses", "replay-across-names", 2))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(1));
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,4 +165,95 @@ class Route53ResolverIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("IpAddresses is required"));
|
||||
}
|
||||
|
||||
// ── CreateResolverEndpoint: IpAddresses is min 2 / max 20 ──────────────────
|
||||
//
|
||||
// The request shape models IpAddresses as min 2 / max 20, so a resolver endpoint
|
||||
// needs at least two IP addresses and rejects more than twenty. The emulator used
|
||||
// to accept a single address and create the endpoint, which a real SDK would never
|
||||
// be allowed to do.
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_singleAddress_returnsInvalidParameters() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(endpointBody("IpAddresses", "single-address", 1))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo("IpAddresses must contain at least two IP addresses."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_twentyOneAddresses_returnsInvalidParameters() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(endpointBody("IpAddresses", "too-many-addresses", 21))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo("IpAddresses must contain at most twenty IP addresses."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_twoAddresses_succeeds() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(endpointBody("IpAddresses", "two-addresses", 2))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.IpAddressCount", equalTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_singleAddress_createsNoEndpoint() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(endpointBody("IpAddresses", "rejected-endpoint", 1))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.ListResolverEndpoints")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoints.findAll { it.Name == 'ep-rejected-endpoint' }.size()",
|
||||
equalTo(0));
|
||||
}
|
||||
|
||||
private static String endpointBody(String ipMember, String creatorRequestId, int ipCount) {
|
||||
StringBuilder addresses = new StringBuilder();
|
||||
for (int i = 0; i < ipCount; i++) {
|
||||
if (i > 0) {
|
||||
addresses.append(",");
|
||||
}
|
||||
addresses.append("{\"SubnetId\":\"subnet-").append(i)
|
||||
.append("\",\"Ip\":\"10.0.0.").append(i + 1).append("\"}");
|
||||
}
|
||||
return "{\"Name\":\"ep-" + creatorRequestId + "\",\"Direction\":\"INBOUND\","
|
||||
+ "\"CreatorRequestId\":\"" + creatorRequestId + "\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],"
|
||||
+ "\"" + ipMember + "\":[" + addresses + "]}";
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.route53resolver;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
@@ -45,9 +46,13 @@ class Route53ResolverReplayFallbackTest {
|
||||
request.put("Direction", "INBOUND");
|
||||
request.put("CreatorRequestId", token);
|
||||
request.putArray("SecurityGroupIds").add("sg-abc123");
|
||||
ObjectNode ipRequest = request.putArray("IpAddressRequests").addObject();
|
||||
ArrayNode ipRequests = request.putArray("IpAddressRequests");
|
||||
ObjectNode ipRequest = ipRequests.addObject();
|
||||
ipRequest.put("SubnetId", "subnet-aaa");
|
||||
ipRequest.put("Ip", ip);
|
||||
ipRequest = ipRequests.addObject();
|
||||
ipRequest.put("SubnetId", "subnet-bbb");
|
||||
ipRequest.put("Ip", "10.0.0.6");
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user