fix(route53): assign distinct nameservers to delegation sets (#7373)

This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-11-03 07:57:23 -04:00
1 parent 548f972d01
commit 525d48dede
11 files changed
+317 -56

No files matched your search

@@ -85,7 +85,7 @@ class Route53DnsPacketIntegrationTest {
void delegationNamesAndSoaUseTheStoredZone() throws Exception {
String name = uniqueName() + ".example";
String id = createZone(name);
List<String> expected = route53.getNameServers();
List<String> expected = route53.getAssignedNameServers(id);
byte[] request = request(name, 2);
byte[] response = query(request);
assertHeader(response, 0, true, 4, 0);
@@ -57,7 +57,7 @@ class Route53CfnProvisionerTest {
when(service.createHostedZone(eq("ssm.us-east-1.amazonaws.com"), eq("dns-stack/Zone"),
eq("central endpoint zone"), argThat(sameVpc(vpc)))).thenReturn(
new Route53Service.CreateZoneResult(zone, null));
when(service.getNameServers()).thenReturn(List.of("ns-1.example", "ns-2.example"));
when(service.getAssignedNameServers("Z123456789")).thenReturn(List.of("ns-1.example", "ns-2.example"));
ObjectMapper mapper = new ObjectMapper();
JsonNode props = mapper.createObjectNode()
@@ -81,6 +81,7 @@ class Route53CfnProvisionerTest {
assertEquals("Z123456789", resource.getPhysicalId());
assertEquals(Set.of("Id", "NameServers"), resource.getAttributes().keySet());
assertEquals("Z123456789", resource.getAttributes().get("Id"));
assertEquals("ns-1.example,ns-2.example", resource.getAttributes().get("NameServers"));
verify(service).createHostedZone(eq("ssm.us-east-1.amazonaws.com"), eq("dns-stack/Zone"),
eq("central endpoint zone"), argThat(sameVpc(vpc)));
verify(service, never()).associateVpcWithHostedZone(any(), any(), any());
@@ -98,7 +99,7 @@ class Route53CfnProvisionerTest {
when(service.createHostedZone(eq("ssm.us-east-1.amazonaws.com"), eq("dns-stack/Zone"),
eq(null), argThat(sameVpc(firstVpc)))).thenReturn(
new Route53Service.CreateZoneResult(zone, null));
when(service.getNameServers()).thenReturn(List.of("ns-1.example", "ns-2.example"));
when(service.getAssignedNameServers("Z123456789")).thenReturn(List.of("ns-1.example", "ns-2.example"));
ObjectMapper mapper = new ObjectMapper();
JsonNode props = mapper.createObjectNode().put("Name", "ssm.us-east-1.amazonaws.com");
@@ -172,7 +173,7 @@ class Route53CfnProvisionerTest {
HostedZone zone = new HostedZone("Z68119D97-4AB", "ssm.us-east-1.amazonaws.com.",
"dns-stack/Zone", null, (VpcAssociation) null);
when(service.getHostedZone("Z68119D97-4AB")).thenReturn(zone);
when(service.getNameServers()).thenReturn(List.of("ns-1.example", "ns-2.example"));
when(service.getAssignedNameServers("Z68119D97-4AB")).thenReturn(List.of("ns-1.example", "ns-2.example"));
ObjectMapper mapper = new ObjectMapper();
JsonNode props = mapper.createObjectNode().put("Name", "ssm.us-east-1.amazonaws.com");
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
@@ -205,7 +206,7 @@ class Route53CfnProvisionerTest {
"dns-stack/Zone", null, vpc);
when(service.createHostedZone(eq("ssm.us-east-1.amazonaws.com"), eq("dns-stack/Zone"),
eq(null), argThat(sameVpc(vpc)))).thenReturn(new Route53Service.CreateZoneResult(zone, null));
when(service.getNameServers()).thenReturn(List.of("ns-1.example", "ns-2.example"));
when(service.getAssignedNameServers("Z987654321")).thenReturn(List.of("ns-1.example", "ns-2.example"));
ObjectMapper mapper = new ObjectMapper();
JsonNode props = mapper.createObjectNode().put("Name", "ssm.us-east-1.amazonaws.com");
@@ -278,7 +279,7 @@ class Route53CfnProvisionerTest {
"caller", null, vpc);
when(service.createHostedZone(eq("ssm.us-east-1.amazonaws.com"), eq("dns-stack/Zone"),
eq(null), argThat(sameVpc(vpc)))).thenReturn(new Route53Service.CreateZoneResult(zone, null));
when(service.getNameServers()).thenReturn(List.of("ns-1.example", "ns-2.example"));
when(service.getAssignedNameServers("Z123456789")).thenReturn(List.of("ns-1.example", "ns-2.example"));
ObjectMapper mapper = new ObjectMapper();
JsonNode props = mapper.createObjectNode().put("Name", "ssm.us-east-1.amazonaws.com");
@@ -360,7 +361,7 @@ class Route53CfnProvisionerTest {
"dns-stack/Zone", null, (VpcAssociation) null);
when(service.createHostedZone(eq("ssm.us-east-1.amazonaws.com"), eq("dns-stack/Zone"),
eq(null), eq(null))).thenReturn(new Route53Service.CreateZoneResult(zone, null));
when(service.getNameServers()).thenReturn(List.of("ns-1.example", "ns-2.example"));
when(service.getAssignedNameServers("Z987654321")).thenReturn(List.of("ns-1.example", "ns-2.example"));
RuntimeException tagFailure = new AwsException("ServiceUnavailable", "throttled", 503);
Mockito.doThrow(tagFailure).when(service)
.changeTagsForResource(eq("hostedzone"), eq("Z987654321"), any(), any());
@@ -13,6 +13,7 @@ import software.amazon.awssdk.services.route53.model.ResourceRecord;
import software.amazon.awssdk.services.route53.model.ResourceRecordSet;
import software.amazon.awssdk.services.route53.model.Route53Exception;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -23,6 +24,28 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@QuarkusTest
class Route53DelegationSetHostedZonesIntegrationTest {
@Test
void implicitNameserversUseRoute53NamesForZonesAndStandaloneSets() {
try (Route53Client client = client("741686000017")) {
CreateHostedZoneResponse zone = createZone(client, "generated.example.", null);
DelegationSet set = createSet(client);
try {
List<String> suffixes = List.of("org", "net", "com", "co\\.uk");
for (List<String> names : List.of(zone.delegationSet().nameServers(), set.nameServers())) {
assertEquals(4, names.size());
for (int i = 0; i < 4; i++) {
assertTrue(names.get(i).matches("ns-[1-9][0-9]{0,3}\\.awsdns-[0-9]{2}\\." + suffixes.get(i)));
}
}
assertEquals(zone.delegationSet(), client.getHostedZone(r -> r.id(zone.hostedZone().id()))
.delegationSet());
} finally {
client.deleteHostedZone(r -> r.id(zone.hostedZone().id()));
client.deleteReusableDelegationSet(r -> r.id(set.id()));
}
}
}
@Test
void zonesReuseTheSetInResponsesAndApexRecordsUntilAllZonesAreDeleted() {
try (Route53Client client = client("741686000010")) {
@@ -94,7 +117,7 @@ class Route53DelegationSetHostedZonesIntegrationTest {
void relatedPublicNamesCannotShareNameServersButSiblingDomainsCan() {
try (Route53Client client = client("741686000013")) {
DelegationSet set = createSet(client);
String zone = createZone(client, "a.example.com.", null).hostedZone().id();
String zone = createZone(client, "a.example.com.", set.id()).hostedZone().id();
try {
for (String name : List.of("A.EXAMPLE.COM", "child.a.example.com.", "example.com.")) {
assertError("ConflictingDomainExists", () -> createZone(client, name, set.id()));
@@ -108,6 +131,56 @@ class Route53DelegationSetHostedZonesIntegrationTest {
}
}
@Test
void relatedPublicNamesCanUseIndependentNameServers() {
try (Route53Client client = client("741686000015")) {
CreateHostedZoneResponse parent = createZone(client, "parent.example.com.", null);
DelegationSet firstSet = null;
DelegationSet secondSet = null;
String child = null;
String grandchild = null;
try {
firstSet = createDisjointSet(client, parent.delegationSet().nameServers());
child = createZone(client, "child.parent.example.com.", firstSet.id()).hostedZone().id();
List<String> used = new ArrayList<>(parent.delegationSet().nameServers());
used.addAll(firstSet.nameServers());
secondSet = createDisjointSet(client, used);
grandchild = createZone(client, "grandchild.child.parent.example.com.", secondSet.id())
.hostedZone().id();
} finally {
if (grandchild != null) {
String id = grandchild;
client.deleteHostedZone(r -> r.id(id));
}
if (child != null) {
String id = child;
client.deleteHostedZone(r -> r.id(id));
}
client.deleteHostedZone(r -> r.id(parent.hostedZone().id()));
if (firstSet != null) {
DelegationSet set = firstSet;
client.deleteReusableDelegationSet(r -> r.id(set.id()));
}
if (secondSet != null) {
DelegationSet set = secondSet;
client.deleteReusableDelegationSet(r -> r.id(set.id()));
}
}
}
}
private DelegationSet createDisjointSet(Route53Client client, List<String> usedNames) {
for (int attempt = 0; attempt < 100; attempt++) {
DelegationSet set = createSet(client);
if (set.nameServers().stream().noneMatch(candidate -> usedNames.stream()
.anyMatch(name -> name.equalsIgnoreCase(candidate)))) {
return set;
}
client.deleteReusableDelegationSet(r -> r.id(set.id()));
}
throw new AssertionError("Unable to allocate a disjoint reusable delegation set after 100 attempts");
}
@Test
void privateZonesCannotUseOrPromoteAReusableSet() {
try (Route53Client client = client("741686000014")) {
@@ -12,6 +12,7 @@ import io.github.hectorvent.floci.services.route53.model.DelegationSet;
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;
import io.github.hectorvent.floci.testing.StorageFactories;
import jakarta.enterprise.inject.Instance;
import org.junit.jupiter.api.Test;
@@ -24,6 +25,7 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
@@ -32,6 +34,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -111,20 +114,112 @@ class Route53DelegationSetsServiceTest {
}
@Test
void legacyPublicZonesParticipateInConflictsBeforeTheirFirstRead() throws Exception {
void legacyPublicZonesUsePersistedNameServersForConflictChecks() throws Exception {
seedLegacyZone();
try (Fixture fixture = fixture("persistent", "original")) {
DelegationSet set = fixture.service().createReusableDelegationSet("set", null);
DelegationSet set = fixture.service().createReusableDelegationSet("set", "ZLEGACY");
assertError("ConflictingDomainExists", () -> fixture.service()
.createHostedZone("child.legacy.example.", "child", null, null, set.id()));
}
}
@Test
void independentZonesAndReusableSetsHaveDistinctNameServers() {
try (Fixture fixture = fixture("memory", null)) {
Route53Service service = fixture.service();
HostedZone firstZone = service.createHostedZone("first.example.", "first-zone", null, null).zone();
HostedZone secondZone = service.createHostedZone("second.example.", "second-zone", null, null).zone();
DelegationSet firstSet = service.createReusableDelegationSet("first-set", null);
DelegationSet secondSet = service.createReusableDelegationSet("second-set", null);
List<List<String>> assignments = List.of(service.getDelegationSet(firstZone).nameServers(),
service.getDelegationSet(secondZone).nameServers(), firstSet.nameServers(), secondSet.nameServers());
for (int i = 0; i < assignments.size(); i++) {
assertEquals(4, assignments.get(i).size());
for (int j = i + 1; j < assignments.size(); j++) {
assertNotEquals(assignments.get(i), assignments.get(j));
}
}
}
}
@Test
void explicitlyConfiguredNameServersRemainUnchangedForZonesAndSets() {
try (Fixture fixture = fixture("memory", "configured")) {
Route53Service service = fixture.service();
String zoneId = service.createHostedZone("configured.example.", "configured-zone", null, null)
.zone().getId();
DelegationSet set = service.createReusableDelegationSet("configured-set", null);
List<String> configured = List.of("configured-1.test", "configured-2.test",
"configured-3.test", "configured-4.test");
assertEquals(configured, service.getAssignedNameServers(zoneId));
assertEquals(configured, set.nameServers());
}
}
@Test
void explicitlyConfiguredLiteralDefaultsRemainUnchanged() {
try (Fixture fixture = fixture("memory", "literal-defaults")) {
Route53Service service = fixture.service();
String zoneId = service.createHostedZone("literal.example.", "literal-zone", null, null)
.zone().getId();
DelegationSet set = service.createReusableDelegationSet("literal-set", null);
List<String> configured = List.of("ns-1.awsdns-01.org", "ns-2.awsdns-02.net",
"ns-3.awsdns-03.com", "ns-4.awsdns-04.co.uk");
assertEquals(configured, service.getAssignedNameServers(zoneId));
assertEquals(configured, set.nameServers());
}
}
@Test
void mixedConfigurationOverridesOnlyItsExplicitSlot() {
try (Fixture fixture = fixture("memory", "mixed")) {
Route53Service service = fixture.service();
String publicId = service.createHostedZone("mixed.example.", "mixed-public", null, null)
.zone().getId();
String privateId = service.createHostedZone("private.mixed.example.", "mixed-private", null,
new VpcAssociation("vpc-mixed", "us-east-1")).zone().getId();
DelegationSet set = service.createReusableDelegationSet("mixed-set", null);
List<String> publicNames = service.getAssignedNameServers(publicId);
assertEquals("configured-1.test", publicNames.getFirst());
assertEquals("configured-1.test", set.nameServers().getFirst());
for (int i = 1; i < 4; i++) {
assertTrue(publicNames.get(i).matches("ns-[1-9][0-9]{0,3}\\.awsdns-[0-9]{2}\\..+"));
assertTrue(set.nameServers().get(i).matches("ns-[1-9][0-9]{0,3}\\.awsdns-[0-9]{2}\\..+"));
}
assertEquals(List.of("configured-1.test", "ns-2.awsdns-02.net", "ns-3.awsdns-03.com",
"ns-4.awsdns-04.co.uk"), service.getAssignedNameServers(privateId));
}
}
@Test
void ordinaryZoneAssignmentSurvivesStorageReloadAndConfigurationChange() {
String zoneId;
List<String> original;
try (Fixture fixture = fixture("persistent", "original")) {
zoneId = fixture.service().createHostedZone("stable.example.", "stable", null, null).zone().getId();
original = fixture.service().getAssignedNameServers(zoneId);
}
try (Fixture reloaded = fixture("persistent", "changed")) {
Route53Service service = reloaded.service();
assertEquals(original, service.getAssignedNameServers(zoneId));
List<ResourceRecordSet> records = service.listResourceRecordSets(zoneId, null, null, 100);
assertEquals(original.stream().map(name -> name + ".").toList(), records.stream()
.filter(record -> "NS".equals(record.getType())).findFirst().orElseThrow().getRecords().stream()
.map(ResourceRecord::getValue).toList());
assertTrue(records.stream().filter(record -> "SOA".equals(record.getType())).findFirst().orElseThrow()
.getRecords().getFirst().getValue().startsWith(original.getFirst() + ". "));
String next = service.createHostedZone("new.example.", "new", null, null).zone().getId();
assertTrue(service.getAssignedNameServers(next).stream().noneMatch(original::contains));
}
}
@Test
void promotionAfterConfigurationChangePreservesTheOriginalZoneAssignment() {
String zoneId;
List<String> original;
try (Fixture fixture = fixture("persistent", "original")) {
zoneId = fixture.service().createHostedZone("original.example.", "original", null, null).zone().getId();
original = fixture.service().getAssignedNameServers(zoneId);
ResourceRecordSet ns = fixture.service().listResourceRecordSets(zoneId, null, null, 100).stream()
.filter(record -> "NS".equals(record.getType())).findFirst().orElseThrow();
ns.setRecords(List.of(new ResourceRecord("custom.nameserver.test.")));
@@ -132,8 +227,7 @@ class Route53DelegationSetsServiceTest {
}
try (Fixture fixture = fixture("persistent", "changed")) {
DelegationSet set = fixture.service().createReusableDelegationSet("promoted", zoneId);
assertEquals(List.of("original-1.test", "original-2.test", "original-3.test", "original-4.test"),
set.nameServers());
assertEquals(original, set.nameServers());
}
}
@@ -285,10 +379,27 @@ class Route53DelegationSetsServiceTest {
private EmulatorConfig config(String prefix) {
EmulatorConfig config = StorageFactories.config(directory, ACCOUNT);
when(config.services().route53().defaultNameserver1()).thenReturn(prefix + "-1.test.");
when(config.services().route53().defaultNameserver2()).thenReturn(prefix + "-2.test.");
when(config.services().route53().defaultNameserver3()).thenReturn(prefix + "-3.test.");
when(config.services().route53().defaultNameserver4()).thenReturn(prefix + "-4.test.");
if (prefix == null) {
when(config.services().route53().defaultNameserver1()).thenReturn(Optional.empty());
when(config.services().route53().defaultNameserver2()).thenReturn(Optional.empty());
when(config.services().route53().defaultNameserver3()).thenReturn(Optional.empty());
when(config.services().route53().defaultNameserver4()).thenReturn(Optional.empty());
} else if ("mixed".equals(prefix)) {
when(config.services().route53().defaultNameserver1()).thenReturn(Optional.of("configured-1.test."));
when(config.services().route53().defaultNameserver2()).thenReturn(Optional.empty());
when(config.services().route53().defaultNameserver3()).thenReturn(Optional.empty());
when(config.services().route53().defaultNameserver4()).thenReturn(Optional.empty());
} else if ("literal-defaults".equals(prefix)) {
when(config.services().route53().defaultNameserver1()).thenReturn(Optional.of("ns-1.awsdns-01.org"));
when(config.services().route53().defaultNameserver2()).thenReturn(Optional.of("ns-2.awsdns-02.net"));
when(config.services().route53().defaultNameserver3()).thenReturn(Optional.of("ns-3.awsdns-03.com"));
when(config.services().route53().defaultNameserver4()).thenReturn(Optional.of("ns-4.awsdns-04.co.uk"));
} else {
when(config.services().route53().defaultNameserver1()).thenReturn(Optional.of(prefix + "-1.test."));
when(config.services().route53().defaultNameserver2()).thenReturn(Optional.of(prefix + "-2.test."));
when(config.services().route53().defaultNameserver3()).thenReturn(Optional.of(prefix + "-3.test."));
when(config.services().route53().defaultNameserver4()).thenReturn(Optional.of(prefix + "-4.test."));
}
return config;
}
@@ -6,6 +6,8 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -17,6 +19,7 @@ class Route53IntegrationTest {
private static final String XML = "application/xml";
private static String zoneId;
private static List<String> zoneNameServers;
private static String changeId;
private static String healthCheckId;
@@ -52,11 +55,13 @@ class Route53IntegrationTest {
.body("CreateHostedZoneResponse.ChangeInfo.Status", equalTo("INSYNC"))
.body("CreateHostedZoneResponse.ChangeInfo.Id", startsWith("/change/C"))
.body(not(containsString("<VPC>")))
.body(containsString("ns-1.awsdns-01.org"))
.body(containsString("<NameServer>ns-"))
.extract().header("Location");
// Location is an absolute URL: http://localhost:PORT/2013-04-01/hostedzone/ZXXX
zoneId = locationHeader.substring(locationHeader.lastIndexOf('/') + 1);
zoneNameServers = given().when().get("/2013-04-01/hostedzone/" + zoneId).then().extract()
.xmlPath().getList("GetHostedZoneResponse.DelegationSet.NameServers.NameServer");
}
@Test
@@ -71,7 +76,7 @@ class Route53IntegrationTest {
.body("GetHostedZoneResponse.HostedZone.Name", equalTo("example.com."))
.body("GetHostedZoneResponse.HostedZone.Config.PrivateZone", equalTo("false"))
.body(not(containsString("<VPCs>")))
.body(containsString("ns-1.awsdns-01.org"));
.body(containsString(zoneNameServers.getFirst()));
}
@Test
@@ -163,6 +168,8 @@ class Route53IntegrationTest {
@Test
@Order(7)
void listResourceRecordSets_autoCreatedSOAandNS() {
String firstNameserver = zoneNameServers.getFirst() + ".";
String fourthNameserver = zoneNameServers.get(3) + ".";
String body = given()
.when().get("/2013-04-01/hostedzone/" + zoneId + "/rrset")
.then()
@@ -174,8 +181,8 @@ class Route53IntegrationTest {
assertThat(body, containsString("<Type>SOA</Type>"));
assertThat(body, containsString("<Type>NS</Type>"));
assertThat(body, containsString(
"<Value>ns-1.awsdns-01.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400</Value>"));
assertThat(body, containsString("<Value>ns-4.awsdns-04.co.uk.</Value>"));
"<Value>" + firstNameserver + " awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400</Value>"));
assertThat(body, containsString("<Value>" + fourthNameserver + "</Value>"));
}
@Test
@@ -249,14 +256,14 @@ class Route53IntegrationTest {
<Type>SOA</Type>
<TTL>900</TTL>
<ResourceRecords>
<ResourceRecord><Value>ns-1.awsdns-01.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400</Value></ResourceRecord>
<ResourceRecord><Value>%s awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400</Value></ResourceRecord>
</ResourceRecords>
</ResourceRecordSet>
</Change>
</Changes>
</ChangeBatch>
</ChangeResourceRecordSetsRequest>
""";
""".formatted(zoneNameServers.getFirst() + ".");
given()
.contentType(XML)
@@ -0,0 +1,29 @@
package io.github.hectorvent.floci.services.route53;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.smallrye.config.EnvConfigSource;
import io.smallrye.config.SmallRyeConfigBuilder;
import org.junit.jupiter.api.Test;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
class Route53NameserverConfigTest {
@Test
void explicitDefaultLiteralIsDistinctFromAnUnsetNameserver() {
assertEquals(Optional.empty(), config(Map.of()).services().route53().defaultNameserver1());
assertEquals(Optional.of("ns-1.awsdns-01.org"), config(Map.of(
"FLOCI_SERVICES_ROUTE53_DEFAULT_NAMESERVER1", "ns-1.awsdns-01.org"))
.services().route53().defaultNameserver1());
}
private static EmulatorConfig config(Map<String, String> environment) {
return new SmallRyeConfigBuilder()
.addDefaultInterceptors()
.withSources(new EnvConfigSource(environment, 300))
.withMapping(EmulatorConfig.class)
.build().getConfigMapping(EmulatorConfig.class);
}
}
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
@@ -63,10 +64,10 @@ class Route53ServiceTest {
Mockito.when(config.defaultAccountId()).thenReturn(ACCOUNT);
Mockito.when(config.services()).thenReturn(servicesConfig);
Mockito.when(servicesConfig.route53()).thenReturn(route53Config);
Mockito.when(route53Config.defaultNameserver1()).thenReturn("ns-1.awsdns-00.com" + nameserverSuffix);
Mockito.when(route53Config.defaultNameserver2()).thenReturn("ns-2.awsdns-00.net" + nameserverSuffix);
Mockito.when(route53Config.defaultNameserver3()).thenReturn("ns-3.awsdns-00.org" + nameserverSuffix);
Mockito.when(route53Config.defaultNameserver4()).thenReturn("ns-4.awsdns-00.co.uk" + nameserverSuffix);
Mockito.when(route53Config.defaultNameserver1()).thenReturn(Optional.of("ns-1.awsdns-00.com" + nameserverSuffix));
Mockito.when(route53Config.defaultNameserver2()).thenReturn(Optional.of("ns-2.awsdns-00.net" + nameserverSuffix));
Mockito.when(route53Config.defaultNameserver3()).thenReturn(Optional.of("ns-3.awsdns-00.org" + nameserverSuffix));
Mockito.when(route53Config.defaultNameserver4()).thenReturn(Optional.of("ns-4.awsdns-00.co.uk" + nameserverSuffix));
Mockito.when(route53Config.vpcAssociationControlPlaneDelayMs()).thenReturn(0L);
Ec2Service ec2Service = Mockito.mock(Ec2Service.class);
@@ -116,35 +117,45 @@ class Route53ServiceTest {
@ParameterizedTest(name = "configured names ending in {0}")
@ValueSource(strings = {"", ".", " ", ".\t", ".\u2003"})
void defaultApexRecordsUseAbsoluteNamesAndTheDelegationSetDoesNot(String nameserverSuffix) {
void configuredApexRecordsUseAbsoluteNamesAndTheDelegationSetDoesNot(String nameserverSuffix) {
Route53Service service = newService(nameserverSuffix);
String zoneId = service.createHostedZone("authority.example", "authority", null, null).zone().getId();
List<ResourceRecordSet> records = service.listResourceRecordSets(zoneId, null, null, 100);
List<String> assigned = service.getAssignedNameServers(zoneId);
assertAll(
() -> assertEquals(List.of("ns-1.awsdns-00.com. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"),
() -> assertEquals(List.of(assigned.getFirst() + ". awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"),
valuesOf(records, "SOA"), "SOA"),
() -> assertEquals(List.of("ns-1.awsdns-00.com.", "ns-2.awsdns-00.net.", "ns-3.awsdns-00.org.",
"ns-4.awsdns-00.co.uk."), valuesOf(records, "NS"), "NS"),
() -> assertEquals(assigned.stream().map(name -> name + ".").toList(), valuesOf(records, "NS"), "NS"),
() -> assertEquals(List.of("ns-1.awsdns-00.com", "ns-2.awsdns-00.net", "ns-3.awsdns-00.org",
"ns-4.awsdns-00.co.uk"), service.getNameServers(), "delegation set"));
"ns-4.awsdns-00.co.uk"), assigned, "configured names"),
() -> assertEquals(assigned, service.getNameServers(), "configured bases"));
}
@ParameterizedTest(name = "configured names ending in {0}")
@ValueSource(strings = {"", ".", " ", ".\t", ".\u2003"})
void apexNsQueryIsAnswered(String nameserverSuffix) {
Route53Service service = newService(nameserverSuffix);
service.createHostedZone("authority.example", "authority", null, null);
String zoneId = service.createHostedZone("authority.example", "authority", null, null).zone().getId();
DnsAnswer answer = new Route53DnsRecordSource(service).resolveAuthoritative("authority.example", 2)
.orElseThrow();
assertEquals(0, answer.responseCode(), "rcode");
assertEquals(List.of(new DnsRecord.Ns("ns-1.awsdns-00.com."), new DnsRecord.Ns("ns-2.awsdns-00.net."),
new DnsRecord.Ns("ns-3.awsdns-00.org."), new DnsRecord.Ns("ns-4.awsdns-00.co.uk.")),
assertEquals(service.getAssignedNameServers(zoneId).stream().map(name -> new DnsRecord.Ns(name + ".")).toList(),
answer.records(), "answers");
}
@Test
void privateZonesKeepTheirConfiguredNameServers() {
Route53Service service = newService();
String zoneId = service.createHostedZone("private.example", "private", null,
new VpcAssociation("vpc-123", "us-east-1")).zone().getId();
assertEquals(service.getNameServers(), service.getAssignedNameServers(zoneId));
assertEquals(service.getNameServers().stream().map(name -> name + ".").toList(),
valuesOf(service.listResourceRecordSets(zoneId, null, null, 100), "NS"));
}
@Test
void rejectedBatchDoesNotRenameSharedStoredRecord() {
Route53Service service = newService();