mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
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:
parent
861fd60d2c
commit
f1ad34b12f
5 changed files with 24 additions and 14 deletions
|
@ -49,7 +49,7 @@ public class RdapEntityAction extends RdapActionBase {
|
|||
|
||||
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 RdapEntityAction() {}
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.rdap;
|
|||
|
||||
import static com.google.common.base.Strings.nullToEmpty;
|
||||
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.common.base.Function;
|
||||
|
@ -1054,6 +1055,7 @@ public class RdapJsonFormatter {
|
|||
}
|
||||
|
||||
private static boolean hasUnicodeComponents(String fullyQualifiedName) {
|
||||
return fullyQualifiedName.startsWith("xn--") || fullyQualifiedName.contains(".xn--");
|
||||
return fullyQualifiedName.startsWith(ACE_PREFIX)
|
||||
|| fullyQualifiedName.contains("." + ACE_PREFIX);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
package google.registry.rdap;
|
||||
|
||||
import static google.registry.util.DomainNameUtils.ACE_PREFIX;
|
||||
|
||||
import google.registry.request.HttpException.UnprocessableEntityException;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -82,8 +84,7 @@ public final class RdapSearchPattern {
|
|||
* @throws UnprocessableEntityException if {@code pattern} does not meet the requirements of RFC
|
||||
* 7482
|
||||
*/
|
||||
public static RdapSearchPattern create(
|
||||
String pattern, boolean allowSuffix) throws UnprocessableEntityException {
|
||||
public static RdapSearchPattern create(String pattern, boolean allowSuffix) {
|
||||
String initialString;
|
||||
boolean hasWildcard;
|
||||
String suffix;
|
||||
|
@ -112,15 +113,14 @@ public final class RdapSearchPattern {
|
|||
suffix = null;
|
||||
}
|
||||
initialString = pattern.substring(0, wildcardPos);
|
||||
}
|
||||
if (initialString.length() < 2) {
|
||||
throw new UnprocessableEntityException("At least two characters must be specified");
|
||||
}
|
||||
if (initialString.startsWith("xn--")
|
||||
&& (initialString.length() < 7)) {
|
||||
if (initialString.startsWith(ACE_PREFIX) && (initialString.length() < 7)) {
|
||||
throw new UnprocessableEntityException(
|
||||
"At least seven characters must be specified for punycode domain searches");
|
||||
}
|
||||
}
|
||||
return new RdapSearchPattern(initialString, hasWildcard, suffix);
|
||||
}
|
||||
|
||||
|
|
|
@ -202,8 +202,8 @@ public class RdapEntityActionTest {
|
|||
|
||||
@Test
|
||||
public void testUnknownEntity_returns404() throws Exception {
|
||||
assertThat(generateActualJson("MISSING-ENTITY")).isEqualTo(
|
||||
generateExpectedJson("MISSING-ENTITY not found", "rdap_error_404.json"));
|
||||
assertThat(generateActualJson("_MISSING-ENTITY_")).isEqualTo(
|
||||
generateExpectedJson("_MISSING-ENTITY_ not found", "rdap_error_404.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,14 @@ public class RdapSearchPatternTest {
|
|||
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
|
||||
public void testPrefixTooShort_unprocessable() throws Exception {
|
||||
thrown.expect(UnprocessableEntityException.class);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue