Add SQL queries to RdapNameserverSearchAction (#987)

This has the same issue as the domain-search action where the database
ordering is not consistent between Objectify and SQL -- as a result,
there is one test that we have to duplicate in order to account for the
two sort orders.

In addition, there isn't a way to query @Convert-ed fields in Postgres
via the standard Hibernate / JPA query language, meaning we have to use
a raw Postgres query for that.
This commit is contained in:
gbrodman 2021-03-22 12:33:11 -04:00 committed by GitHub
parent 0b6a5aec96
commit 67d767bd68
5 changed files with 198 additions and 114 deletions

View file

@ -211,6 +211,7 @@ PRESUBMITS = {
# CriteriaQueryBuilder is a false positive # CriteriaQueryBuilder is a false positive
"CriteriaQueryBuilder.java", "CriteriaQueryBuilder.java",
"RdapDomainSearchAction.java", "RdapDomainSearchAction.java",
"RdapNameserverSearchAction.java",
"RdapSearchActionBase.java", "RdapSearchActionBase.java",
}, },
): ):

View file

@ -26,6 +26,7 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -489,40 +490,33 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
.map(VKey::from) .map(VKey::from)
.collect(toImmutableSet()); .collect(toImmutableSet());
} else { } else {
// Hibernate does not allow us to query @Converted array fields directly, either
// in the CriteriaQuery or the raw text format. However, Postgres does -- so we
// use native queries to find hosts where any of the inetAddresses match.
StringBuilder queryBuilder =
new StringBuilder(
"SELECT h.repo_id FROM \"Host\" h WHERE :address = ANY(h.inet_addresses) AND "
+ "h.deletion_time = CAST(:endOfTime AS timestamptz)");
ImmutableMap.Builder<String, String> parameters =
new ImmutableMap.Builder<String, String>()
.put("address", InetAddresses.toAddrString(inetAddress))
.put("endOfTime", END_OF_TIME.toString());
if (desiredRegistrar.isPresent()) {
queryBuilder.append(" AND h.current_sponsor_registrar_id = :desiredRegistrar");
parameters.put("desiredRegistrar", desiredRegistrar.get());
}
hostKeys = hostKeys =
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {
// Hibernate does not allow us to query @Converted array fields directly, either javax.persistence.Query query =
// in the CriteriaQuery or the raw text format. However, Postgres does -- so we
// use native queries to find hosts where any of the inetAddresses match.
javax.persistence.Query query;
if (desiredRegistrar.isPresent()) {
query =
jpaTm() jpaTm()
.getEntityManager() .getEntityManager()
.createNativeQuery( .createNativeQuery(queryBuilder.toString())
"SELECT h.repo_id FROM \"Host\" h WHERE :address = " .setMaxResults(maxNameserversInFirstStage);
+ "ANY(h.inet_addresses) AND " parameters.build().forEach(query::setParameter);
+ "h.current_sponsor_registrar_id = :desiredRegistrar AND "
+ "h.deletion_time = CAST(:endOfTime AS timestamptz)")
.setParameter("desiredRegistrar", desiredRegistrar.get());
} else {
query =
jpaTm()
.getEntityManager()
.createNativeQuery(
"SELECT h.repo_id FROM \"Host\" h WHERE :address = "
+ "ANY(h.inet_addresses) AND "
+ "h.deletion_time = CAST(:endOfTime AS timestamptz)");
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Stream<String> resultStream = Stream<String> resultStream = query.getResultStream();
query
.setParameter("address", InetAddresses.toAddrString(inetAddress))
.setParameter("endOfTime", END_OF_TIME.toString())
.setMaxResults(maxNameserversInFirstStage)
.getResultStream();
return resultStream return resultStream
.map(repoId -> VKey.create(HostResource.class, repoId)) .map(repoId -> VKey.create(HostResource.class, repoId))
.collect(toImmutableSet()); .collect(toImmutableSet());

View file

@ -15,9 +15,12 @@
package google.registry.rdap; package google.registry.rdap;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.request.Action.Method.GET; import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.HEAD; import static google.registry.request.Action.Method.HEAD;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
@ -25,6 +28,7 @@ import com.google.common.primitives.Booleans;
import com.googlecode.objectify.cmd.Query; import com.googlecode.objectify.cmd.Query;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.persistence.transaction.CriteriaQueryBuilder;
import google.registry.rdap.RdapJsonFormatter.OutputDataType; import google.registry.rdap.RdapJsonFormatter.OutputDataType;
import google.registry.rdap.RdapMetrics.EndpointType; import google.registry.rdap.RdapMetrics.EndpointType;
import google.registry.rdap.RdapMetrics.SearchType; import google.registry.rdap.RdapMetrics.SearchType;
@ -216,6 +220,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
private NameserverSearchResponse searchByNameUsingPrefix(RdapSearchPattern partialStringQuery) { private NameserverSearchResponse searchByNameUsingPrefix(RdapSearchPattern partialStringQuery) {
// Add 1 so we can detect truncation. // Add 1 so we can detect truncation.
int querySizeLimit = getStandardQuerySizeLimit(); int querySizeLimit = getStandardQuerySizeLimit();
if (isDatastore()) {
Query<HostResource> query = Query<HostResource> query =
queryItems( queryItems(
HostResource.class, HostResource.class,
@ -226,12 +231,30 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
querySizeLimit); querySizeLimit);
return makeSearchResults( return makeSearchResults(
getMatchingResources(query, shouldIncludeDeleted(), querySizeLimit), CursorType.NAME); getMatchingResources(query, shouldIncludeDeleted(), querySizeLimit), CursorType.NAME);
} else {
return jpaTm()
.transact(
() -> {
CriteriaQueryBuilder<HostResource> queryBuilder =
queryItemsSql(
HostResource.class,
"fullyQualifiedHostName",
partialStringQuery,
cursorString,
getDeletedItemHandling());
return makeSearchResults(
getMatchingResourcesSql(queryBuilder, shouldIncludeDeleted(), querySizeLimit),
CursorType.NAME);
});
}
} }
/** Searches for nameservers by IP address, returning a JSON array of nameserver info maps. */ /** Searches for nameservers by IP address, returning a JSON array of nameserver info maps. */
private NameserverSearchResponse searchByIp(InetAddress inetAddress) { private NameserverSearchResponse searchByIp(InetAddress inetAddress) {
// Add 1 so we can detect truncation. // Add 1 so we can detect truncation.
int querySizeLimit = getStandardQuerySizeLimit(); int querySizeLimit = getStandardQuerySizeLimit();
RdapResultSet<HostResource> rdapResultSet;
if (isDatastore()) {
Query<HostResource> query = Query<HostResource> query =
queryItems( queryItems(
HostResource.class, HostResource.class,
@ -241,8 +264,46 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
cursorString, cursorString,
getDeletedItemHandling(), getDeletedItemHandling(),
querySizeLimit); querySizeLimit);
return makeSearchResults( rdapResultSet = getMatchingResources(query, shouldIncludeDeleted(), querySizeLimit);
getMatchingResources(query, shouldIncludeDeleted(), querySizeLimit), CursorType.ADDRESS); } else {
// Hibernate does not allow us to query @Converted array fields directly, either in the
// CriteriaQuery or the raw text format. However, Postgres does -- so we use native queries to
// find hosts where any of the inetAddresses match.
StringBuilder queryBuilder =
new StringBuilder("SELECT * FROM \"Host\" WHERE :address = ANY(inet_addresses)");
ImmutableMap.Builder<String, String> parameters =
new ImmutableMap.Builder<String, String>()
.put("address", InetAddresses.toAddrString(inetAddress));
if (getDeletedItemHandling().equals(DeletedItemHandling.EXCLUDE)) {
queryBuilder.append(" AND deletion_time = CAST(:endOfTime AS timestamptz)");
parameters.put("endOfTime", END_OF_TIME.toString());
}
if (cursorString.isPresent()) {
// cursorString here must be the repo ID
queryBuilder.append(" AND repo_id > :repoId");
parameters.put("repoId", cursorString.get());
}
if (getDesiredRegistrar().isPresent()) {
queryBuilder.append(" AND current_sponsor_registrar_id = :desiredRegistrar");
parameters.put("desiredRegistrar", getDesiredRegistrar().get());
}
queryBuilder.append(" ORDER BY repo_id ASC");
rdapResultSet =
jpaTm()
.transact(
() -> {
javax.persistence.Query query =
jpaTm()
.getEntityManager()
.createNativeQuery(queryBuilder.toString(), HostResource.class)
.setMaxResults(querySizeLimit);
parameters.build().forEach(query::setParameter);
@SuppressWarnings("unchecked")
List<HostResource> resultList = query.getResultList();
return filterResourcesByVisibility(resultList, querySizeLimit);
});
}
return makeSearchResults(rdapResultSet, CursorType.ADDRESS);
} }
/** Output JSON for a lists of hosts contained in an {@link RdapResultSet}. */ /** Output JSON for a lists of hosts contained in an {@link RdapResultSet}. */

View file

@ -214,7 +214,7 @@ public abstract class RdapSearchActionBase extends RdapActionBase {
} }
} }
private <T extends EppResource> RdapResultSet<T> filterResourcesByVisibility( protected <T extends EppResource> RdapResultSet<T> filterResourcesByVisibility(
List<T> queryResult, int querySizeLimit) { List<T> queryResult, int querySizeLimit) {
// If we are including deleted resources, we need to check that we're authorized for each one. // If we are including deleted resources, we need to check that we're authorized for each one.
List<T> resources = new ArrayList<>(); List<T> resources = new ArrayList<>();

View file

@ -43,13 +43,17 @@ import google.registry.rdap.RdapMetrics.EndpointType;
import google.registry.rdap.RdapMetrics.SearchType; import google.registry.rdap.RdapMetrics.SearchType;
import google.registry.rdap.RdapMetrics.WildcardType; import google.registry.rdap.RdapMetrics.WildcardType;
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType; import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.FakeResponse; import google.registry.testing.FakeResponse;
import google.registry.testing.TestOfyAndSql;
import google.registry.testing.TestOfyOnly;
import google.registry.testing.TestSqlOnly;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.Optional; import java.util.Optional;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link RdapNameserverSearchAction}. */ /** Unit tests for {@link RdapNameserverSearchAction}. */
@DualDatabaseTest
class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNameserverSearchAction> { class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNameserverSearchAction> {
RdapNameserverSearchActionTest() { RdapNameserverSearchActionTest() {
@ -231,7 +235,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(numHostsRetrieved, IncompletenessWarningType.COMPLETE); verifyMetrics(numHostsRetrieved, IncompletenessWarningType.COMPLETE);
} }
@Test @TestOfyAndSql
void testInvalidPath_rejected() { void testInvalidPath_rejected() {
action.requestPath = actionPath + "/path"; action.requestPath = actionPath + "/path";
action.run(); action.run();
@ -239,7 +243,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.empty(), 400); verifyErrorMetrics(Optional.empty(), 400);
} }
@Test @TestOfyAndSql
void testInvalidRequest_rejected() { void testInvalidRequest_rejected() {
action.run(); action.run();
assertThat(parseJsonObject(response.getPayload())) assertThat(parseJsonObject(response.getPayload()))
@ -248,7 +252,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.empty(), 400); verifyErrorMetrics(Optional.empty(), 400);
} }
@Test @TestOfyAndSql
void testInvalidSuffix_rejected() { void testInvalidSuffix_rejected() {
assertThat(generateActualJsonWithName("exam*ple")) assertThat(generateActualJsonWithName("exam*ple"))
.isEqualTo( .isEqualTo(
@ -261,7 +265,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.empty(), 422); verifyErrorMetrics(Optional.empty(), 422);
} }
@Test @TestOfyAndSql
void testNonexistentDomainSuffix_unprocessable() { void testNonexistentDomainSuffix_unprocessable() {
assertThat(generateActualJsonWithName("exam*.foo.bar")) assertThat(generateActualJsonWithName("exam*.foo.bar"))
.isEqualTo( .isEqualTo(
@ -272,7 +276,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.empty(), 422); verifyErrorMetrics(Optional.empty(), 422);
} }
@Test @TestOfyAndSql
void testMultipleWildcards_rejected() { void testMultipleWildcards_rejected() {
assertThat(generateActualJsonWithName("*.*")) assertThat(generateActualJsonWithName("*.*"))
.isEqualTo( .isEqualTo(
@ -285,7 +289,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.empty(), 422); verifyErrorMetrics(Optional.empty(), 422);
} }
@Test @TestOfyAndSql
void testNoCharactersToMatch_rejected() { void testNoCharactersToMatch_rejected() {
assertThat(generateActualJsonWithName("*")) assertThat(generateActualJsonWithName("*"))
.isEqualTo( .isEqualTo(
@ -294,7 +298,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.empty(), 422); verifyErrorMetrics(Optional.empty(), 422);
} }
@Test @TestOfyAndSql
void testFewerThanTwoCharactersToMatch_rejected() { void testFewerThanTwoCharactersToMatch_rejected() {
assertThat(generateActualJsonWithName("a*")) assertThat(generateActualJsonWithName("a*"))
.isEqualTo( .isEqualTo(
@ -303,7 +307,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.empty(), 422); verifyErrorMetrics(Optional.empty(), 422);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat_lol_found() { void testNameMatch_ns1_cat_lol_found() {
assertThat(generateActualJsonWithName("ns1.cat.lol")) assertThat(generateActualJsonWithName("ns1.cat.lol"))
.isEqualTo( .isEqualTo(
@ -313,7 +317,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat_lol_foundWithUpperCase() { void testNameMatch_ns1_cat_lol_foundWithUpperCase() {
assertThat(generateActualJsonWithName("Ns1.CaT.lOl")) assertThat(generateActualJsonWithName("Ns1.CaT.lOl"))
.isEqualTo( .isEqualTo(
@ -323,7 +327,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat_lol_found_sameRegistrarRequested() { void testNameMatch_ns1_cat_lol_found_sameRegistrarRequested() {
action.registrarParam = Optional.of("TheRegistrar"); action.registrarParam = Optional.of("TheRegistrar");
generateActualJsonWithName("ns1.cat.lol"); generateActualJsonWithName("ns1.cat.lol");
@ -331,7 +335,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat_lol_notFound_differentRegistrarRequested() { void testNameMatch_ns1_cat_lol_notFound_differentRegistrarRequested() {
action.registrarParam = Optional.of("unicoderegistrar"); action.registrarParam = Optional.of("unicoderegistrar");
generateActualJsonWithName("ns1.cat.lol"); generateActualJsonWithName("ns1.cat.lol");
@ -339,7 +343,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.of(1L), 404); verifyErrorMetrics(Optional.of(1L), 404);
} }
@Test @TestOfyAndSql
void testNameMatch_ns2_cat_lol_found() { void testNameMatch_ns2_cat_lol_found() {
assertThat(generateActualJsonWithName("ns2.cat.lol")) assertThat(generateActualJsonWithName("ns2.cat.lol"))
.isEqualTo( .isEqualTo(
@ -354,7 +358,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat2_lol_found() { void testNameMatch_ns1_cat2_lol_found() {
// ns1.cat2.lol has two IP addresses; just test that we are able to find it // ns1.cat2.lol has two IP addresses; just test that we are able to find it
generateActualJsonWithName("ns1.cat2.lol"); generateActualJsonWithName("ns1.cat2.lol");
@ -362,7 +366,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat_external_found() { void testNameMatch_ns1_cat_external_found() {
assertThat(generateActualJsonWithName("ns1.cat.external")) assertThat(generateActualJsonWithName("ns1.cat.external"))
.isEqualTo( .isEqualTo(
@ -372,7 +376,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat_idn_unicode_found() { void testNameMatch_ns1_cat_idn_unicode_found() {
assertThat(generateActualJsonWithName("ns1.cat.みんな")) assertThat(generateActualJsonWithName("ns1.cat.みんな"))
.isEqualTo( .isEqualTo(
@ -389,7 +393,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat_idn_punycode_found() { void testNameMatch_ns1_cat_idn_punycode_found() {
assertThat(generateActualJsonWithName("ns1.cat.xn--q9jyb4c")) assertThat(generateActualJsonWithName("ns1.cat.xn--q9jyb4c"))
.isEqualTo( .isEqualTo(
@ -404,7 +408,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat_1_test_found() { void testNameMatch_ns1_cat_1_test_found() {
assertThat(generateActualJsonWithName("ns1.cat.1.test")) assertThat(generateActualJsonWithName("ns1.cat.1.test"))
.isEqualTo( .isEqualTo(
@ -414,14 +418,14 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_nsstar_cat_lol_found() { void testNameMatch_nsstar_cat_lol_found() {
generateActualJsonWithName("ns*.cat.lol"); generateActualJsonWithName("ns*.cat.lol");
assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getStatus()).isEqualTo(200);
verifyMetrics(2); verifyMetrics(2);
} }
@Test @TestOfyAndSql
void testNameMatch_nsstar_cat_lol_found_sameRegistrarRequested() { void testNameMatch_nsstar_cat_lol_found_sameRegistrarRequested() {
action.registrarParam = Optional.of("TheRegistrar"); action.registrarParam = Optional.of("TheRegistrar");
generateActualJsonWithName("ns*.cat.lol"); generateActualJsonWithName("ns*.cat.lol");
@ -429,7 +433,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(2); verifyMetrics(2);
} }
@Test @TestOfyAndSql
void testNameMatch_nsstar_cat_lol_notFound_differentRegistrarRequested() { void testNameMatch_nsstar_cat_lol_notFound_differentRegistrarRequested() {
action.registrarParam = Optional.of("unicoderegistrar"); action.registrarParam = Optional.of("unicoderegistrar");
generateActualJsonWithName("ns*.cat.lol"); generateActualJsonWithName("ns*.cat.lol");
@ -437,21 +441,21 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.of(2L), 404); verifyErrorMetrics(Optional.of(2L), 404);
} }
@Test @TestOfyAndSql
void testNameMatch_nstar_cat_lol_found() { void testNameMatch_nstar_cat_lol_found() {
generateActualJsonWithName("n*.cat.lol"); generateActualJsonWithName("n*.cat.lol");
assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getStatus()).isEqualTo(200);
verifyMetrics(2); verifyMetrics(2);
} }
@Test @TestOfyAndSql
void testNameMatch_star_cat_lol_found() { void testNameMatch_star_cat_lol_found() {
generateActualJsonWithName("*.cat.lol"); generateActualJsonWithName("*.cat.lol");
assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getStatus()).isEqualTo(200);
verifyMetrics(2); verifyMetrics(2);
} }
@Test @TestOfyAndSql
void testNameMatch_star_cat_lol_found_sameRegistrarRequested() { void testNameMatch_star_cat_lol_found_sameRegistrarRequested() {
action.registrarParam = Optional.of("TheRegistrar"); action.registrarParam = Optional.of("TheRegistrar");
generateActualJsonWithName("*.cat.lol"); generateActualJsonWithName("*.cat.lol");
@ -459,7 +463,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(2); verifyMetrics(2);
} }
@Test @TestOfyAndSql
void testNameMatch_star_cat_lol_notFound_differentRegistrarRequested() { void testNameMatch_star_cat_lol_notFound_differentRegistrarRequested() {
action.registrarParam = Optional.of("unicoderegistrar"); action.registrarParam = Optional.of("unicoderegistrar");
generateActualJsonWithName("*.cat.lol"); generateActualJsonWithName("*.cat.lol");
@ -467,35 +471,35 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.of(2L), 404); verifyErrorMetrics(Optional.of(2L), 404);
} }
@Test @TestOfyAndSql
void testNameMatch_nsstar_found() { void testNameMatch_nsstar_found() {
generateActualJsonWithName("ns*"); generateActualJsonWithName("ns*");
assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getStatus()).isEqualTo(200);
verifyMetrics(5, IncompletenessWarningType.TRUNCATED); verifyMetrics(5, IncompletenessWarningType.TRUNCATED);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_cat_lstar_found() { void testNameMatch_ns1_cat_lstar_found() {
generateActualJsonWithName("ns1.cat.l*"); generateActualJsonWithName("ns1.cat.l*");
assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getStatus()).isEqualTo(200);
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatch_ns1_castar_found() { void testNameMatch_ns1_castar_found() {
generateActualJsonWithName("ns1.ca*"); generateActualJsonWithName("ns1.ca*");
assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getStatus()).isEqualTo(200);
verifyMetrics(5, IncompletenessWarningType.TRUNCATED); verifyMetrics(5, IncompletenessWarningType.TRUNCATED);
} }
@Test @TestOfyAndSql
void testNameMatch_dogstar_notFound() { void testNameMatch_dogstar_notFound() {
generateActualJsonWithName("dog*"); generateActualJsonWithName("dog*");
assertThat(response.getStatus()).isEqualTo(404); assertThat(response.getStatus()).isEqualTo(404);
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testNameMatch_nontruncatedResultSet() { void testNameMatch_nontruncatedResultSet() {
createManyHosts(4); createManyHosts(4);
assertThat(generateActualJsonWithName("nsx*.cat.lol")) assertThat(generateActualJsonWithName("nsx*.cat.lol"))
@ -504,7 +508,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(4); verifyMetrics(4);
} }
@Test @TestOfyAndSql
void testNameMatch_truncatedResultSet() { void testNameMatch_truncatedResultSet() {
createManyHosts(5); createManyHosts(5);
assertThat(generateActualJsonWithName("nsx*.cat.lol")) assertThat(generateActualJsonWithName("nsx*.cat.lol"))
@ -515,7 +519,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(5, IncompletenessWarningType.TRUNCATED); verifyMetrics(5, IncompletenessWarningType.TRUNCATED);
} }
@Test @TestOfyAndSql
void testNameMatch_reallyTruncatedResultSet() { void testNameMatch_reallyTruncatedResultSet() {
createManyHosts(9); createManyHosts(9);
assertThat(generateActualJsonWithName("nsx*.cat.lol")) assertThat(generateActualJsonWithName("nsx*.cat.lol"))
@ -527,7 +531,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(9, IncompletenessWarningType.TRUNCATED); verifyMetrics(9, IncompletenessWarningType.TRUNCATED);
} }
@Test @TestOfyAndSql
void testNameMatchDeletedHost_foundTheOtherHost() { void testNameMatchDeletedHost_foundTheOtherHost() {
persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
assertThat(generateActualJsonWithName("ns*.cat.lol")) assertThat(generateActualJsonWithName("ns*.cat.lol"))
@ -543,7 +547,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(2); verifyMetrics(2);
} }
@Test @TestOfyAndSql
void testNameMatchDeletedHost_notFound() { void testNameMatchDeletedHost_notFound() {
persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
assertThat(generateActualJsonWithName("ns1.cat.lol")) assertThat(generateActualJsonWithName("ns1.cat.lol"))
@ -552,7 +556,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testNameMatchDeletedHostWithWildcard_notFound() { void testNameMatchDeletedHostWithWildcard_notFound() {
persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
assertThat(generateActualJsonWithName("cat.lo*")) assertThat(generateActualJsonWithName("cat.lo*"))
@ -561,7 +565,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testNameMatchDeleted_notFound_includeDeletedNotSpecified() { void testNameMatchDeleted_notFound_includeDeletedNotSpecified() {
createDeletedHost(); createDeletedHost();
generateActualJsonWithName("nsdeleted.cat.lol"); generateActualJsonWithName("nsdeleted.cat.lol");
@ -569,7 +573,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testNameMatchDeleted_notFound_notLoggedIn() { void testNameMatchDeleted_notFound_notLoggedIn() {
createDeletedHost(); createDeletedHost();
action.includeDeletedParam = Optional.of(true); action.includeDeletedParam = Optional.of(true);
@ -578,7 +582,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testNameMatchDeleted_notFound_loggedInAsDifferentRegistrar() { void testNameMatchDeleted_notFound_loggedInAsDifferentRegistrar() {
createDeletedHost(); createDeletedHost();
action.includeDeletedParam = Optional.of(true); action.includeDeletedParam = Optional.of(true);
@ -588,7 +592,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.of(1L), 404); verifyErrorMetrics(Optional.of(1L), 404);
} }
@Test @TestOfyAndSql
void testNameMatchDeleted_found_loggedInAsCorrectRegistrar() { void testNameMatchDeleted_found_loggedInAsCorrectRegistrar() {
createDeletedHost(); createDeletedHost();
action.includeDeletedParam = Optional.of(true); action.includeDeletedParam = Optional.of(true);
@ -598,7 +602,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatchDeleted_found_loggedInAsAdmin() { void testNameMatchDeleted_found_loggedInAsAdmin() {
createDeletedHost(); createDeletedHost();
action.includeDeletedParam = Optional.of(true); action.includeDeletedParam = Optional.of(true);
@ -608,7 +612,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatchDeleted_found_loggedInAndRequestingSameRegistrar() { void testNameMatchDeleted_found_loggedInAndRequestingSameRegistrar() {
createDeletedHost(); createDeletedHost();
action.registrarParam = Optional.of("TheRegistrar"); action.registrarParam = Optional.of("TheRegistrar");
@ -619,7 +623,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testNameMatchDeleted_notFound_loggedInButRequestingDifferentRegistrar() { void testNameMatchDeleted_notFound_loggedInButRequestingDifferentRegistrar() {
createDeletedHost(); createDeletedHost();
action.registrarParam = Optional.of("unicoderegistrar"); action.registrarParam = Optional.of("unicoderegistrar");
@ -672,7 +676,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
} }
} }
@Test @TestOfyAndSql
void testNameMatch_cursorNavigationWithSuperordinateDomain() throws Exception { void testNameMatch_cursorNavigationWithSuperordinateDomain() throws Exception {
createManyHosts(9); createManyHosts(9);
checkCursorNavigation( checkCursorNavigation(
@ -690,8 +694,8 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
"nsx9.cat.lol")); "nsx9.cat.lol"));
} }
@Test @TestOfyOnly
void testNameMatch_cursorNavigationWithPrefix() throws Exception { void testNameMatch_cursorNavigationWithPrefix_ofy() throws Exception {
createManyHosts(9); createManyHosts(9);
checkCursorNavigation( checkCursorNavigation(
true, true,
@ -714,14 +718,38 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
"nsx9.cat.lol")); "nsx9.cat.lol"));
} }
@Test @TestSqlOnly
void testNameMatch_cursorNavigationWithPrefix_sql() throws Exception {
createManyHosts(9);
checkCursorNavigation(
true,
"ns*",
ImmutableList.of(
"ns1.cat.1.test",
"ns1.cat2.lol",
"ns1.cat.external",
"ns1.cat.lol",
"ns1.cat.xn--q9jyb4c",
"ns2.cat.lol",
"nsx1.cat.lol",
"nsx2.cat.lol",
"nsx3.cat.lol",
"nsx4.cat.lol",
"nsx5.cat.lol",
"nsx6.cat.lol",
"nsx7.cat.lol",
"nsx8.cat.lol",
"nsx9.cat.lol"));
}
@TestOfyAndSql
void testAddressMatch_invalidAddress() { void testAddressMatch_invalidAddress() {
generateActualJsonWithIp("It is to laugh"); generateActualJsonWithIp("It is to laugh");
assertThat(response.getStatus()).isEqualTo(400); assertThat(response.getStatus()).isEqualTo(400);
verifyErrorMetrics(Optional.empty(), 400); verifyErrorMetrics(Optional.empty(), 400);
} }
@Test @TestOfyAndSql
void testAddressMatchV4Address_found() { void testAddressMatchV4Address_found() {
assertThat(generateActualJsonWithIp("1.2.3.4")) assertThat(generateActualJsonWithIp("1.2.3.4"))
.isEqualTo( .isEqualTo(
@ -731,7 +759,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testAddressMatchV4Address_found_sameRegistrarRequested() { void testAddressMatchV4Address_found_sameRegistrarRequested() {
action.registrarParam = Optional.of("TheRegistrar"); action.registrarParam = Optional.of("TheRegistrar");
generateActualJsonWithIp("1.2.3.4"); generateActualJsonWithIp("1.2.3.4");
@ -739,7 +767,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testAddressMatchV4Address_notFound_differentRegistrarRequested() { void testAddressMatchV4Address_notFound_differentRegistrarRequested() {
action.registrarParam = Optional.of("unicoderegistrar"); action.registrarParam = Optional.of("unicoderegistrar");
generateActualJsonWithIp("1.2.3.4"); generateActualJsonWithIp("1.2.3.4");
@ -747,7 +775,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testAddressMatchV6Address_foundMultiple() { void testAddressMatchV6Address_foundMultiple() {
assertThat(generateActualJsonWithIp("bad:f00d:cafe::15:beef")) assertThat(generateActualJsonWithIp("bad:f00d:cafe::15:beef"))
.isEqualTo(loadJsonFile("rdap_multiple_hosts.json")); .isEqualTo(loadJsonFile("rdap_multiple_hosts.json"));
@ -755,14 +783,14 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(2); verifyMetrics(2);
} }
@Test @TestOfyAndSql
void testAddressMatchLocalhost_notFound() { void testAddressMatchLocalhost_notFound() {
generateActualJsonWithIp("127.0.0.1"); generateActualJsonWithIp("127.0.0.1");
assertThat(response.getStatus()).isEqualTo(404); assertThat(response.getStatus()).isEqualTo(404);
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testAddressMatchDeletedHost_notFound() { void testAddressMatchDeletedHost_notFound() {
persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
assertThat(generateActualJsonWithIp("1.2.3.4")) assertThat(generateActualJsonWithIp("1.2.3.4"))
@ -771,7 +799,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testAddressMatch_nontruncatedResultSet() { void testAddressMatch_nontruncatedResultSet() {
createManyHosts(4); createManyHosts(4);
assertThat(generateActualJsonWithIp("5.5.5.1")) assertThat(generateActualJsonWithIp("5.5.5.1"))
@ -780,7 +808,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(4); verifyMetrics(4);
} }
@Test @TestOfyAndSql
void testAddressMatch_truncatedResultSet() { void testAddressMatch_truncatedResultSet() {
createManyHosts(5); createManyHosts(5);
assertThat(generateActualJsonWithIp("5.5.5.1")) assertThat(generateActualJsonWithIp("5.5.5.1"))
@ -791,7 +819,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(5, IncompletenessWarningType.TRUNCATED); verifyMetrics(5, IncompletenessWarningType.TRUNCATED);
} }
@Test @TestOfyAndSql
void testAddressMatch_reallyTruncatedResultSet() { void testAddressMatch_reallyTruncatedResultSet() {
createManyHosts(9); createManyHosts(9);
assertThat(generateActualJsonWithIp("5.5.5.1")) assertThat(generateActualJsonWithIp("5.5.5.1"))
@ -804,7 +832,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(5, IncompletenessWarningType.TRUNCATED); verifyMetrics(5, IncompletenessWarningType.TRUNCATED);
} }
@Test @TestOfyAndSql
void testAddressMatchDeleted_notFound_includeDeletedNotSpecified() { void testAddressMatchDeleted_notFound_includeDeletedNotSpecified() {
createDeletedHost(); createDeletedHost();
generateActualJsonWithIp("4.3.2.1"); generateActualJsonWithIp("4.3.2.1");
@ -812,7 +840,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testAddressMatchDeleted_notFound_notLoggedIn() { void testAddressMatchDeleted_notFound_notLoggedIn() {
createDeletedHost(); createDeletedHost();
action.includeDeletedParam = Optional.of(true); action.includeDeletedParam = Optional.of(true);
@ -821,7 +849,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testAddressMatchDeleted_notFound_loggedInAsDifferentRegistrar() { void testAddressMatchDeleted_notFound_loggedInAsDifferentRegistrar() {
createDeletedHost(); createDeletedHost();
action.includeDeletedParam = Optional.of(true); action.includeDeletedParam = Optional.of(true);
@ -831,7 +859,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(Optional.of(1L), 404); verifyErrorMetrics(Optional.of(1L), 404);
} }
@Test @TestOfyAndSql
void testAddressMatchDeleted_found_loggedInAsCorrectRegistrar() { void testAddressMatchDeleted_found_loggedInAsCorrectRegistrar() {
createDeletedHost(); createDeletedHost();
action.includeDeletedParam = Optional.of(true); action.includeDeletedParam = Optional.of(true);
@ -841,7 +869,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testAddressMatchDeleted_found_loggedInAsAdmin() { void testAddressMatchDeleted_found_loggedInAsAdmin() {
createDeletedHost(); createDeletedHost();
action.includeDeletedParam = Optional.of(true); action.includeDeletedParam = Optional.of(true);
@ -851,7 +879,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testAddressMatchDeleted_found_loggedInAndRequestingSameRegisrar() { void testAddressMatchDeleted_found_loggedInAndRequestingSameRegisrar() {
createDeletedHost(); createDeletedHost();
action.registrarParam = Optional.of("TheRegistrar"); action.registrarParam = Optional.of("TheRegistrar");
@ -862,7 +890,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyMetrics(1); verifyMetrics(1);
} }
@Test @TestOfyAndSql
void testAddressMatchDeleted_notFound_loggedButRequestingDiffentRegistrar() { void testAddressMatchDeleted_notFound_loggedButRequestingDiffentRegistrar() {
createDeletedHost(); createDeletedHost();
action.registrarParam = Optional.of("unicoderegistrar"); action.registrarParam = Optional.of("unicoderegistrar");
@ -873,7 +901,7 @@ class RdapNameserverSearchActionTest extends RdapSearchActionTestCase<RdapNamese
verifyErrorMetrics(); verifyErrorMetrics();
} }
@Test @TestOfyAndSql
void testAddressMatch_cursorNavigation() throws Exception { void testAddressMatch_cursorNavigation() throws Exception {
createManyHosts(9); createManyHosts(9);
checkCursorNavigation( checkCursorNavigation(