Translate multi-part TLD zone names

Convert periods to hyphens in multi-part TLDs when using them as a zone name
(cloud-dns doesn't allow periods in zone names).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172007089
This commit is contained in:
mmuller 2017-10-12 13:53:30 -07:00 committed by jianglai
parent 7e85ae9964
commit bf818a0139
2 changed files with 19 additions and 4 deletions

View file

@ -99,7 +99,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
Retrier retrier) {
this.dnsConnection = dnsConnection;
this.projectId = projectId;
this.zoneName = zoneName;
this.zoneName = zoneName.replace('.', '-');
this.defaultATtl = defaultATtl;
this.defaultNsTtl = defaultNsTtl;
this.defaultDsTtl = defaultDsTtl;

View file

@ -17,7 +17,6 @@ package google.registry.dns.writer.clouddns;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.newHostResource;
@ -86,6 +85,7 @@ public class CloudDnsWriterTest {
@Mock private Dns.Changes.Create createChangeRequest;
@Mock private Callable<Void> mutateZoneCallable;
@Captor ArgumentCaptor<String> recordNameCaptor;
@Captor ArgumentCaptor<String> zoneNameCaptor;
@Captor ArgumentCaptor<Change> changeCaptor;
private CloudDnsWriter writer;
private ImmutableSet<ResourceRecordSet> stubZone;
@ -101,7 +101,7 @@ public class CloudDnsWriterTest {
new CloudDnsWriter(
dnsConnection,
"projectId",
"zoneName",
"triple.secret.tld", // used by testInvalidZoneNames()
DEFAULT_A_TTL,
DEFAULT_NS_TTL,
DEFAULT_DS_TTL,
@ -142,7 +142,7 @@ public class CloudDnsWriterTest {
}
});
when(changes.create(anyString(), anyString(), changeCaptor.capture()))
when(changes.create(anyString(), zoneNameCaptor.capture(), changeCaptor.capture()))
.thenReturn(createChangeRequest);
// Change our stub zone when a request to change the records is executed
when(createChangeRequest.execute())
@ -485,4 +485,19 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 1, 0, 0, 0));
}
@Test
public void testInvalidZoneNames() {
createTld("triple.secret.tld");
persistResource(
fakeDomain(
"example.triple.secret.tld",
ImmutableSet.of(persistResource(fakeHost("0.ip4.example.tld", IPv4))),
0)
.asBuilder()
.build());
writer.publishDomain("example.triple.secret.tld");
writer.commit();
assertThat(zoneNameCaptor.getValue()).isEqualTo("triple-secret-tld");
}
}