Skip to content

Commit c187c92

Browse files
authored
Allow creation of hostnames on .zz-- style TLDs for RST (#2935)
This is a follow-on to PR #2909, which fixed the issue for domains, but apparently not fully for hostnames. BUG= http://b/476144993
1 parent 22ca4e3 commit c187c92

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

core/src/main/java/google/registry/flows/host/HostFlowUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static google.registry.flows.domain.DomainFlowUtils.validateFirstLabel;
1818
import static google.registry.model.EppResourceUtils.isActive;
1919
import static google.registry.model.tld.Tlds.findTldForName;
20+
import static google.registry.util.DomainNameUtils.canonicalizeHostname;
2021
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
2122
import static java.util.stream.Collectors.joining;
2223

@@ -34,7 +35,6 @@
3435
import google.registry.model.ForeignKeyUtils;
3536
import google.registry.model.domain.Domain;
3637
import google.registry.model.eppcommon.StatusValue;
37-
import google.registry.util.Idn;
3838
import java.net.InetAddress;
3939
import java.util.Optional;
4040
import org.joda.time.DateTime;
@@ -57,7 +57,7 @@ public static InternetDomainName validateHostName(String name) throws EppExcepti
5757
throw new HostNameNotLowerCaseException(hostNameLowerCase);
5858
}
5959
try {
60-
String hostNamePunyCoded = Idn.toASCII(name);
60+
String hostNamePunyCoded = canonicalizeHostname(name);
6161
if (!name.equals(hostNamePunyCoded)) {
6262
throw new HostNameNotPunyCodedException(hostNamePunyCoded);
6363
}

core/src/test/java/google/registry/flows/host/HostCreateFlowTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import google.registry.flows.host.HostFlowUtils.HostNameNotPunyCodedException;
4646
import google.registry.flows.host.HostFlowUtils.HostNameTooLongException;
4747
import google.registry.flows.host.HostFlowUtils.HostNameTooShallowException;
48+
import google.registry.flows.host.HostFlowUtils.InvalidHostNameException;
4849
import google.registry.flows.host.HostFlowUtils.LoopbackIpNotValidForHostException;
4950
import google.registry.flows.host.HostFlowUtils.SuperordinateDomainDoesNotExistException;
5051
import google.registry.flows.host.HostFlowUtils.SuperordinateDomainInPendingDeleteException;
@@ -82,9 +83,14 @@ private void setEppHostCreateInputWithIps(String hostName) {
8283
}
8384

8485
private void doSuccessfulTest() throws Exception {
86+
doSuccessfulTest("host_create_response.xml", ImmutableMap.of());
87+
}
88+
89+
private void doSuccessfulTest(String responseFile, ImmutableMap<String, String> substitutions)
90+
throws Exception {
8591
clock.advanceOneMilli();
8692
assertMutatingFlow(true);
87-
runFlowAssertResponse(loadFile("host_create_response.xml"));
93+
runFlowAssertResponse(loadFile(responseFile, substitutions));
8894
Host host = reloadResourceByForeignKey();
8995
// Check that the host was created and persisted with a history entry.
9096
assertAboutHosts()
@@ -134,6 +140,28 @@ void testSuccess_internalNeverExisted() throws Exception {
134140
assertHostDnsRequests("ns1.example.tld");
135141
}
136142

143+
@Test
144+
void testSuccess_tldWithHyphenOn3And4() throws Exception {
145+
setEppHostCreateInput("ns1.example.zz--main-2262", null);
146+
doSuccessfulTest(
147+
"host_create_response_wildcard.xml",
148+
ImmutableMap.of("HOSTNAME", "ns1.example.zz--main-2262"));
149+
}
150+
151+
@Test
152+
void testFailure_domainWithHyphenOn3And4() throws Exception {
153+
setEppHostCreateInput("ns1.zz--main-2262.tld", null);
154+
EppException thrown = assertThrows(InvalidHostNameException.class, this::runFlow);
155+
assertAboutEppExceptions().that(thrown).marshalsToXml();
156+
}
157+
158+
@Test
159+
void testFailure_hostnameWithHyphenOn3And4() throws Exception {
160+
setEppHostCreateInput("zz--ns1.domain.tld", null);
161+
EppException thrown = assertThrows(InvalidHostNameException.class, this::runFlow);
162+
assertAboutEppExceptions().that(thrown).marshalsToXml();
163+
}
164+
137165
@Test
138166
void testFailure_multipartTLDsAndInvalidHost() {
139167
createTlds("bar.tld", "tld");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
2+
<response>
3+
<result code="1000">
4+
<msg>Command completed successfully</msg>
5+
</result>
6+
<resData>
7+
<host:creData
8+
xmlns:host="urn:ietf:params:xml:ns:host-1.0">
9+
<host:name>%HOSTNAME%</host:name>
10+
<host:crDate>1999-04-03T22:00:00.0Z</host:crDate>
11+
</host:creData>
12+
</resData>
13+
<trID>
14+
<clTRID>ABC-12345</clTRID>
15+
<svTRID>server-trid</svTRID>
16+
</trID>
17+
</response>
18+
</epp>

0 commit comments

Comments
 (0)