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 '_'.
This commit is contained in:
Weimin Yu
2025-11-25 19:41:44 +00:00
committed by GitHub
parent 76d4dfbb04
commit 0dc7ab99d7
2 changed files with 60 additions and 6 deletions
@@ -21,6 +21,8 @@ import com.beust.jcommander.Parameters;
import com.google.api.services.dns.Dns; import com.google.api.services.dns.Dns;
import com.google.api.services.dns.model.ManagedZone; import com.google.api.services.dns.model.ManagedZone;
import com.google.api.services.dns.model.ManagedZoneDnsSecConfig; import com.google.api.services.dns.model.ManagedZoneDnsSecConfig;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import google.registry.config.RegistryConfig.Config; import google.registry.config.RegistryConfig.Config;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import java.io.IOException; import java.io.IOException;
@@ -52,6 +54,13 @@ final class CreateCdnsTld extends ConfirmingCommand {
description = "In Sandbox, skip the dns_name format check.") description = "In Sandbox, skip the dns_name format check.")
boolean skipSandboxTldCheck; boolean skipSandboxTldCheck;
@Parameter(
names = "--use_prod_name_servers_in_sandbox",
description =
"In Sandbox, create zone on the production name servers, e.g., for ICANN tests. "
+ "Ignored in other environments.")
boolean useProdNameServersInSandbox;
@Inject @Inject
@Config("projectId") @Config("projectId")
String projectId; String projectId;
@@ -77,15 +86,25 @@ final class CreateCdnsTld extends ConfirmingCommand {
} }
} }
String nameServerSetName;
if (RegistryToolEnvironment.get().equals(RegistryToolEnvironment.PRODUCTION)) {
nameServerSetName = "cloud-dns-registry";
} else if (RegistryToolEnvironment.get().equals(RegistryToolEnvironment.SANDBOX)
&& useProdNameServersInSandbox) {
nameServerSetName = "cloud-dns-registry";
} else {
nameServerSetName = "cloud-dns-registry-test";
}
managedZone = managedZone =
new ManagedZone() new ManagedZone()
.setDescription(description) .setDescription(description)
.setNameServerSet( .setNameServerSet(nameServerSetName)
RegistryToolEnvironment.get() == RegistryToolEnvironment.PRODUCTION
? "cloud-dns-registry"
: "cloud-dns-registry-test")
.setDnsName(dnsName) .setDnsName(dnsName)
.setName((name != null) ? name : dnsName) .setName(
(name != null)
? name
: Joiner.on('_').join(Splitter.on('.').omitEmptyStrings().split(dnsName)))
.setDnssecConfig(new ManagedZoneDnsSecConfig().setNonExistence("nsec").setState("on")); .setDnssecConfig(new ManagedZoneDnsSecConfig().setNonExistence("nsec").setState("on"));
} }
@@ -71,7 +71,7 @@ class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
void testNameDefault() throws Exception { void testNameDefault() throws Exception {
runCommand("--dns_name=tld.", "--description=test run", "--force"); runCommand("--dns_name=tld.", "--description=test run", "--force");
ManagedZone zone = requestBody.getValue(); ManagedZone zone = requestBody.getValue();
assertThat(zone).isEqualTo(createZone("cloud-dns-registry-test", "test run", "tld.", "tld.")); assertThat(zone).isEqualTo(createZone("cloud-dns-registry-test", "test run", "tld.", "tld"));
} }
@Test @Test
@@ -109,4 +109,39 @@ class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
"--description=test run", "--description=test run",
"--force"); "--force");
} }
@Test
void testSandbox_defaultNameServer() throws Exception {
runCommandInEnvironment(
RegistryToolEnvironment.SANDBOX,
"--dns_name=abc.test.",
"--description=test run",
"--force");
ManagedZone zone = requestBody.getValue();
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry-test");
}
@Test
void testSandbox_useProdNameServer() throws Exception {
runCommandInEnvironment(
RegistryToolEnvironment.SANDBOX,
"--use_prod_name_servers_in_sandbox",
"--dns_name=abc.test.",
"--description=test run",
"--force");
ManagedZone zone = requestBody.getValue();
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry");
}
@Test
void testProdNameServerFlag_ignoredIfNotSandbox() throws Exception {
runCommandInEnvironment(
RegistryToolEnvironment.QA,
"--use_prod_name_servers_in_sandbox",
"--dns_name=abc.test.",
"--description=test run",
"--force");
ManagedZone zone = requestBody.getValue();
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry-test");
}
} }