mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(route53): paginate hosted zones by name (#6997)
This commit is contained in:
1 parent
07f2d62c17
commit
fb1d2d1fdb
5 files changed
+195
-17
No files matched your search
+97
@@ -0,0 +1,97 @@
|
||||
package io.github.hectorvent.floci.services.route53;
|
||||
|
||||
import io.github.hectorvent.floci.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.route53.Route53Client;
|
||||
import software.amazon.awssdk.services.route53.model.ListHostedZonesByNameResponse;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
class Route53HostedZonesByNamePaginationIntegrationTest {
|
||||
|
||||
@Test
|
||||
void awsSdkContinuesDuplicateNamesWithBothCursorFields() {
|
||||
String name = "byname-sdk-" + UUID.randomUUID() + ".example.test.";
|
||||
String firstId = Route53HostedZoneTestSupport.createZone(name, "byname-sdk-first-" + name);
|
||||
String secondId = null;
|
||||
try {
|
||||
secondId = Route53HostedZoneTestSupport.createZone(name, "byname-sdk-second-" + name);
|
||||
try (Route53Client client = AwsTestClients.create(Route53Client.builder(), "test", Region.US_EAST_1)) {
|
||||
ListHostedZonesByNameResponse firstPage = client.listHostedZonesByName(request -> request
|
||||
.dnsName(name).maxItems("1"));
|
||||
assertEquals(1, firstPage.hostedZones().size());
|
||||
String returnedId = firstPage.hostedZones().getFirst().id();
|
||||
assertTrue(returnedId.equals("/hostedzone/" + firstId)
|
||||
|| returnedId.equals("/hostedzone/" + secondId));
|
||||
String expectedNextId = returnedId.equals("/hostedzone/" + firstId) ? secondId : firstId;
|
||||
assertTrue(firstPage.isTruncated());
|
||||
assertEquals(name, firstPage.nextDNSName());
|
||||
assertEquals(expectedNextId, firstPage.nextHostedZoneId());
|
||||
|
||||
ListHostedZonesByNameResponse secondPage = client.listHostedZonesByName(request -> request
|
||||
.dnsName(firstPage.nextDNSName())
|
||||
.hostedZoneId(firstPage.nextHostedZoneId())
|
||||
.maxItems("1"));
|
||||
assertEquals(1, secondPage.hostedZones().size());
|
||||
assertEquals("/hostedzone/" + expectedNextId, secondPage.hostedZones().getFirst().id());
|
||||
assertEquals(name, secondPage.dnsName());
|
||||
assertEquals(expectedNextId, secondPage.hostedZoneId());
|
||||
}
|
||||
} finally {
|
||||
if (secondId != null) {
|
||||
given().when().delete("/2013-04-01/hostedzone/" + secondId).then().statusCode(200);
|
||||
}
|
||||
given().when().delete("/2013-04-01/hostedzone/" + firstId).then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateNamesContinueFromTheNextZoneId() {
|
||||
String name = "byname-" + UUID.randomUUID() + ".example.test.";
|
||||
String firstId = Route53HostedZoneTestSupport.createZone(name, "byname-first-" + name);
|
||||
String secondId = null;
|
||||
try {
|
||||
secondId = Route53HostedZoneTestSupport.createZone(name, "byname-second-" + name);
|
||||
XmlPath firstPage = given()
|
||||
.queryParam("dnsname", name)
|
||||
.queryParam("maxitems", 1)
|
||||
.when().get("/2013-04-01/hostedzonesbyname")
|
||||
.then().statusCode(200).extract().xmlPath();
|
||||
|
||||
String returnedId = firstPage.getString("ListHostedZonesByNameResponse.HostedZones.HostedZone.Id");
|
||||
String expectedNextId = returnedId.equals("/hostedzone/" + firstId) ? secondId : firstId;
|
||||
assertTrue(firstPage.getBoolean("ListHostedZonesByNameResponse.IsTruncated"));
|
||||
assertEquals(name, firstPage.getString("ListHostedZonesByNameResponse.NextDNSName"));
|
||||
assertEquals(expectedNextId,
|
||||
firstPage.getString("ListHostedZonesByNameResponse.NextHostedZoneId"));
|
||||
|
||||
XmlPath secondPage = given()
|
||||
.queryParam("dnsname", firstPage.getString("ListHostedZonesByNameResponse.NextDNSName"))
|
||||
.queryParam("hostedzoneid", firstPage.getString("ListHostedZonesByNameResponse.NextHostedZoneId"))
|
||||
.queryParam("maxitems", 1)
|
||||
.when().get("/2013-04-01/hostedzonesbyname")
|
||||
.then().statusCode(200).extract().xmlPath();
|
||||
|
||||
assertEquals("/hostedzone/" + expectedNextId,
|
||||
secondPage.getString("ListHostedZonesByNameResponse.HostedZones.HostedZone.Id"));
|
||||
assertEquals(name, secondPage.getString("ListHostedZonesByNameResponse.DNSName"));
|
||||
assertEquals(expectedNextId, secondPage.getString("ListHostedZonesByNameResponse.HostedZoneId"));
|
||||
given().queryParam("maxitems", 0)
|
||||
.when().get("/2013-04-01/hostedzonesbyname")
|
||||
.then().statusCode(400);
|
||||
} finally {
|
||||
if (secondId != null) {
|
||||
given().when().delete("/2013-04-01/hostedzone/" + secondId).then().statusCode(200);
|
||||
}
|
||||
given().when().delete("/2013-04-01/hostedzone/" + firstId).then().statusCode(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.route53.model.AliasTarget;
|
||||
import io.github.hectorvent.floci.services.route53.model.HealthCheck;
|
||||
import io.github.hectorvent.floci.services.route53.model.HealthCheckConfig;
|
||||
import io.github.hectorvent.floci.services.route53.model.HostedZone;
|
||||
import io.github.hectorvent.floci.services.route53.model.ResourceRecord;
|
||||
import io.github.hectorvent.floci.services.route53.model.ResourceRecordSet;
|
||||
import io.github.hectorvent.floci.services.route53.model.VpcAssociation;
|
||||
@@ -74,6 +75,45 @@ class Route53ServiceTest {
|
||||
return new Route53Service(storageFactory, config, regionResolver, ec2Service);
|
||||
}
|
||||
|
||||
@Test
|
||||
void hostedZonesByNameUseReversedLabelsAndFilteredPageBoundary() {
|
||||
Route53Service service = newService();
|
||||
String firstId = service.createHostedZone("z.example.com.", "byname-first", null, null).zone().getId();
|
||||
String lastId = service.createHostedZone("a.other.com.", "byname-last", null, null).zone().getId();
|
||||
|
||||
assertEquals(List.of(firstId, lastId), service.listHostedZonesByName(null, 0).stream()
|
||||
.map(HostedZone::getId).toList());
|
||||
|
||||
Route53Pagination.Page<HostedZone> lastPage = service.pageHostedZonesByName("a.other.com.", null, 1);
|
||||
assertEquals(List.of(lastId), lastPage.items().stream().map(HostedZone::getId).toList());
|
||||
assertFalse(lastPage.isTruncated());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reversedDnsNameKeepsAnEscapedDotInsideItsLabel() {
|
||||
assertEquals("com.example.a\\.b.", Route53Service.reversedDnsName("a\\.b.example.com."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hostedZonesByNameContinueAcrossNamesAndLimitPagesToOneHundred() {
|
||||
Route53Service service = newService();
|
||||
for (int i = 0; i < 101; i++) {
|
||||
service.createHostedZone("zone-" + String.format("%03d", i) + ".example.test.",
|
||||
"byname-cap-" + i, null, null);
|
||||
}
|
||||
|
||||
assertEquals(101, service.listHostedZonesByName(null, 0).size());
|
||||
Route53Pagination.Page<HostedZone> firstPage = service.pageHostedZonesByName(null, null, 200);
|
||||
assertEquals(100, firstPage.items().size());
|
||||
assertTrue(firstPage.isTruncated());
|
||||
|
||||
HostedZone nextZone = firstPage.nextItem();
|
||||
Route53Pagination.Page<HostedZone> secondPage = service.pageHostedZonesByName(
|
||||
nextZone.getName(), nextZone.getId(), 200);
|
||||
assertEquals(List.of(nextZone.getId()), secondPage.items().stream().map(HostedZone::getId).toList());
|
||||
assertFalse(secondPage.isTruncated());
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "configured names ending in {0}")
|
||||
@ValueSource(strings = {"", ".", " ", ".\t", ".\u2003"})
|
||||
void defaultApexRecordsUseAbsoluteNamesAndTheDelegationSetDoesNot(String nameserverSuffix) {
|
||||
|
||||
Reference in new issue
Block a user