mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Add RDAP search support for only contacts or only registrars
By default, RDAP entity searches return both contacts and registrars. This CL adds a new query parameter to request only one or the other. Among other benefits, this will allow a future CL to permit wildcard searches that return all registrars. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=181605990
This commit is contained in:
parent
e07d011bc6
commit
716ba726fc
4 changed files with 253 additions and 47 deletions
|
@ -26,6 +26,7 @@ import static google.registry.testing.DatastoreHelper.persistSimpleResources;
|
|||
import static google.registry.testing.FullFieldsTestEntityHelper.makeAndPersistContactResource;
|
||||
import static google.registry.testing.FullFieldsTestEntityHelper.makeAndPersistDeletedContactResource;
|
||||
import static google.registry.testing.FullFieldsTestEntityHelper.makeContactResource;
|
||||
import static google.registry.testing.FullFieldsTestEntityHelper.makeHistoryEntry;
|
||||
import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrar;
|
||||
import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrarContacts;
|
||||
import static google.registry.testing.TestDataHelper.loadFile;
|
||||
|
@ -40,6 +41,7 @@ import google.registry.model.ImmutableObject;
|
|||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.rdap.RdapMetrics.EndpointType;
|
||||
import google.registry.rdap.RdapMetrics.SearchType;
|
||||
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
|
||||
|
@ -192,6 +194,7 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase {
|
|||
action.rdapWhoisServer = null;
|
||||
action.fnParam = Optional.empty();
|
||||
action.handleParam = Optional.empty();
|
||||
action.subtypeParam = Optional.empty();
|
||||
action.registrarParam = Optional.empty();
|
||||
action.includeDeletedParam = Optional.empty();
|
||||
action.formatOutputParam = Optional.empty();
|
||||
|
@ -281,16 +284,20 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase {
|
|||
.asBuilder()
|
||||
.setRepoId(String.format("%04d-ROID", i))
|
||||
.build();
|
||||
resourcesBuilder.add(makeHistoryEntry(
|
||||
contact, HistoryEntry.Type.CONTACT_CREATE, null, "created", clock.nowUtc()));
|
||||
resourcesBuilder.add(contact);
|
||||
}
|
||||
persistResources(resourcesBuilder.build());
|
||||
for (int i = 1; i <= numRegistrars; i++) {
|
||||
resourcesBuilder.add(
|
||||
Registrar registrar =
|
||||
makeRegistrar(
|
||||
String.format("registrar%d", i),
|
||||
String.format("Entity %d", i + numContacts),
|
||||
Registrar.State.ACTIVE,
|
||||
300L + i));
|
||||
300L + i);
|
||||
resourcesBuilder.add(registrar);
|
||||
resourcesBuilder.addAll(makeRegistrarContacts(registrar));
|
||||
}
|
||||
persistResources(resourcesBuilder.build());
|
||||
}
|
||||
|
@ -537,6 +544,19 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase {
|
|||
verifyErrorMetrics(Optional.empty(), 422);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidSubtype_rejected() throws Exception {
|
||||
action.subtypeParam = Optional.of("Space Aliens");
|
||||
assertThat(generateActualJsonWithFullName("Blinky (赤ベイ)"))
|
||||
.isEqualTo(
|
||||
generateExpectedJson(
|
||||
"Subtype parameter must specify contacts, registrars or all",
|
||||
"rdap_error_400.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(400);
|
||||
metricSearchType = SearchType.NONE; // Error occurs before search type is set.
|
||||
verifyErrorMetrics(Optional.empty(), 400);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchContact_found() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
|
@ -544,6 +564,30 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase {
|
|||
verifyMetrics(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchContact_found_subtypeAll() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("aLl");
|
||||
runSuccessfulNameTestWithBlinky("Blinky (赤ベイ)", "rdap_contact.json");
|
||||
verifyMetrics(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchContact_found_subtypeContacts() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("cONTACTS");
|
||||
runSuccessfulNameTestWithBlinky("Blinky (赤ベイ)", "rdap_contact.json");
|
||||
verifyMetrics(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchContact_notFound_subtypeRegistrars() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("Registrars");
|
||||
runNotFoundNameTest("Blinky (赤ベイ)");
|
||||
verifyErrorMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchContact_found_specifyingSameRegistrar() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
|
@ -653,6 +697,32 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase {
|
|||
verifyMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchRegistrar_found_subtypeAll() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("all");
|
||||
runSuccessfulNameTest(
|
||||
"Yes Virginia <script>", "20", "Yes Virginia <script>", "rdap_registrar.json");
|
||||
verifyMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchRegistrar_found_subtypeRegistrars() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("REGISTRARS");
|
||||
runSuccessfulNameTest(
|
||||
"Yes Virginia <script>", "20", "Yes Virginia <script>", "rdap_registrar.json");
|
||||
verifyMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchRegistrar_notFound_subtypeContacts() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("contacts");
|
||||
runNotFoundNameTest("Yes Virginia <script>");
|
||||
verifyErrorMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchRegistrar_found_specifyingSameRegistrar() throws Exception {
|
||||
action.registrarParam = Optional.of("2-Registrar");
|
||||
|
@ -810,6 +880,28 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase {
|
|||
"Entity 6"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchMix_subtypeContacts() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("contacts");
|
||||
createManyContactsAndRegistrars(4, 4, registrarTest);
|
||||
rememberWildcardType("Entity *");
|
||||
assertThat(generateActualJsonWithFullName("Entity *"))
|
||||
.isEqualTo(generateExpectedJson("rdap_nontruncated_contacts.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
verifyMetrics(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchMix_subtypeRegistrars() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("registrars");
|
||||
createManyContactsAndRegistrars(1, 1, registrarTest);
|
||||
runSuccessfulNameTest(
|
||||
"Entity *", "301", "Entity 2", "rdap_registrar.json");
|
||||
verifyMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameMatchRegistrar_notFound_inactive() throws Exception {
|
||||
runNotFoundNameTest("No Way");
|
||||
|
@ -879,6 +971,30 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase {
|
|||
verifyMetrics(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleMatchContact_found_subtypeAll() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("all");
|
||||
runSuccessfulHandleTestWithBlinky("2-ROID", "rdap_contact.json");
|
||||
verifyMetrics(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleMatchContact_found_subtypeContacts() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("contacts");
|
||||
runSuccessfulHandleTestWithBlinky("2-ROID", "rdap_contact.json");
|
||||
verifyMetrics(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleMatchContact_notFound_subtypeRegistrars() throws Exception {
|
||||
login("2-RegistrarTest");
|
||||
action.subtypeParam = Optional.of("reGistrars");
|
||||
runNotFoundHandleTest("2-ROID");
|
||||
verifyErrorMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleMatchContact_found_specifyingSameRegistrar() throws Exception {
|
||||
action.registrarParam = Optional.of("2-RegistrarTest");
|
||||
|
@ -992,6 +1108,27 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase {
|
|||
verifyMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleMatchRegistrar_found_subtypeAll() throws Exception {
|
||||
action.subtypeParam = Optional.of("all");
|
||||
runSuccessfulHandleTest("20", "20", "Yes Virginia <script>", "rdap_registrar.json");
|
||||
verifyMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleMatchRegistrar_found_subtypeRegistrars() throws Exception {
|
||||
action.subtypeParam = Optional.of("registrars");
|
||||
runSuccessfulHandleTest("20", "20", "Yes Virginia <script>", "rdap_registrar.json");
|
||||
verifyMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleMatchRegistrar_notFound_subtypeContacts() throws Exception {
|
||||
action.subtypeParam = Optional.of("contacts");
|
||||
runNotFoundHandleTest("20");
|
||||
verifyErrorMetrics(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleMatchRegistrar_found_specifyingSameRegistrar() throws Exception {
|
||||
action.registrarParam = Optional.of("2-Registrar");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue