Skip to content

Commit 0dc7ab9

Browse files
authored
Update CreateCdnsTld command for RST Tests (#2891)
Add a flag indicating that a Sandbox TLD should use the production servers. No additional TLD name pattern checks. Cloud DNS has an allowlist for names that may use production servers. Also updated default descriptive name generation: dropping the trailing '.', and replacing remaining dots with '_'.
1 parent 76d4dfb commit 0dc7ab9

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

core/src/main/java/google/registry/tools/CreateCdnsTld.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import com.google.api.services.dns.Dns;
2222
import com.google.api.services.dns.model.ManagedZone;
2323
import com.google.api.services.dns.model.ManagedZoneDnsSecConfig;
24+
import com.google.common.base.Joiner;
25+
import com.google.common.base.Splitter;
2426
import google.registry.config.RegistryConfig.Config;
2527
import jakarta.inject.Inject;
2628
import java.io.IOException;
@@ -52,6 +54,13 @@ final class CreateCdnsTld extends ConfirmingCommand {
5254
description = "In Sandbox, skip the dns_name format check.")
5355
boolean skipSandboxTldCheck;
5456

57+
@Parameter(
58+
names = "--use_prod_name_servers_in_sandbox",
59+
description =
60+
"In Sandbox, create zone on the production name servers, e.g., for ICANN tests. "
61+
+ "Ignored in other environments.")
62+
boolean useProdNameServersInSandbox;
63+
5564
@Inject
5665
@Config("projectId")
5766
String projectId;
@@ -77,15 +86,25 @@ protected void init() {
7786
}
7887
}
7988

89+
String nameServerSetName;
90+
if (RegistryToolEnvironment.get().equals(RegistryToolEnvironment.PRODUCTION)) {
91+
nameServerSetName = "cloud-dns-registry";
92+
} else if (RegistryToolEnvironment.get().equals(RegistryToolEnvironment.SANDBOX)
93+
&& useProdNameServersInSandbox) {
94+
nameServerSetName = "cloud-dns-registry";
95+
} else {
96+
nameServerSetName = "cloud-dns-registry-test";
97+
}
98+
8099
managedZone =
81100
new ManagedZone()
82101
.setDescription(description)
83-
.setNameServerSet(
84-
RegistryToolEnvironment.get() == RegistryToolEnvironment.PRODUCTION
85-
? "cloud-dns-registry"
86-
: "cloud-dns-registry-test")
102+
.setNameServerSet(nameServerSetName)
87103
.setDnsName(dnsName)
88-
.setName((name != null) ? name : dnsName)
104+
.setName(
105+
(name != null)
106+
? name
107+
: Joiner.on('_').join(Splitter.on('.').omitEmptyStrings().split(dnsName)))
89108
.setDnssecConfig(new ManagedZoneDnsSecConfig().setNonExistence("nsec").setState("on"));
90109
}
91110

core/src/test/java/google/registry/tools/CreateCdnsTldTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void testBasicFunctionality() throws Exception {
7171
void testNameDefault() throws Exception {
7272
runCommand("--dns_name=tld.", "--description=test run", "--force");
7373
ManagedZone zone = requestBody.getValue();
74-
assertThat(zone).isEqualTo(createZone("cloud-dns-registry-test", "test run", "tld.", "tld."));
74+
assertThat(zone).isEqualTo(createZone("cloud-dns-registry-test", "test run", "tld.", "tld"));
7575
}
7676

7777
@Test
@@ -109,4 +109,39 @@ void testSandboxTldRestrictions_testTld() throws Exception {
109109
"--description=test run",
110110
"--force");
111111
}
112+
113+
@Test
114+
void testSandbox_defaultNameServer() throws Exception {
115+
runCommandInEnvironment(
116+
RegistryToolEnvironment.SANDBOX,
117+
"--dns_name=abc.test.",
118+
"--description=test run",
119+
"--force");
120+
ManagedZone zone = requestBody.getValue();
121+
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry-test");
122+
}
123+
124+
@Test
125+
void testSandbox_useProdNameServer() throws Exception {
126+
runCommandInEnvironment(
127+
RegistryToolEnvironment.SANDBOX,
128+
"--use_prod_name_servers_in_sandbox",
129+
"--dns_name=abc.test.",
130+
"--description=test run",
131+
"--force");
132+
ManagedZone zone = requestBody.getValue();
133+
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry");
134+
}
135+
136+
@Test
137+
void testProdNameServerFlag_ignoredIfNotSandbox() throws Exception {
138+
runCommandInEnvironment(
139+
RegistryToolEnvironment.QA,
140+
"--use_prod_name_servers_in_sandbox",
141+
"--dns_name=abc.test.",
142+
"--description=test run",
143+
"--force");
144+
ManagedZone zone = requestBody.getValue();
145+
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry-test");
146+
}
112147
}

0 commit comments

Comments
 (0)