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

@ -380,11 +380,29 @@ public class RdapDomainSearchActionTest {
assertThat(response.getStatus()).isEqualTo(422);
}
@Test
public void testNoCharactersToMatch_rejected() throws Exception {
assertThat(generateActualJson(RequestType.NAME, "*"))
.isEqualTo(
generateExpectedJson(
"Initial search string is required for wildcard domain searches without a TLD"
+ " suffix",
null,
null,
"rdap_error_422.json"));
assertThat(response.getStatus()).isEqualTo(422);
}
@Test
public void testFewerThanTwoCharactersToMatch_rejected() throws Exception {
assertThat(generateActualJson(RequestType.NAME, "a*"))
.isEqualTo(generateExpectedJson(
"At least two characters must be specified", null, null, "rdap_error_422.json"));
.isEqualTo(
generateExpectedJson(
"Initial search string must be at least 2 characters for wildcard domain searches"
+ " without a TLD suffix",
null,
null,
"rdap_error_422.json"));
assertThat(response.getStatus()).isEqualTo(422);
}
@ -454,6 +472,18 @@ public class RdapDomainSearchActionTest {
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testDomainMatch_cstar_lol_found() throws Exception {
generateActualJson(RequestType.NAME, "c*.lol");
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testDomainMatch_star_lol_found() throws Exception {
generateActualJson(RequestType.NAME, "*.lol");
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testDomainMatch_cat_star_found() throws Exception {
generateActualJson(RequestType.NAME, "cat.*");
@ -511,7 +541,7 @@ public class RdapDomainSearchActionTest {
assertThat(response.getStatus()).isEqualTo(404);
}
// todo (b/27378695): reenable or delete this test
// TODO(b/27378695): reenable or delete this test
@Ignore
@Test
public void testDomainMatchDomainInTestTld_notFound() throws Exception {
@ -714,7 +744,23 @@ public class RdapDomainSearchActionTest {
}
@Test
public void testNameserverMatchWithWildcardAndDomainSuffix_found() throws Exception {
public void testNameserverMatchWithNoPrefixWildcardAndDomainSuffix_found() throws Exception {
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "*.cat.lol"))
.isEqualTo(generateExpectedJson("rdap_multiple_domains.json"));
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testNameserverMatchWithOneCharacterPrefixWildcardAndDomainSuffix_found()
throws Exception {
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "n*.cat.lol"))
.isEqualTo(generateExpectedJson("rdap_multiple_domains.json"));
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testNameserverMatchWithTwoCharacterPrefixWildcardAndDomainSuffix_found()
throws Exception {
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "ns*.cat.lol"))
.isEqualTo(generateExpectedJson("rdap_multiple_domains.json"));
assertThat(response.getStatus()).isEqualTo(200);
@ -828,7 +874,7 @@ public class RdapDomainSearchActionTest {
hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "ns1.cat*.lol"))
.isEqualTo(generateExpectedJson(
"No domain found for specified nameserver suffix", null, null, "rdap_error_404.json"));
"No matching nameservers found", null, null, "rdap_error_404.json"));
assertThat(response.getStatus()).isEqualTo(404);
}