Skip to content

Commit db1dbb4

Browse files
committed
Allow top level tld creation in Sandbox
Add a flag to the CreateCdnsTld command to bypass the dns name format check in Sandbox (limiting names to `*.test.`). With this flag, we can create TLDs for RST testing in Sandbox. Note that if the new flag is wrongly set for a disallowed name, the request to the Cloud DNS API will fail. The format check in the command just provides a user-friendly error message.
1 parent 97d0b76 commit db1dbb4

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ final class CreateCdnsTld extends ConfirmingCommand {
4747
)
4848
String name;
4949

50+
@Parameter(
51+
names = "--skip_sandbox_tld_check",
52+
description = "In Sandbox, skip the dns_name format check.")
53+
boolean skipSandboxTldCheck;
54+
5055
@Inject
5156
@Config("projectId")
5257
String projectId;
@@ -61,10 +66,15 @@ final class CreateCdnsTld extends ConfirmingCommand {
6166
protected void init() {
6267
// Sandbox talks to production Cloud DNS. As a result, we can't configure any domains with a
6368
// suffix that might be used by customers on the same nameserver set. Limit the user to setting
64-
// up *.test TLDs.
65-
if (RegistryToolEnvironment.get() == RegistryToolEnvironment.SANDBOX
66-
&& !dnsName.endsWith(".test.")) {
67-
throw new IllegalArgumentException("Sandbox TLDs must be of the form \"*.test.\"");
69+
// up *.test TLDs unless the user declares that the name is approved.
70+
//
71+
// The name format check simply provides a user-friendly error message. If the user wrongly
72+
// declares name approval, the request to the Cloud DNS API will still fail.
73+
if (RegistryToolEnvironment.get() == RegistryToolEnvironment.SANDBOX) {
74+
if (!skipSandboxTldCheck && !dnsName.endsWith(".test.")) {
75+
throw new IllegalArgumentException(
76+
"Sandbox TLDs must be approved or in the form \"*.test.\"");
77+
}
6878
}
6979

7080
managedZone =

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,37 @@ void testNameDefault() throws Exception {
7676

7777
@Test
7878
@MockitoSettings(strictness = Strictness.LENIENT)
79-
void testSandboxTldRestrictions() {
79+
void testSandboxTldRestrictions_Disallowed() {
8080
IllegalArgumentException thrown =
8181
assertThrows(
8282
IllegalArgumentException.class,
83-
() -> runCommandInEnvironment(RegistryToolEnvironment.SANDBOX, "--dns_name=foobar."));
84-
assertThat(thrown).hasMessageThat().contains("Sandbox TLDs must be of the form \"*.test.\"");
83+
() ->
84+
runCommandInEnvironment(
85+
RegistryToolEnvironment.SANDBOX,
86+
"--dns_name=foobar.",
87+
"--description=test run",
88+
"--force"));
89+
assertThat(thrown)
90+
.hasMessageThat()
91+
.contains("Sandbox TLDs must be approved or in the form \"*.test.\"");
92+
}
93+
94+
@Test
95+
void testSandboxTldRestrictions_tldCheckSkipped() throws Exception {
96+
runCommandInEnvironment(
97+
RegistryToolEnvironment.SANDBOX,
98+
"--dns_name=foobar.",
99+
"--description=test run",
100+
"--force",
101+
"--skip_sandbox_tld_check");
102+
}
103+
104+
@Test
105+
void testSandboxTldRestrictions_testTld() throws Exception {
106+
runCommandInEnvironment(
107+
RegistryToolEnvironment.SANDBOX,
108+
"--dns_name=abc.test.",
109+
"--description=test run",
110+
"--force");
85111
}
86112
}

0 commit comments

Comments
 (0)