mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(route53resolver): add Route 53 Resolver with DNS Firewall domain lists (#2582)
* feat(route53resolver): AWS-managed DNS Firewall domain lists
New JSON 1.1 service exposing ListFirewallDomainLists with the four
AWS-managed domain lists, deterministic ids stable across restarts.
LZA's NetworkPrepStack Custom::ResolverManagedDomainList Lambda resolves
managed list ids by name and previously failed with UnknownOperation.
* feat(route53resolver): full-parity build-out (16 ops)
Adds firewall domain list CRUD, resolver endpoint CRUD, resolver rule
CRUD, and rule-association management, backed by four new
StorageBackend stores. The pre-existing deterministic AWS-managed
domain list logic (AWS_MANAGED_DOMAIN_LIST_NAMES, managedList(),
FirewallDomainList) is untouched -- LZA's bootstrap Lambda depends on
those ids being stable across calls.
Also fixes the JSON-1.1 dispatch case in AwsJson11Controller to pass
the account id through to the handler, matching every other service's
dispatch signature (route53resolver was the one holdout still calling
handle() with the old 3-arg signature).
* fix(config): declare route53resolver enabled toggle in both application.yml files
Upstream's ServiceConfigYamlCoverageTest requires every service config with an
enabled() toggle to declare it explicitly in both files; this branch predates
that test and fails it without the declaration.
* docs(route53resolver): register the generated action table
* fix(route53resolver): declare storageKey and storageMode on the service descriptor
The service persists four stores through StorageFactory, but its catalog
descriptor left storageKey and storageMode null, so it was invisible to
PersistentPathValidator's boot check and to per-service storage config
resolution. Mirror the organizations descriptor.
* fix(route53resolver): make creates idempotent on CreatorRequestId
CreateFirewallDomainList, CreateResolverEndpoint and CreateResolverRule
allocated a new resource on every call, so an LZA/CloudFormation retry of
the same CreatorRequestId left duplicates behind. Real AWS returns the
resource the token originally created. Dedupe per store, after the
operation's own validation so a replayed token cannot excuse a malformed
body; a blank or absent token still allocates.
* fix(route53resolver): give outbound resolver endpoints rslvr-out ids
Every CreateResolverEndpoint allocated an inbound-style rslvr-in- id
regardless of Direction, so an outbound endpoint carried an id AWS would
never issue. Key the prefix off Direction (INBOUND/INBOUND_DELEGATION ->
rslvr-in, OUTBOUND -> rslvr-out) and reject values outside the
ResolverEndpointDirection enum instead of silently defaulting to inbound.
* test(route53resolver): assert managed domain lists by name, not by count
ListFirewallDomainLists returns the four managed lists plus whatever
custom lists other tests in the run have created, so size()==4 and the
[0] index extraction were both order-dependent. Assert the four managed
names are present and pick the id by name. Also drop the call-site counts
from the 404-convention comment, which would go stale on any refactor.
* docs(route53resolver): correct the scoping limitation
The limitation claimed resources are visible regardless of the caller's
account. They are not: all four stores are created through StorageFactory,
which wraps every backend in AccountAwareStorageBackend, so keys are
prefixed with the calling credential's account id and both scan() and
keys() filter on that prefix. Region and VPC are what go unenforced, and
the AWS-managed lists are region-derived and globally visible by design.
* fix(route53resolver): validate Direction before the CreatorRequestId replay check
endpointIdPrefix ran only on the allocation path, so replaying a known
CreatorRequestId with an unrecognised Direction returned 200 and the
original endpoint instead of InvalidParametersException. Bind the prefix
right after the Direction is read, so every request is validated whether
or not it turns out to be a replay.
* fix(route53resolver): enforce the RuleType and ResolverEndpointType enums
CreateResolverRule stored any RuleType string it was given and UpdateResolverEndpoint
copied any ResolverEndpointType through, so Get/ListResolverRules and
GetResolverEndpoint reported values outside botocore's RuleTypeOption
(FORWARD/SYSTEM/RECURSIVE/DELEGATE) and ResolverEndpointType (IPV6/IPV4/DUALSTACK).
Both now reject with the same InvalidParametersException the Direction check uses.
* fix(route53resolver): reject an empty TargetIps list
The model pins TargetIps to list min 1; a present-but-empty array was
stored verbatim. Absent stays allowed for SYSTEM rules. Found by the
botocore-grounded review pipeline; the hand audit missed it.
* fix(route53resolver): make the CreatorRequestId replay check atomic
Two overlapping create retries with the same token could both pass the
replay scan before either put, persisting two resources with different
ids. The three create methods are now synchronized, making the
scan-then-put pair atomic on this ApplicationScoped singleton.
* fix(route53resolver): scope the CreatorRequestId replay to the request's region
replayOf matched purely on CreatorRequestId content across the whole
account-partitioned store, which carries no region in its keys. The same
account replaying a token in a second region got the first region's
resource and ARN back instead of the regional resource it asked for.
Route 53 Resolver is regional, so a token identifies one resource per
region: match the candidate's region too, taken from the ARN this service
builds rather than a stored field, so nothing new reaches the wire.
Also folds the two stacked javadoc blocks above replayOf into one; the
second was shadowing the first, which left the idempotency contract out
of the generated docs.
* docs: correct service count to 79 after the #2579 merge
The upstream/main merge (ca772bc72) added two new services
(servicequotas, ram) on top of this branch's own route53resolver
addition. The merge-base count was 76; three disjoint new services
(1 ours + 2 upstream) makes 79, not 78 as the merge commit left it.
* fix(config): restore the controltower enabled toggle in both application.yml files
The route53resolver key was inserted between controltower: and the
enabled: true that belonged to it, so controltower: became a bare key
binding nothing and route53resolver adopted its child. Control Tower kept
running only because ControlTowerServiceConfig.enabled() carries
@WithDefault("true"), which masked the break; the explicit toggle was
gone. Caught by ServiceConfigYamlCoverageTest, which names controltower
rather than route53resolver and made the CI failure read as unrelated.
* fix(route53resolver): raise the error codes the model actually names
InvalidParametersException (plural) is a Service Catalog shape and does
not exist anywhere in route53resolver's model. Checked every throw site
against the per-operation error lists in botocore route53resolver
2018-04-01 rather than renaming globally, because the service carries two
vocabularies: the resolver endpoint, rule and association operations model
the singular InvalidParameterException, while the DNS Firewall operations
model ValidationException and do not list InvalidParameterException at all.
CreateFirewallDomainList therefore raises ValidationException; the other
eight sites raise InvalidParameterException. requireText and requireEnum
are shared across both families, so each caller now passes the code its
own operation models instead of the helper picking one. ResourceNotFound
usage was already correct and is untouched.
* fix(route53resolver): reject a CreatorRequestId replayed with different parameters
A replayed token was deduplicated on the token alone, so a retry carrying
different but individually valid parameters got a success response
describing the original resource rather than the one it asked for.
CreateResolverEndpoint and CreateResolverRule now compare the retry
against the stored resource and raise ResourceExistsException, which both
operations model. CreateFirewallDomainList is deliberately left lenient:
its modeled error list carries no conflict error at all, so reporting one
would mean inventing a shape real SDK clients cannot deserialize. That
divergence is pinned by a test and ledgered rather than guessed at.
* fix(route53resolver): compare IP request values, not just their count, on a replayed create
The conflict check compared IpAddressRequests by size, so a retry reusing
a CreatorRequestId with the same number of entries but a different subnet
or address was treated as an equivalent replay and returned the original
endpoint, dropping the configuration the caller actually asked for.
The modeled ResolverEndpoint shape carries IpAddressCount and no IP list,
and the handlers return the stored node verbatim, so the addresses are
recorded in a side store keyed by endpoint id rather than on the resource
itself; nothing new reaches the wire. Comparison is order-insensitive so a
reordered retry is still a replay, and endpoints created before this
record existed fall back to the count comparison instead of reporting a
conflict on every retry.
* fix(route53resolver): treat a missing IP-request record as a conflict, not a pass
The fallback for an endpoint with no recorded IpAddressRequests compared
IpAddressCount instead, which accepts a retry that keeps the count but
changes a subnet or address — exactly the case the record exists to catch.
That made it a silently wrong check rather than a lenient one.
With nothing to compare against, sameness cannot be established, so the
retry is now reported as ResourceExistsException. A spurious conflict is
loud and recoverable; a wrong success is neither. Nothing released can
reach this state: the endpoint store is new in the same change as the
record, so the only ways in are a write interrupted between the two stores
or state from an intermediate build of this branch.
Adds a package-private constructor so a hermetic test can create the
missing-record state the public API cannot, following the pattern in
Ec2IpamService. The cost of failing closed — an identical retry also
conflicting — is pinned as its own test rather than left implicit.
* fix(route53resolver): order IP requests by a member-order-independent key
The replay comparison sorted IpAddressRequests by JsonNode.toString, which
serialises members in insertion order. A retry carrying the same addresses
with the members written in a different order could sort the entries into a
different sequence, so an equivalent request was rejected as a conflict.
Sort by a canonical key that ignores member order instead. Both sides are
re-normalised at comparison time rather than trusting the stored order, so
a record written before this fix still compares as equal.
This commit is contained in:
1 parent
bd436eeea1
commit
d60bd6ead2
16 files changed
+1882
-4
No files matched your search
+92
@@ -0,0 +1,92 @@
|
||||
package io.github.hectorvent.floci.services.route53resolver;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Integration tests for {@code Route53Resolver.GetFirewallDomainList}.
|
||||
*
|
||||
* <p>Success path exercises the happy path by listing the pre-seeded AWS-managed
|
||||
* domain lists, picking the first stable Id, and asserting the shape returned by
|
||||
* {@code GetFirewallDomainList}. The not-found path verifies that an invalid Id
|
||||
* produces the AWS-style {@code ResourceNotFoundException} (HTTP 400 with
|
||||
* {@code __type} in the body).</p>
|
||||
*/
|
||||
@QuarkusTest
|
||||
class GetFirewallDomainListConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/route53resolver/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFirewallDomainList_success() {
|
||||
// 1. List to obtain a real, seeded FirewallDomainList Id. Other tests create
|
||||
// custom lists into the same store, so assert the managed lists are present
|
||||
// by name rather than pinning the total or an index.
|
||||
String firewallDomainListId = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.ListFirewallDomainLists")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainLists", notNullValue())
|
||||
.body("FirewallDomainLists.Name", hasItems(
|
||||
"AWSManagedDomainsAggregateThreatList",
|
||||
"AWSManagedDomainsAmazonGuardDutyThreatList",
|
||||
"AWSManagedDomainsBotnetCommandandControl",
|
||||
"AWSManagedDomainsMalwareDomainList"))
|
||||
.extract().path(
|
||||
"FirewallDomainLists.find { it.Name == 'AWSManagedDomainsAggregateThreatList' }.Id");
|
||||
|
||||
// 2. Get the individual list and assert the response shape.
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.GetFirewallDomainList")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{\"FirewallDomainListId\":\"" + firewallDomainListId + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainList.Id", equalTo(firewallDomainListId))
|
||||
.body("FirewallDomainList.Arn", startsWith("arn:aws:route53resolver:"))
|
||||
.body("FirewallDomainList.Name", notNullValue())
|
||||
.body("FirewallDomainList.Name", not(equalTo("")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFirewallDomainList_notFound_returns400() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.GetFirewallDomainList")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{\"FirewallDomainListId\":\"rslvr-fdl-nonexistent\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
// 404, matching Floci's dominant convention for ResourceNotFoundException.
|
||||
// The Botocore packet does not pin an httpStatusCode for this shape and no
|
||||
// AWS doc quote was obtained, so the real AWS status is UNVERIFIED —
|
||||
// recorded as a known ambiguity rather than asserted as parity.
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
+753
@@ -0,0 +1,753 @@
|
||||
package io.github.hectorvent.floci.services.route53resolver;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
/**
|
||||
* Wire-level tests for the custom (non-managed) Route 53 Resolver operations
|
||||
* added this session: firewall domain list CRUD, resolver endpoint CRUD,
|
||||
* resolver rule CRUD, and resolver rule / VPC associations.
|
||||
*
|
||||
* <p>These are all new persistence-backed additions layered onto the
|
||||
* pre-existing, deterministic-id AWS-managed firewall domain list logic in
|
||||
* {@link Route53ResolverService}, which is left untouched (see
|
||||
* {@link Route53ResolverIntegrationTest} for its coverage).</p>
|
||||
*/
|
||||
@QuarkusTest
|
||||
class Route53ResolverCustomResourcesConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/route53resolver/aws4_request";
|
||||
/** Same access key (so the same account) in a second region, for region-scoping tests. */
|
||||
private static final String AUTH_HEADER_WEST =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-west-2/route53resolver/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return callAs(AUTH_HEADER, action, body);
|
||||
}
|
||||
|
||||
private static Response callAs(String authHeader, String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver." + action)
|
||||
.header("Authorization", authHeader)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
// ---------- CreateFirewallDomainList / DeleteFirewallDomainList ----------
|
||||
|
||||
@Test
|
||||
void createFirewallDomainList_returnsCompleteListAndIsListable() {
|
||||
String id = call("CreateFirewallDomainList", "{\"Name\":\"ab-custom-fdl\","
|
||||
+ "\"CreatorRequestId\":\"tok-create-fdl\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainList.Name", equalTo("ab-custom-fdl"))
|
||||
.body("FirewallDomainList.Status", equalTo("COMPLETE"))
|
||||
.extract().path("FirewallDomainList.Id");
|
||||
|
||||
call("GetFirewallDomainList", "{\"FirewallDomainListId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainList.Id", equalTo(id));
|
||||
|
||||
call("ListFirewallDomainLists", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainLists.Id", hasItem(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteFirewallDomainList_removesCustomList() {
|
||||
String id = call("CreateFirewallDomainList", "{\"Name\":\"ab-delete-fdl\","
|
||||
+ "\"CreatorRequestId\":\"tok-delete-fdl\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("FirewallDomainList.Id");
|
||||
|
||||
call("DeleteFirewallDomainList", "{\"FirewallDomainListId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainList.Status", equalTo("DELETING"));
|
||||
|
||||
call("GetFirewallDomainList", "{\"FirewallDomainListId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFirewallDomainList_missingName_returnsValidationException() {
|
||||
// The DNS Firewall operations model ValidationException, not the resolver
|
||||
// family's InvalidParameterException: CreateFirewallDomainList does not list
|
||||
// InvalidParameterException among its errors at all.
|
||||
call("CreateFirewallDomainList", "{\"CreatorRequestId\":\"tok-fdl-noname\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
// ---------- CreatorRequestId idempotency ----------
|
||||
|
||||
@Test
|
||||
void createFirewallDomainList_replayedCreatorRequestId_returnsOriginalList() {
|
||||
String body = "{\"Name\":\"ab-idem-fdl\",\"CreatorRequestId\":\"tok-idem-fdl\"}";
|
||||
|
||||
String first = call("CreateFirewallDomainList", body)
|
||||
.then().statusCode(200).extract().path("FirewallDomainList.Id");
|
||||
String second = call("CreateFirewallDomainList", body)
|
||||
.then().statusCode(200).extract().path("FirewallDomainList.Id");
|
||||
|
||||
assertEquals(first, second);
|
||||
call("ListFirewallDomainLists", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainLists.findAll { it.CreatorRequestId == 'tok-idem-fdl' }.size()",
|
||||
equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFirewallDomainList_withoutCreatorRequestId_createsDistinctLists() {
|
||||
String body = "{\"Name\":\"ab-noidem-fdl\"}";
|
||||
|
||||
String first = call("CreateFirewallDomainList", body)
|
||||
.then().statusCode(200).extract().path("FirewallDomainList.Id");
|
||||
String second = call("CreateFirewallDomainList", body)
|
||||
.then().statusCode(200).extract().path("FirewallDomainList.Id");
|
||||
|
||||
assertNotEquals(first, second);
|
||||
}
|
||||
|
||||
@Test
|
||||
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\"}";
|
||||
|
||||
String first = call("CreateResolverEndpoint", body)
|
||||
.then().statusCode(200).extract().path("ResolverEndpoint.Id");
|
||||
String second = call("CreateResolverEndpoint", body)
|
||||
.then().statusCode(200).extract().path("ResolverEndpoint.Id");
|
||||
|
||||
assertEquals(first, second);
|
||||
call("ListResolverEndpoints", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoints.findAll { it.CreatorRequestId == 'tok-idem-endpoint' }.size()",
|
||||
equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_withoutCreatorRequestId_createsDistinctEndpoints() {
|
||||
String body = "{\"Name\":\"ab-noidem-endpoint\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.5\"}]}";
|
||||
|
||||
String first = call("CreateResolverEndpoint", body)
|
||||
.then().statusCode(200).extract().path("ResolverEndpoint.Id");
|
||||
String second = call("CreateResolverEndpoint", body)
|
||||
.then().statusCode(200).extract().path("ResolverEndpoint.Id");
|
||||
|
||||
assertNotEquals(first, second);
|
||||
}
|
||||
|
||||
@Test
|
||||
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\"}";
|
||||
call("CreateResolverEndpoint", valid).then().statusCode(200);
|
||||
|
||||
// Replaying the token does not excuse a malformed request body.
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-idem-validate\",\"Direction\":\"INBOUND\","
|
||||
+ "\"CreatorRequestId\":\"tok-idem-validate\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
|
||||
// ... 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\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverRule_replayedCreatorRequestId_returnsOriginalRule() {
|
||||
String body = "{\"Name\":\"ab-idem-rule\",\"RuleType\":\"FORWARD\","
|
||||
+ "\"DomainName\":\"ab-idem-rule.example.com.\","
|
||||
+ "\"TargetIps\":[{\"Ip\":\"10.0.0.1\",\"Port\":53}],"
|
||||
+ "\"CreatorRequestId\":\"tok-idem-rule\"}";
|
||||
|
||||
String first = call("CreateResolverRule", body)
|
||||
.then().statusCode(200).extract().path("ResolverRule.Id");
|
||||
String second = call("CreateResolverRule", body)
|
||||
.then().statusCode(200).extract().path("ResolverRule.Id");
|
||||
|
||||
assertEquals(first, second);
|
||||
call("ListResolverRules", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRules.findAll { it.CreatorRequestId == 'tok-idem-rule' }.size()", equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverRule_withoutCreatorRequestId_createsDistinctRules() {
|
||||
String body = "{\"Name\":\"ab-noidem-rule\",\"RuleType\":\"FORWARD\","
|
||||
+ "\"DomainName\":\"ab-noidem-rule.example.com.\","
|
||||
+ "\"TargetIps\":[{\"Ip\":\"10.0.0.1\",\"Port\":53}]}";
|
||||
|
||||
String first = call("CreateResolverRule", body)
|
||||
.then().statusCode(200).extract().path("ResolverRule.Id");
|
||||
String second = call("CreateResolverRule", body)
|
||||
.then().statusCode(200).extract().path("ResolverRule.Id");
|
||||
|
||||
assertNotEquals(first, second);
|
||||
}
|
||||
|
||||
// ---------- A replayed token with different parameters is a conflict ----------
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_replayedCreatorRequestIdWithDifferentParameters_returnsResourceExists() {
|
||||
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 + "\"}")
|
||||
.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 + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceExistsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_replayedCreatorRequestIdWithDifferentIpValues_returnsResourceExists() {
|
||||
String token = "tok-conflict-endpoint-ips";
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-conflict-ips\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":["
|
||||
+ "{\"SubnetId\":\"subnet-aaa\",\"Ip\":\"10.0.0.5\"},"
|
||||
+ "{\"SubnetId\":\"subnet-bbb\",\"Ip\":\"10.0.1.5\"}],"
|
||||
+ "\"CreatorRequestId\":\"" + token + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
// Same COUNT of IP requests, different subnet and IP values. Comparing counts alone
|
||||
// would read this as an equivalent replay and silently return the original endpoint.
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-conflict-ips\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":["
|
||||
+ "{\"SubnetId\":\"subnet-ccc\",\"Ip\":\"10.0.2.5\"},"
|
||||
+ "{\"SubnetId\":\"subnet-ddd\",\"Ip\":\"10.0.3.5\"}],"
|
||||
+ "\"CreatorRequestId\":\"" + token + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceExistsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_replayedCreatorRequestIdWithIdenticalIps_returnsTheOriginal() {
|
||||
String token = "tok-replay-endpoint-ips";
|
||||
String body = "{\"Name\":\"ab-replay-ips\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":["
|
||||
+ "{\"SubnetId\":\"subnet-aaa\",\"Ip\":\"10.0.0.5\"},"
|
||||
+ "{\"SubnetId\":\"subnet-bbb\",\"Ip\":\"10.0.1.5\"}],"
|
||||
+ "\"CreatorRequestId\":\"" + token + "\"}";
|
||||
|
||||
String first = call("CreateResolverEndpoint", body)
|
||||
.then().statusCode(200).extract().path("ResolverEndpoint.Id");
|
||||
|
||||
// A genuine retry must still be idempotent — the stricter comparison must not turn
|
||||
// every retry into a conflict.
|
||||
call("CreateResolverEndpoint", body)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Id", equalTo(first));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_replayedWithReorderedFieldsWithinIpRequests_returnsTheOriginal() {
|
||||
// Same two IP requests, but the members are written in a different order inside each
|
||||
// object. JSON object member order is not significant, so this is the same request.
|
||||
// The pair is chosen so that ordering the entries by their serialised form flips:
|
||||
// by SubnetId, subnet-aaa sorts first; by Ip, 10.0.0.1 sorts first — opposite entries.
|
||||
String token = "tok-field-order";
|
||||
String subnetFirst = "{\"Name\":\"ab-field-order\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":["
|
||||
+ "{\"SubnetId\":\"subnet-zzz\",\"Ip\":\"10.0.0.1\"},"
|
||||
+ "{\"SubnetId\":\"subnet-aaa\",\"Ip\":\"10.9.9.9\"}],"
|
||||
+ "\"CreatorRequestId\":\"" + token + "\"}";
|
||||
String ipFirst = "{\"Name\":\"ab-field-order\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":["
|
||||
+ "{\"Ip\":\"10.0.0.1\",\"SubnetId\":\"subnet-zzz\"},"
|
||||
+ "{\"Ip\":\"10.9.9.9\",\"SubnetId\":\"subnet-aaa\"}],"
|
||||
+ "\"CreatorRequestId\":\"" + token + "\"}";
|
||||
|
||||
String first = call("CreateResolverEndpoint", subnetFirst)
|
||||
.then().statusCode(200).extract().path("ResolverEndpoint.Id");
|
||||
|
||||
call("CreateResolverEndpoint", ipFirst)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Id", equalTo(first));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_replayResponseOmitsInternalIpFingerprint() {
|
||||
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 + "\"}")
|
||||
.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.any { it.key == 'IpAddressRequests' }", equalTo(false))
|
||||
.body("ResolverEndpoint.any { it.key == 'IpAddresses' }", equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverRule_replayedCreatorRequestIdWithDifferentParameters_returnsResourceExists() {
|
||||
String token = "tok-conflict-rule";
|
||||
call("CreateResolverRule", "{\"Name\":\"ab-conflict-rule\",\"RuleType\":\"FORWARD\","
|
||||
+ "\"DomainName\":\"ab-conflict.example.com.\","
|
||||
+ "\"TargetIps\":[{\"Ip\":\"10.0.0.1\",\"Port\":53}],"
|
||||
+ "\"CreatorRequestId\":\"" + token + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("CreateResolverRule", "{\"Name\":\"ab-conflict-rule\",\"RuleType\":\"FORWARD\","
|
||||
+ "\"DomainName\":\"ab-conflict-different.example.com.\","
|
||||
+ "\"TargetIps\":[{\"Ip\":\"10.0.0.1\",\"Port\":53}],"
|
||||
+ "\"CreatorRequestId\":\"" + token + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceExistsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFirewallDomainList_replayedCreatorRequestIdWithDifferentParameters_returnsTheOriginal() {
|
||||
// Deliberate divergence, pinned so it cannot drift silently: CreateFirewallDomainList
|
||||
// models no conflict error at all (LimitExceeded / Validation / AccessDenied /
|
||||
// InternalServiceError / Throttling only), so there is no faithful way to report a
|
||||
// conflicting retry here. The lenient replay stands rather than inventing an error
|
||||
// code. See issues/route53resolver-firewall-domain-list-retry-conflict.md.
|
||||
String token = "tok-conflict-fdl";
|
||||
String first = call("CreateFirewallDomainList",
|
||||
"{\"Name\":\"ab-conflict-fdl\",\"CreatorRequestId\":\"" + token + "\"}")
|
||||
.then().statusCode(200).extract().path("FirewallDomainList.Id");
|
||||
|
||||
call("CreateFirewallDomainList",
|
||||
"{\"Name\":\"ab-conflict-fdl-renamed\",\"CreatorRequestId\":\"" + token + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainList.Id", equalTo(first))
|
||||
.body("FirewallDomainList.Name", equalTo("ab-conflict-fdl"));
|
||||
}
|
||||
|
||||
// ---------- CreatorRequestId replay is scoped to one region ----------
|
||||
|
||||
@Test
|
||||
void createFirewallDomainList_sameCreatorRequestIdInAnotherRegion_createsRegionalList() {
|
||||
String body = "{\"Name\":\"ab-xregion-fdl\",\"CreatorRequestId\":\"tok-xregion-fdl\"}";
|
||||
|
||||
String east = callAs(AUTH_HEADER, "CreateFirewallDomainList", body)
|
||||
.then().statusCode(200)
|
||||
.body("FirewallDomainList.Arn", startsWith("arn:aws:route53resolver:us-east-1:"))
|
||||
.extract().path("FirewallDomainList.Id");
|
||||
|
||||
callAs(AUTH_HEADER_WEST, "CreateFirewallDomainList", body)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
// A replay in another region must not hand back us-east-1's resource.
|
||||
.body("FirewallDomainList.Id", not(equalTo(east)))
|
||||
.body("FirewallDomainList.Arn", startsWith("arn:aws:route53resolver:us-west-2:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
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\"}";
|
||||
|
||||
String east = callAs(AUTH_HEADER, "CreateResolverEndpoint", body)
|
||||
.then().statusCode(200)
|
||||
.body("ResolverEndpoint.Arn", startsWith("arn:aws:route53resolver:us-east-1:"))
|
||||
.extract().path("ResolverEndpoint.Id");
|
||||
|
||||
callAs(AUTH_HEADER_WEST, "CreateResolverEndpoint", body)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Id", not(equalTo(east)))
|
||||
.body("ResolverEndpoint.Arn", startsWith("arn:aws:route53resolver:us-west-2:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverRule_sameCreatorRequestIdInAnotherRegion_createsRegionalRule() {
|
||||
String body = "{\"Name\":\"ab-xregion-rule\",\"RuleType\":\"FORWARD\","
|
||||
+ "\"DomainName\":\"ab-xregion-rule.example.com.\","
|
||||
+ "\"TargetIps\":[{\"Ip\":\"10.0.0.1\",\"Port\":53}],"
|
||||
+ "\"CreatorRequestId\":\"tok-xregion-rule\"}";
|
||||
|
||||
String east = callAs(AUTH_HEADER, "CreateResolverRule", body)
|
||||
.then().statusCode(200)
|
||||
.body("ResolverRule.Arn", startsWith("arn:aws:route53resolver:us-east-1:"))
|
||||
.extract().path("ResolverRule.Id");
|
||||
|
||||
callAs(AUTH_HEADER_WEST, "CreateResolverRule", body)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRule.Id", not(equalTo(east)))
|
||||
.body("ResolverRule.Arn", startsWith("arn:aws:route53resolver:us-west-2:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFirewallDomainList_replayWithinTheSameRegion_stillReturnsTheOriginal() {
|
||||
String body = "{\"Name\":\"ab-sameregion-fdl\",\"CreatorRequestId\":\"tok-sameregion-fdl\"}";
|
||||
|
||||
String first = callAs(AUTH_HEADER_WEST, "CreateFirewallDomainList", body)
|
||||
.then().statusCode(200).extract().path("FirewallDomainList.Id");
|
||||
String second = callAs(AUTH_HEADER_WEST, "CreateFirewallDomainList", body)
|
||||
.then().statusCode(200).extract().path("FirewallDomainList.Id");
|
||||
|
||||
assertEquals(first, second);
|
||||
}
|
||||
|
||||
// ---------- Resolver endpoints ----------
|
||||
|
||||
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 + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ResolverEndpoint.Id");
|
||||
}
|
||||
|
||||
@Test
|
||||
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\"}")
|
||||
.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));
|
||||
}
|
||||
|
||||
@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\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Direction", equalTo("INBOUND"))
|
||||
.body("ResolverEndpoint.Id", startsWith("rslvr-in-"));
|
||||
}
|
||||
|
||||
@Test
|
||||
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\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Direction", equalTo("OUTBOUND"))
|
||||
.body("ResolverEndpoint.Id", startsWith("rslvr-out-"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_unknownDirection_returnsInvalidParameters() {
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-endpoint-sideways\",\"Direction\":\"SIDEWAYS\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"IpAddressRequests\":[{\"SubnetId\":\"subnet-abc\","
|
||||
+ "\"Ip\":\"10.0.0.7\"}],\"CreatorRequestId\":\"tok-endpoint-sideways\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverEndpoint_missingIpAddressRequests_returnsInvalidParameters() {
|
||||
call("CreateResolverEndpoint", "{\"Name\":\"ab-endpoint-noip\",\"Direction\":\"INBOUND\","
|
||||
+ "\"SecurityGroupIds\":[\"sg-abc123\"],\"CreatorRequestId\":\"tok-noip\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getResolverEndpoint_returnsCreatedEndpoint() {
|
||||
String id = createEndpoint("ab-endpoint-get");
|
||||
|
||||
call("GetResolverEndpoint", "{\"ResolverEndpointId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Id", equalTo(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getResolverEndpoint_unknownId_returnsResourceNotFound() {
|
||||
call("GetResolverEndpoint", "{\"ResolverEndpointId\":\"rslvr-in-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listResolverEndpoints_includesCreatedEndpoint() {
|
||||
String id = createEndpoint("ab-endpoint-list");
|
||||
|
||||
call("ListResolverEndpoints", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoints.Id", hasItem(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateResolverEndpoint_changesName() {
|
||||
String id = createEndpoint("ab-endpoint-update-before");
|
||||
|
||||
call("UpdateResolverEndpoint", "{\"ResolverEndpointId\":\"" + id
|
||||
+ "\",\"Name\":\"ab-endpoint-update-after\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Id", equalTo(id))
|
||||
.body("ResolverEndpoint.Name", equalTo("ab-endpoint-update-after"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateResolverEndpoint_unknownEndpointType_returnsInvalidParameters() {
|
||||
String id = createEndpoint("ab-endpoint-badtype");
|
||||
|
||||
// ResolverEndpointType is an enum of IPV6 / IPV4 / DUALSTACK: storing anything
|
||||
// else would have GetResolverEndpoint report an endpoint type AWS never allows.
|
||||
call("UpdateResolverEndpoint", "{\"ResolverEndpointId\":\"" + id
|
||||
+ "\",\"ResolverEndpointType\":\"IPV5\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
|
||||
call("GetResolverEndpoint", "{\"ResolverEndpointId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.ResolverEndpointType", equalTo(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteResolverEndpoint_removesEndpoint() {
|
||||
String id = createEndpoint("ab-endpoint-delete");
|
||||
|
||||
call("DeleteResolverEndpoint", "{\"ResolverEndpointId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverEndpoint.Status", equalTo("DELETING"));
|
||||
|
||||
call("GetResolverEndpoint", "{\"ResolverEndpointId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- Resolver rules ----------
|
||||
|
||||
private static String createRule(String name, String domain) {
|
||||
return call("CreateResolverRule", "{\"Name\":\"" + name + "\",\"RuleType\":\"FORWARD\","
|
||||
+ "\"DomainName\":\"" + domain + "\",\"TargetIps\":[{\"Ip\":\"10.0.0.1\",\"Port\":53}],"
|
||||
+ "\"CreatorRequestId\":\"tok-" + name + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ResolverRule.Id");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverRule_returnsCompleteRule() {
|
||||
call("CreateResolverRule", "{\"Name\":\"ab-rule-create\",\"RuleType\":\"FORWARD\","
|
||||
+ "\"DomainName\":\"example.com.\",\"TargetIps\":[{\"Ip\":\"10.0.0.1\",\"Port\":53}],"
|
||||
+ "\"CreatorRequestId\":\"tok-rule-create\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRule.Name", equalTo("ab-rule-create"))
|
||||
.body("ResolverRule.DomainName", equalTo("example.com."))
|
||||
.body("ResolverRule.RuleType", equalTo("FORWARD"))
|
||||
.body("ResolverRule.Status", equalTo("COMPLETE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverRule_emptyTargetIps_returnsInvalidParameters() {
|
||||
// The model pins TargetIps to list min 1: present-but-empty is invalid.
|
||||
// Absent TargetIps stays allowed (SYSTEM rules carry none).
|
||||
call("CreateResolverRule", "{\"Name\":\"ab-rule-emptytargets\",\"RuleType\":\"FORWARD\","
|
||||
+ "\"DomainName\":\"ab-rule-emptytargets.example.com.\",\"TargetIps\":[],"
|
||||
+ "\"CreatorRequestId\":\"tok-rule-emptytargets\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolverRule_unknownRuleType_returnsInvalidParameters() {
|
||||
// RuleTypeOption is FORWARD / SYSTEM / RECURSIVE / DELEGATE. An unmodelled value
|
||||
// was stored verbatim and echoed back by Get/ListResolverRules as a real rule.
|
||||
call("CreateResolverRule", "{\"Name\":\"ab-rule-badtype\",\"RuleType\":\"SIDEWAYS\","
|
||||
+ "\"DomainName\":\"ab-rule-badtype.example.com.\","
|
||||
+ "\"TargetIps\":[{\"Ip\":\"10.0.0.1\",\"Port\":53}],"
|
||||
+ "\"CreatorRequestId\":\"tok-rule-badtype\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
|
||||
call("ListResolverRules", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRules.Name", not(hasItem("ab-rule-badtype")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getResolverRule_returnsCreatedRule() {
|
||||
String id = createRule("ab-rule-get", "ab-rule-get.example.com.");
|
||||
|
||||
call("GetResolverRule", "{\"ResolverRuleId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRule.Id", equalTo(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getResolverRule_unknownId_returnsResourceNotFound() {
|
||||
call("GetResolverRule", "{\"ResolverRuleId\":\"rslvr-rr-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listResolverRules_includesCreatedRule() {
|
||||
String id = createRule("ab-rule-list", "ab-rule-list.example.com.");
|
||||
|
||||
call("ListResolverRules", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRules.Id", hasItem(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateResolverRule_changesName() {
|
||||
String id = createRule("ab-rule-update-before", "ab-rule-update.example.com.");
|
||||
|
||||
call("UpdateResolverRule", "{\"ResolverRuleId\":\"" + id
|
||||
+ "\",\"Config\":{\"Name\":\"ab-rule-update-after\"}}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRule.Id", equalTo(id))
|
||||
.body("ResolverRule.Name", equalTo("ab-rule-update-after"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteResolverRule_removesRule() {
|
||||
String id = createRule("ab-rule-delete", "ab-rule-delete.example.com.");
|
||||
|
||||
call("DeleteResolverRule", "{\"ResolverRuleId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRule.Status", equalTo("DELETING"));
|
||||
|
||||
call("GetResolverRule", "{\"ResolverRuleId\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- Resolver rule associations ----------
|
||||
|
||||
@Test
|
||||
void associateResolverRule_returnsCompleteAssociation() {
|
||||
String ruleId = createRule("ab-assoc-rule", "ab-assoc.example.com.");
|
||||
|
||||
String associationId = call("AssociateResolverRule", "{\"ResolverRuleId\":\"" + ruleId
|
||||
+ "\",\"VPCId\":\"vpc-abc123\",\"Name\":\"ab-assoc-name\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRuleAssociation.ResolverRuleId", equalTo(ruleId))
|
||||
.body("ResolverRuleAssociation.VPCId", equalTo("vpc-abc123"))
|
||||
.body("ResolverRuleAssociation.Status", equalTo("COMPLETE"))
|
||||
.extract().path("ResolverRuleAssociation.Id");
|
||||
|
||||
call("GetResolverRuleAssociation", "{\"ResolverRuleAssociationId\":\"" + associationId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRuleAssociation.Id", equalTo(associationId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void associateResolverRule_unknownRule_returnsResourceNotFound() {
|
||||
call("AssociateResolverRule", "{\"ResolverRuleId\":\"rslvr-rr-doesnotexist\","
|
||||
+ "\"VPCId\":\"vpc-abc123\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listResolverRuleAssociations_includesAssociatedRule() {
|
||||
String ruleId = createRule("ab-list-assoc-rule", "ab-list-assoc.example.com.");
|
||||
call("AssociateResolverRule", "{\"ResolverRuleId\":\"" + ruleId
|
||||
+ "\",\"VPCId\":\"vpc-list-assoc\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("ListResolverRuleAssociations", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRuleAssociations.ResolverRuleId", hasItem(ruleId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void disassociateResolverRule_removesAssociation() {
|
||||
String ruleId = createRule("ab-disassoc-rule", "ab-disassoc.example.com.");
|
||||
call("AssociateResolverRule", "{\"ResolverRuleId\":\"" + ruleId
|
||||
+ "\",\"VPCId\":\"vpc-disassoc\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("DisassociateResolverRule", "{\"ResolverRuleId\":\"" + ruleId
|
||||
+ "\",\"VPCId\":\"vpc-disassoc\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRuleAssociation.Status", equalTo("DELETING"));
|
||||
|
||||
call("ListResolverRuleAssociations", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResolverRuleAssociations.findAll { it.ResolverRuleId == '" + ruleId + "' }.size()",
|
||||
equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void disassociateResolverRule_unknownAssociation_returnsResourceNotFound() {
|
||||
call("DisassociateResolverRule", "{\"ResolverRuleId\":\"rslvr-rr-neverassociated\","
|
||||
+ "\"VPCId\":\"vpc-neverassociated\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package io.github.hectorvent.floci.services.route53resolver;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Integration tests for Route 53 Resolver DNS Firewall operations
|
||||
* (JSON 1.1 protocol, {@code X-Amz-Target: Route53Resolver.*}).
|
||||
*
|
||||
* <p>LZA's {@code Custom::ResolverManagedDomainList} Lambda pages through
|
||||
* {@code ListFirewallDomainLists} and resolves an AWS-managed list's Id by
|
||||
* Name, so the managed lists must be present out of the box.</p>
|
||||
*/
|
||||
@QuarkusTest
|
||||
class Route53ResolverIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/route53resolver/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void listFirewallDomainLists_returnsAwsManagedLists() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.ListFirewallDomainLists")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainLists.Name", hasItems(
|
||||
"AWSManagedDomainsAggregateThreatList",
|
||||
"AWSManagedDomainsMalwareDomainList",
|
||||
"AWSManagedDomainsBotnetCommandandControl"))
|
||||
.body("FirewallDomainLists[0].Id", startsWith("rslvr-fdl-"))
|
||||
.body("FirewallDomainLists[0].ManagedOwnerName", equalTo("Route 53 Resolver DNS Firewall"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listFirewallDomainLists_idsAreStableAcrossCalls() {
|
||||
String firstId = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.ListFirewallDomainLists")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("FirewallDomainLists[0].Id");
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.ListFirewallDomainLists")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FirewallDomainLists[0].Id", equalTo(firstId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownOperation_returns400() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "Route53Resolver.DoesNotExist")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
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.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* What {@code CreateResolverEndpoint} does when a stored endpoint has no recorded
|
||||
* {@code IpAddressRequests} — a state the public API cannot produce, so it needs the
|
||||
* hermetic constructor.
|
||||
*
|
||||
* <p>The recorded addresses are what a replayed {@code CreatorRequestId} is checked
|
||||
* against. Without them the service cannot tell a genuine retry from a different request
|
||||
* that happens to reuse the token, so it reports the conflict rather than returning an
|
||||
* endpoint that may not match what was asked for. Failing closed is the safe direction:
|
||||
* a spurious {@code ResourceExistsException} is loud and recoverable, while a wrong
|
||||
* success is silent.</p>
|
||||
*/
|
||||
class Route53ResolverReplayFallbackTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private InMemoryStorage<String, ObjectNode> endpointIpRequests;
|
||||
private Route53ResolverService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
endpointIpRequests = new InMemoryStorage<>();
|
||||
service = new Route53ResolverService(new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), endpointIpRequests, objectMapper);
|
||||
}
|
||||
|
||||
private JsonNode createRequest(String token, String ip) {
|
||||
ObjectNode request = objectMapper.createObjectNode();
|
||||
request.put("Name", "ab-fallback");
|
||||
request.put("Direction", "INBOUND");
|
||||
request.put("CreatorRequestId", token);
|
||||
request.putArray("SecurityGroupIds").add("sg-abc123");
|
||||
ObjectNode ipRequest = request.putArray("IpAddressRequests").addObject();
|
||||
ipRequest.put("SubnetId", "subnet-aaa");
|
||||
ipRequest.put("Ip", ip);
|
||||
return request;
|
||||
}
|
||||
|
||||
@Test
|
||||
void replayWithoutARecordedIpRequestIsReportedAsAConflict() {
|
||||
String token = "tok-fallback";
|
||||
ObjectNode created = service.createResolverEndpoint(createRequest(token, "10.0.0.5"), REGION, ACCOUNT);
|
||||
|
||||
// Drop the record, leaving the endpoint behind: the shape an interrupted write, or a
|
||||
// store written by a build predating the record, would leave.
|
||||
endpointIpRequests.delete(created.get("Id").asText());
|
||||
|
||||
// Same count, different address. Comparing IpAddressCount alone would call this an
|
||||
// equivalent replay and hand back the original endpoint.
|
||||
AwsException conflict = assertThrows(AwsException.class,
|
||||
() -> service.createResolverEndpoint(createRequest(token, "10.9.9.9"), REGION, ACCOUNT));
|
||||
assertEquals("ResourceExistsException", conflict.jsonType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void replayWithoutARecordedIpRequestConflictsEvenWhenTheRequestIsIdentical() {
|
||||
// The cost of failing closed, stated as a test rather than left implicit: with no
|
||||
// record there is nothing to compare against, so even a truly identical retry is
|
||||
// refused instead of being guessed at.
|
||||
String token = "tok-fallback-identical";
|
||||
ObjectNode created = service.createResolverEndpoint(createRequest(token, "10.0.0.5"), REGION, ACCOUNT);
|
||||
endpointIpRequests.delete(created.get("Id").asText());
|
||||
|
||||
AwsException conflict = assertThrows(AwsException.class,
|
||||
() -> service.createResolverEndpoint(createRequest(token, "10.0.0.5"), REGION, ACCOUNT));
|
||||
assertEquals("ResourceExistsException", conflict.jsonType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anIntactRecordStillReplaysAnIdenticalRequest() {
|
||||
// Guard against over-correcting: the ordinary path must stay idempotent.
|
||||
String token = "tok-fallback-intact";
|
||||
ObjectNode first = service.createResolverEndpoint(createRequest(token, "10.0.0.5"), REGION, ACCOUNT);
|
||||
ObjectNode second = service.createResolverEndpoint(createRequest(token, "10.0.0.5"), REGION, ACCOUNT);
|
||||
assertEquals(first.get("Id").asText(), second.get("Id").asText());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user