Skip to content

Commit c24f09f

Browse files
authored
Don't call canonicalizeHostname() on nomulus command TLD args (#2908)
The canonicalizeHostname() helper method is only suitable for use with domain names or host names. It does not work on bare TLDs, because a bare TLD can have hyphens in the third and fourth position without necessarily being an IDN. Note that the configure TLD command already correctly allows TLDs with such names to be created. Note that we are still enforcing that the TLDs to be added exist, so they have to pass all TLD naming requirements that are enforced on creating TLDs, and we are still lowercasing the TLD names passed as arguments here (though we're no longer punycoding them, although arguably that's not super useful on command-line params anyway). BUG= http://b/471013082
1 parent fd51035 commit c24f09f

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import static com.google.common.base.Verify.verify;
2020
import static com.google.common.collect.ImmutableList.toImmutableList;
2121
import static com.google.common.collect.ImmutableSet.toImmutableSet;
22-
import static google.registry.util.DomainNameUtils.canonicalizeHostname;
2322
import static google.registry.util.RegistrarUtils.normalizeRegistrarName;
2423
import static java.nio.charset.StandardCharsets.US_ASCII;
2524
import static org.joda.time.DateTimeZone.UTC;
2625

2726
import com.beust.jcommander.Parameter;
27+
import com.google.common.base.Ascii;
2828
import com.google.common.collect.ImmutableList;
2929
import com.google.common.collect.ImmutableSet;
3030
import google.registry.flows.certs.CertificateChecker;
@@ -305,20 +305,16 @@ protected final void init() throws Exception {
305305
if (!allowedTlds.isEmpty()) {
306306
checkArgument(
307307
addAllowedTlds.isEmpty(), "Can't specify both --allowedTlds and --addAllowedTlds");
308-
ImmutableSet.Builder<String> allowedTldsBuilder = new ImmutableSet.Builder<>();
309-
for (String allowedTld : allowedTlds) {
310-
allowedTldsBuilder.add(canonicalizeHostname(allowedTld));
311-
}
312-
builder.setAllowedTlds(allowedTldsBuilder.build());
308+
builder.setAllowedTlds(
309+
allowedTlds.stream().map(Ascii::toLowerCase).collect(toImmutableSet()));
313310
}
314311
if (!addAllowedTlds.isEmpty()) {
315312
ImmutableSet.Builder<String> allowedTldsBuilder = new ImmutableSet.Builder<>();
316313
if (oldRegistrar != null) {
317314
allowedTldsBuilder.addAll(oldRegistrar.getAllowedTlds());
318315
}
319-
for (String allowedTld : addAllowedTlds) {
320-
allowedTldsBuilder.add(canonicalizeHostname(allowedTld));
321-
}
316+
allowedTldsBuilder.addAll(
317+
addAllowedTlds.stream().map(Ascii::toLowerCase).collect(toImmutableSet()));
322318
builder.setAllowedTlds(allowedTldsBuilder.build());
323319
}
324320
if (ipAllowList != null) {

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ void testSuccess_allowedTlds() throws Exception {
124124
.containsExactly("xn--q9jyb4c", "foobar");
125125
}
126126

127+
@Test
128+
void testSuccess_allowedTlds_tldNameWithHyphens() throws Exception {
129+
persistRdapAbuseContact();
130+
createTlds("zz--main-1611", "foobar");
131+
persistResource(
132+
loadRegistrar("NewRegistrar")
133+
.asBuilder()
134+
.setAllowedTlds(ImmutableSet.of("foobar"))
135+
.build());
136+
runCommandInEnvironment(
137+
RegistryToolEnvironment.PRODUCTION,
138+
"--allowed_tlds=zz--main-1611,foobar",
139+
"--force",
140+
"NewRegistrar");
141+
assertThat(loadRegistrar("NewRegistrar").getAllowedTlds())
142+
.containsExactly("zz--main-1611", "foobar");
143+
}
144+
127145
@Test
128146
void testSuccess_addAllowedTlds() throws Exception {
129147
persistRdapAbuseContact();
@@ -142,6 +160,19 @@ void testSuccess_addAllowedTlds() throws Exception {
142160
.containsExactly("xn--q9jyb4c", "foo", "bar");
143161
}
144162

163+
@Test
164+
void testSuccess_addAllowedTlds_tldNameWithHyphens() throws Exception {
165+
persistRdapAbuseContact();
166+
createTlds("foo", "bar", "zz--main-1611");
167+
runCommandInEnvironment(
168+
RegistryToolEnvironment.PRODUCTION,
169+
"--add_allowed_tlds=foo,bar",
170+
"--force",
171+
"NewRegistrar");
172+
assertThat(loadRegistrar("NewRegistrar").getAllowedTlds())
173+
.containsExactly("foo", "bar", "zz--main-1611");
174+
}
175+
145176
@Test
146177
void testSuccess_addAllowedTldsWithDupes() throws Exception {
147178
persistRdapAbuseContact();

0 commit comments

Comments
 (0)