RDAP: Display truncation notice for large entity result sets

The ICAAN Operational Profile dictates that a notice be added to the RDAP search results response when there are more objects than the server's chosen result set size. This CL (hopefully the last one) handles the fixes for entity (contact and registrar) searches.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135494283
This commit is contained in:
mountford 2016-07-24 11:02:45 -04:00 committed by Ben McIlwain
parent 49fd75300e
commit b224a90a4c
10 changed files with 1354 additions and 29 deletions

View file

@ -17,6 +17,7 @@ package google.registry.rdap;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistResources;
import static google.registry.testing.DatastoreHelper.persistSimpleResources;
import static google.registry.testing.FullFieldsTestEntityHelper.makeAndPersistContactResource;
import static google.registry.testing.FullFieldsTestEntityHelper.makeContactResource;
@ -27,6 +28,7 @@ import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import google.registry.model.ImmutableObject;
import google.registry.model.contact.ContactResource;
import google.registry.model.ofy.Ofy;
import google.registry.model.registrar.Registrar;
@ -34,6 +36,8 @@ import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import google.registry.testing.InjectRule;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.json.simple.JSONValue;
@ -120,7 +124,7 @@ public class RdapEntitySearchActionTest {
action.clock = clock;
action.requestPath = RdapEntitySearchAction.PATH;
action.response = response;
action.rdapResultSetMaxSize = 100;
action.rdapResultSetMaxSize = 4;
action.rdapLinkBase = "https://example.com/rdap/";
action.rdapWhoisServer = null;
action.fnParam = Optional.absent();
@ -177,6 +181,38 @@ public class RdapEntitySearchActionTest {
return builder.build();
}
private void createManyContactsAndRegistrars(int numContacts, int numRegistrars) {
ImmutableList.Builder<ImmutableObject> resourcesBuilder = new ImmutableList.Builder<>();
for (int i = 1; i <= numContacts; i++) {
resourcesBuilder.add(makeContactResource(
String.format("contact%d", i),
String.format("Entity %d", i),
String.format("contact%d@gmail.com", i)));
}
persistResources(resourcesBuilder.build());
for (int i = 1; i <= numRegistrars; i++) {
resourcesBuilder.add(
makeRegistrar(
String.format("registrar%d", i),
String.format("Entity %d", i + numContacts),
Registrar.State.ACTIVE,
300L + i));
}
persistResources(resourcesBuilder.build());
}
private void checkNumberOfEntitiesInResult(Object obj, int expected) {
assertThat(obj).isInstanceOf(Map.class);
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) obj;
@SuppressWarnings("unchecked")
List<Object> domains = (List<Object>) map.get("entitySearchResults");
assertThat(domains).hasSize(expected);
}
@Test
public void testInvalidPath_rejected() throws Exception {
action.requestPath = RdapEntitySearchAction.PATH + "/path";
@ -274,6 +310,62 @@ public class RdapEntitySearchActionTest {
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testNameMatch_nonTruncatedContacts() throws Exception {
createManyContactsAndRegistrars(4, 0);
assertThat(generateActualJsonWithFullName("Entity *"))
.isEqualTo(generateExpectedJson("rdap_nontruncated_contacts.json"));
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testNameMatch_truncatedContacts() throws Exception {
createManyContactsAndRegistrars(5, 0);
assertThat(generateActualJsonWithFullName("Entity *"))
.isEqualTo(generateExpectedJson("rdap_truncated_contacts.json"));
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testNameMatch_reallyTruncatedContacts() throws Exception {
createManyContactsAndRegistrars(9, 0);
assertThat(generateActualJsonWithFullName("Entity *"))
.isEqualTo(generateExpectedJson("rdap_truncated_contacts.json"));
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testNameMatch_nonTruncatedRegistrars() throws Exception {
createManyContactsAndRegistrars(0, 4);
assertThat(generateActualJsonWithFullName("Entity *"))
.isEqualTo(generateExpectedJson("rdap_nontruncated_registrars.json"));
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testNameMatch_truncatedRegistrars() throws Exception {
createManyContactsAndRegistrars(0, 5);
assertThat(generateActualJsonWithFullName("Entity *"))
.isEqualTo(generateExpectedJson("rdap_truncated_registrars.json"));
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testNameMatch_reallyTruncatedRegistrars() throws Exception {
createManyContactsAndRegistrars(0, 9);
assertThat(generateActualJsonWithFullName("Entity *"))
.isEqualTo(generateExpectedJson("rdap_truncated_registrars.json"));
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testNameMatch_truncatedMixOfContactsAndRegistrars() throws Exception {
createManyContactsAndRegistrars(3, 3);
assertThat(generateActualJsonWithFullName("Entity *"))
.isEqualTo(generateExpectedJson("rdap_truncated_mixed_entities.json"));
assertThat(response.getStatus()).isEqualTo(200);
}
@Test
public void testHandleMatch_2roid_found() throws Exception {
assertThat(generateActualJsonWithHandle("2-ROID"))
@ -352,4 +444,12 @@ public class RdapEntitySearchActionTest {
generateActualJsonWithHandle("3test*");
assertThat(response.getStatus()).isEqualTo(404);
}
@Test
public void testHandleMatch_truncatedEntities() throws Exception {
createManyContactsAndRegistrars(300, 0);
Object obj = generateActualJsonWithHandle("10*");
assertThat(response.getStatus()).isEqualTo(200);
checkNumberOfEntitiesInResult(obj, 4);
}
}