RDAP: Allow domain and nameserver queries with no initial string under certain circumstances

Up to now, our search wildcard rules have been that there must be an initial string of at least two characters. If a wildcard is present after that, it can optionally be followed by a suffix specifying the TLD (for domains) or domain (for nameservers). So domain queries can look like:

example.tld
ex*
ex*.tld

and nameserver queries can look like:

ns1.example.tld
ns*.example.tld
ns*

But you can't do a domain query for *.tld, nor a nameserver query for *.example.tld. It would be nice to support such queries, and the presence of a valid TLD or domain makes them relatively efficient. This CL relaxes the restrictions to allow wildcards with no initial string if the suffix is present. For nameservers, the suffix must be a valid domain in the system, to avoid having to loop through all nameservers.

A side effect of the changes is to fix a shortcoming in the logic which caused wildcard nameserver searches to fail if the specified domain suffix referred to an external domain.

Entity searches are not affected, since they do not support suffixes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159856563
This commit is contained in:
mountford 2017-06-22 11:55:24 -07:00 committed by Ben McIlwain
parent 4b2e587480
commit 5a31be12ba
9 changed files with 278 additions and 94 deletions

View file

@ -136,9 +136,17 @@ public class RdapEntitySearchAction extends RdapActionBase {
* assume that entity names are regular unicode.
*/
private RdapSearchResults searchByName(final RdapSearchPattern partialStringQuery, DateTime now) {
// Don't allow suffixes in entity name search queries.
if (!partialStringQuery.getHasWildcard() && (partialStringQuery.getSuffix() != null)) {
throw new UnprocessableEntityException("Suffixes not allowed in entity name searches");
// For wildcard searches, make sure the initial string is long enough, and don't allow suffixes.
if (partialStringQuery.getHasWildcard()) {
if (partialStringQuery.getSuffix() != null) {
throw new UnprocessableEntityException(
"Suffixes not allowed in wildcard entity name searches");
}
if (partialStringQuery.getInitialString().length()
< RdapSearchPattern.MIN_INITIAL_STRING_LENGTH) {
throw new UnprocessableEntityException(
"Initial search string required in wildcard entity name searches");
}
}
// Get the registrar matches, depending on whether there's a wildcard.
ImmutableList<Registrar> registrarMatches =
@ -183,6 +191,11 @@ public class RdapEntitySearchAction extends RdapActionBase {
// wildcard searches for registrars, by simply not searching for registrars if a wildcard is
// present. Fetch an extra contact to detect result set truncation.
} else if (partialStringQuery.getSuffix() == null) {
if (partialStringQuery.getInitialString().length()
< RdapSearchPattern.MIN_INITIAL_STRING_LENGTH) {
throw new UnprocessableEntityException(
"Initial search string required in wildcard entity handle searches");
}
return makeSearchResults(
ofy().load()
.type(ContactResource.class)