Fix RDAP quirks uncovered during documentation

There's no reason not to allow a one-character search string when there are no wildcards. And the ROID validity pattern did not allow underscores, which was causing problems with our ROIDs.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=136256605
This commit is contained in:
mountford 2016-10-15 13:33:11 -07:00 committed by Ben McIlwain
parent 861fd60d2c
commit f1ad34b12f
5 changed files with 24 additions and 14 deletions

View file

@ -49,7 +49,7 @@ public class RdapEntityAction extends RdapActionBase {
public static final String PATH = "/rdap/entity/"; public static final String PATH = "/rdap/entity/";
private static final Pattern ROID_PATTERN = Pattern.compile("[-.a-zA-Z0-9]+"); private static final Pattern ROID_PATTERN = Pattern.compile("[-_.a-zA-Z0-9]+");
@Inject Clock clock; @Inject Clock clock;
@Inject RdapEntityAction() {} @Inject RdapEntityAction() {}

View file

@ -16,6 +16,7 @@ package google.registry.rdap;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.DomainNameUtils.ACE_PREFIX;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -1054,6 +1055,7 @@ public class RdapJsonFormatter {
} }
private static boolean hasUnicodeComponents(String fullyQualifiedName) { private static boolean hasUnicodeComponents(String fullyQualifiedName) {
return fullyQualifiedName.startsWith("xn--") || fullyQualifiedName.contains(".xn--"); return fullyQualifiedName.startsWith(ACE_PREFIX)
|| fullyQualifiedName.contains("." + ACE_PREFIX);
} }
} }

View file

@ -14,6 +14,8 @@
package google.registry.rdap; package google.registry.rdap;
import static google.registry.util.DomainNameUtils.ACE_PREFIX;
import google.registry.request.HttpException.UnprocessableEntityException; import google.registry.request.HttpException.UnprocessableEntityException;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -82,8 +84,7 @@ public final class RdapSearchPattern {
* @throws UnprocessableEntityException if {@code pattern} does not meet the requirements of RFC * @throws UnprocessableEntityException if {@code pattern} does not meet the requirements of RFC
* 7482 * 7482
*/ */
public static RdapSearchPattern create( public static RdapSearchPattern create(String pattern, boolean allowSuffix) {
String pattern, boolean allowSuffix) throws UnprocessableEntityException {
String initialString; String initialString;
boolean hasWildcard; boolean hasWildcard;
String suffix; String suffix;
@ -112,14 +113,13 @@ public final class RdapSearchPattern {
suffix = null; suffix = null;
} }
initialString = pattern.substring(0, wildcardPos); initialString = pattern.substring(0, wildcardPos);
} if (initialString.length() < 2) {
if (initialString.length() < 2) { throw new UnprocessableEntityException("At least two characters must be specified");
throw new UnprocessableEntityException("At least two characters must be specified"); }
} if (initialString.startsWith(ACE_PREFIX) && (initialString.length() < 7)) {
if (initialString.startsWith("xn--") throw new UnprocessableEntityException(
&& (initialString.length() < 7)) { "At least seven characters must be specified for punycode domain searches");
throw new UnprocessableEntityException( }
"At least seven characters must be specified for punycode domain searches");
} }
return new RdapSearchPattern(initialString, hasWildcard, suffix); return new RdapSearchPattern(initialString, hasWildcard, suffix);
} }

View file

@ -202,8 +202,8 @@ public class RdapEntityActionTest {
@Test @Test
public void testUnknownEntity_returns404() throws Exception { public void testUnknownEntity_returns404() throws Exception {
assertThat(generateActualJson("MISSING-ENTITY")).isEqualTo( assertThat(generateActualJson("_MISSING-ENTITY_")).isEqualTo(
generateExpectedJson("MISSING-ENTITY not found", "rdap_error_404.json")); generateExpectedJson("_MISSING-ENTITY_ not found", "rdap_error_404.json"));
assertThat(response.getStatus()).isEqualTo(404); assertThat(response.getStatus()).isEqualTo(404);
} }

View file

@ -72,6 +72,14 @@ public class RdapSearchPatternTest {
RdapSearchPattern.create("ex*am.lol", true); RdapSearchPattern.create("ex*am.lol", true);
} }
@Test
public void testShortString_ok() throws Exception {
RdapSearchPattern rdapSearchPattern = RdapSearchPattern.create("e", true);
assertThat(rdapSearchPattern.getInitialString()).isEqualTo("e");
assertThat(rdapSearchPattern.getHasWildcard()).isFalse();
assertThat(rdapSearchPattern.getSuffix()).isNull();
}
@Test @Test
public void testPrefixTooShort_unprocessable() throws Exception { public void testPrefixTooShort_unprocessable() throws Exception {
thrown.expect(UnprocessableEntityException.class); thrown.expect(UnprocessableEntityException.class);