mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 08:57:12 +02:00
Add RDAP nameserver search metric information
Also, login logic pulled out to helper methods in the test class. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=175870131
This commit is contained in:
parent
e4c5024400
commit
d840180f3a
2 changed files with 194 additions and 28 deletions
|
@ -30,6 +30,7 @@ import google.registry.model.host.HostResource;
|
||||||
import google.registry.rdap.RdapJsonFormatter.BoilerplateType;
|
import google.registry.rdap.RdapJsonFormatter.BoilerplateType;
|
||||||
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.RdapSearchResults.IncompletenessWarningType;
|
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.HttpException.BadRequestException;
|
import google.registry.request.HttpException.BadRequestException;
|
||||||
|
@ -105,14 +106,19 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
||||||
RdapSearchResults results;
|
RdapSearchResults results;
|
||||||
if (nameParam.isPresent()) {
|
if (nameParam.isPresent()) {
|
||||||
// syntax: /rdap/nameservers?name=exam*.com
|
// syntax: /rdap/nameservers?name=exam*.com
|
||||||
|
metricInformationBuilder.setSearchType(SearchType.BY_NAMESERVER_NAME);
|
||||||
if (!LDH_PATTERN.matcher(nameParam.get()).matches()) {
|
if (!LDH_PATTERN.matcher(nameParam.get()).matches()) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
"Name parameter must contain only letters, dots"
|
"Name parameter must contain only letters, dots"
|
||||||
+ " and hyphens, and an optional single wildcard");
|
+ " and hyphens, and an optional single wildcard");
|
||||||
}
|
}
|
||||||
results = searchByName(RdapSearchPattern.create(Idn.toASCII(nameParam.get()), true), now);
|
results =
|
||||||
|
searchByName(
|
||||||
|
recordWildcardType(RdapSearchPattern.create(Idn.toASCII(nameParam.get()), true)),
|
||||||
|
now);
|
||||||
} else {
|
} else {
|
||||||
// syntax: /rdap/nameservers?ip=1.2.3.4
|
// syntax: /rdap/nameservers?ip=1.2.3.4
|
||||||
|
metricInformationBuilder.setSearchType(SearchType.BY_NAMESERVER_ADDRESS);
|
||||||
InetAddress inetAddress;
|
InetAddress inetAddress;
|
||||||
try {
|
try {
|
||||||
inetAddress = InetAddresses.forString(ipParam.get());
|
inetAddress = InetAddresses.forString(ipParam.get());
|
||||||
|
@ -175,8 +181,10 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
||||||
HostResource hostResource =
|
HostResource hostResource =
|
||||||
loadByForeignKey(HostResource.class, partialStringQuery.getInitialString(), now);
|
loadByForeignKey(HostResource.class, partialStringQuery.getInitialString(), now);
|
||||||
if ((hostResource == null) || !shouldBeVisible(hostResource, now)) {
|
if ((hostResource == null) || !shouldBeVisible(hostResource, now)) {
|
||||||
|
metricInformationBuilder.setNumHostsRetrieved(0);
|
||||||
throw new NotFoundException("No nameservers found");
|
throw new NotFoundException("No nameservers found");
|
||||||
}
|
}
|
||||||
|
metricInformationBuilder.setNumHostsRetrieved(1);
|
||||||
return RdapSearchResults.create(
|
return RdapSearchResults.create(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
rdapJsonFormatter.makeRdapJsonForHost(
|
rdapJsonFormatter.makeRdapJsonForHost(
|
||||||
|
@ -211,7 +219,11 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return makeSearchResults(hostList, IncompletenessWarningType.COMPLETE, now);
|
return makeSearchResults(
|
||||||
|
hostList,
|
||||||
|
IncompletenessWarningType.COMPLETE,
|
||||||
|
domainResource.getSubordinateHosts().size(),
|
||||||
|
now);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -251,12 +263,20 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
||||||
|
|
||||||
/** Output JSON for a lists of hosts contained in an {@link RdapResultSet}. */
|
/** Output JSON for a lists of hosts contained in an {@link RdapResultSet}. */
|
||||||
private RdapSearchResults makeSearchResults(RdapResultSet<HostResource> resultSet, DateTime now) {
|
private RdapSearchResults makeSearchResults(RdapResultSet<HostResource> resultSet, DateTime now) {
|
||||||
return makeSearchResults(resultSet.resources(), resultSet.incompletenessWarningType(), now);
|
return makeSearchResults(
|
||||||
|
resultSet.resources(),
|
||||||
|
resultSet.incompletenessWarningType(),
|
||||||
|
resultSet.numResourcesRetrieved(),
|
||||||
|
now);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Output JSON for a list of hosts. */
|
/** Output JSON for a list of hosts. */
|
||||||
private RdapSearchResults makeSearchResults(
|
private RdapSearchResults makeSearchResults(
|
||||||
List<HostResource> hosts, IncompletenessWarningType incompletenessWarningType, DateTime now) {
|
List<HostResource> hosts,
|
||||||
|
IncompletenessWarningType incompletenessWarningType,
|
||||||
|
int numHostsRetrieved,
|
||||||
|
DateTime now) {
|
||||||
|
metricInformationBuilder.setNumHostsRetrieved(numHostsRetrieved);
|
||||||
OutputDataType outputDataType =
|
OutputDataType outputDataType =
|
||||||
(hosts.size() > 1) ? OutputDataType.SUMMARY : OutputDataType.FULL;
|
(hosts.size() > 1) ? OutputDataType.SUMMARY : OutputDataType.FULL;
|
||||||
ImmutableList.Builder<ImmutableMap<String, Object>> jsonListBuilder =
|
ImmutableList.Builder<ImmutableMap<String, Object>> jsonListBuilder =
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
package google.registry.rdap;
|
package google.registry.rdap;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static google.registry.rdap.RdapAuthorization.Role.ADMINISTRATOR;
|
||||||
|
import static google.registry.rdap.RdapAuthorization.Role.PUBLIC;
|
||||||
|
import static google.registry.rdap.RdapAuthorization.Role.REGISTRAR;
|
||||||
|
import static google.registry.request.Action.Method.GET;
|
||||||
import static google.registry.testing.DatastoreHelper.createTld;
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||||
import static google.registry.testing.DatastoreHelper.persistResources;
|
import static google.registry.testing.DatastoreHelper.persistResources;
|
||||||
|
@ -27,6 +31,7 @@ import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrar;
|
||||||
import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrarContacts;
|
import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrarContacts;
|
||||||
import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
|
import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.appengine.api.users.User;
|
import com.google.appengine.api.users.User;
|
||||||
|
@ -38,6 +43,10 @@ import google.registry.model.domain.DomainResource;
|
||||||
import google.registry.model.host.HostResource;
|
import google.registry.model.host.HostResource;
|
||||||
import google.registry.model.ofy.Ofy;
|
import google.registry.model.ofy.Ofy;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
|
import google.registry.rdap.RdapMetrics.EndpointType;
|
||||||
|
import google.registry.rdap.RdapMetrics.SearchType;
|
||||||
|
import google.registry.rdap.RdapMetrics.WildcardType;
|
||||||
|
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.auth.AuthLevel;
|
import google.registry.request.auth.AuthLevel;
|
||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.request.auth.AuthResult;
|
||||||
|
@ -47,6 +56,7 @@ import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import google.registry.ui.server.registrar.SessionUtils;
|
import google.registry.ui.server.registrar.SessionUtils;
|
||||||
|
import google.registry.util.Idn;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -74,6 +84,10 @@ public class RdapNameserverSearchActionTest {
|
||||||
private final UserAuthInfo userAuthInfo = UserAuthInfo.create(user, false);
|
private final UserAuthInfo userAuthInfo = UserAuthInfo.create(user, false);
|
||||||
private final UserAuthInfo adminUserAuthInfo = UserAuthInfo.create(user, true);
|
private final UserAuthInfo adminUserAuthInfo = UserAuthInfo.create(user, true);
|
||||||
private final RdapNameserverSearchAction action = new RdapNameserverSearchAction();
|
private final RdapNameserverSearchAction action = new RdapNameserverSearchAction();
|
||||||
|
private RdapAuthorization.Role metricRole = PUBLIC;
|
||||||
|
private SearchType metricSearchType = SearchType.NONE;
|
||||||
|
private WildcardType metricWildcardType = WildcardType.INVALID;
|
||||||
|
private int metricPrefixLength = 0;
|
||||||
private final RdapMetrics rdapMetrics = mock(RdapMetrics.class);
|
private final RdapMetrics rdapMetrics = mock(RdapMetrics.class);
|
||||||
|
|
||||||
private DomainResource domainCatLol;
|
private DomainResource domainCatLol;
|
||||||
|
@ -81,12 +95,15 @@ public class RdapNameserverSearchActionTest {
|
||||||
private HostResource hostNs2CatLol;
|
private HostResource hostNs2CatLol;
|
||||||
|
|
||||||
private Object generateActualJsonWithName(String name) {
|
private Object generateActualJsonWithName(String name) {
|
||||||
|
metricSearchType = SearchType.BY_NAMESERVER_NAME;
|
||||||
|
rememberWildcardType(name);
|
||||||
action.nameParam = Optional.of(name);
|
action.nameParam = Optional.of(name);
|
||||||
action.run();
|
action.run();
|
||||||
return JSONValue.parse(response.getPayload());
|
return JSONValue.parse(response.getPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object generateActualJsonWithIp(String ipString) {
|
private Object generateActualJsonWithIp(String ipString) {
|
||||||
|
metricSearchType = SearchType.BY_NAMESERVER_ADDRESS;
|
||||||
action.ipParam = Optional.of(ipString);
|
action.ipParam = Optional.of(ipString);
|
||||||
action.run();
|
action.run();
|
||||||
return JSONValue.parse(response.getPayload());
|
return JSONValue.parse(response.getPayload());
|
||||||
|
@ -160,6 +177,19 @@ public class RdapNameserverSearchActionTest {
|
||||||
action.rdapMetrics = rdapMetrics;
|
action.rdapMetrics = rdapMetrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void login(String clientId) {
|
||||||
|
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
||||||
|
when(sessionUtils.getRegistrarClientId(request)).thenReturn(clientId);
|
||||||
|
metricRole = REGISTRAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loginAsAdmin() {
|
||||||
|
when(sessionUtils.checkRegistrarConsoleLogin(request, adminUserAuthInfo)).thenReturn(true);
|
||||||
|
when(sessionUtils.getRegistrarClientId(request)).thenReturn("irrelevant");
|
||||||
|
action.authResult = AuthResult.create(AuthLevel.USER, adminUserAuthInfo);
|
||||||
|
metricRole = ADMINISTRATOR;
|
||||||
|
}
|
||||||
|
|
||||||
private Object generateExpectedJson(String expectedOutputFile) {
|
private Object generateExpectedJson(String expectedOutputFile) {
|
||||||
return generateExpectedJson(null, null, null, null, null, expectedOutputFile);
|
return generateExpectedJson(null, null, null, null, null, expectedOutputFile);
|
||||||
}
|
}
|
||||||
|
@ -238,11 +268,79 @@ public class RdapNameserverSearchActionTest {
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rememberWildcardType(String queryString) {
|
||||||
|
try {
|
||||||
|
RdapSearchPattern partialStringQuery =
|
||||||
|
RdapSearchPattern.create(Idn.toASCII(queryString), true);
|
||||||
|
if (!partialStringQuery.getHasWildcard()) {
|
||||||
|
metricWildcardType = WildcardType.NO_WILDCARD;
|
||||||
|
} else if (partialStringQuery.getSuffix() == null) {
|
||||||
|
metricWildcardType = WildcardType.PREFIX;
|
||||||
|
} else if (partialStringQuery.getInitialString().isEmpty()) {
|
||||||
|
metricWildcardType = WildcardType.SUFFIX;
|
||||||
|
} else {
|
||||||
|
metricWildcardType = WildcardType.PREFIX_AND_SUFFIX;
|
||||||
|
}
|
||||||
|
metricPrefixLength = partialStringQuery.getInitialString().length();
|
||||||
|
} catch (Exception e) {
|
||||||
|
metricWildcardType = WildcardType.INVALID;
|
||||||
|
metricPrefixLength = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyMetrics(long numHostsRetrieved) {
|
||||||
|
verifyMetrics(Optional.of(numHostsRetrieved), IncompletenessWarningType.COMPLETE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyMetrics(
|
||||||
|
Optional<Long> numHostsRetrieved, IncompletenessWarningType incompletenessWarningType) {
|
||||||
|
RdapMetrics.RdapMetricInformation.Builder builder =
|
||||||
|
RdapMetrics.RdapMetricInformation.builder()
|
||||||
|
.setEndpointType(EndpointType.NAMESERVERS)
|
||||||
|
.setSearchType(metricSearchType)
|
||||||
|
.setWildcardType(metricWildcardType)
|
||||||
|
.setPrefixLength(metricPrefixLength)
|
||||||
|
.setIncludeDeleted(action.includeDeletedParam.isPresent())
|
||||||
|
.setRegistrarSpecified(action.registrarParam.isPresent())
|
||||||
|
.setRole(metricRole)
|
||||||
|
.setRequestMethod(GET)
|
||||||
|
.setStatusCode(200)
|
||||||
|
.setIncompletenessWarningType(incompletenessWarningType);
|
||||||
|
if (numHostsRetrieved.isPresent()) {
|
||||||
|
builder.setNumHostsRetrieved(numHostsRetrieved.get());
|
||||||
|
}
|
||||||
|
verify(rdapMetrics).updateMetrics(builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyErrorMetrics() {
|
||||||
|
verifyErrorMetrics(Optional.of(0L), 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyErrorMetrics(Optional<Long> numHostsRetrieved, int statusCode) {
|
||||||
|
RdapMetrics.RdapMetricInformation.Builder builder =
|
||||||
|
RdapMetrics.RdapMetricInformation.builder()
|
||||||
|
.setEndpointType(EndpointType.NAMESERVERS)
|
||||||
|
.setSearchType(metricSearchType)
|
||||||
|
.setWildcardType(metricWildcardType)
|
||||||
|
.setPrefixLength(metricPrefixLength)
|
||||||
|
.setIncludeDeleted(action.includeDeletedParam.isPresent())
|
||||||
|
.setRegistrarSpecified(action.registrarParam.isPresent())
|
||||||
|
.setRole(metricRole)
|
||||||
|
.setRequestMethod(GET)
|
||||||
|
.setStatusCode(statusCode)
|
||||||
|
.setIncompletenessWarningType(IncompletenessWarningType.COMPLETE);
|
||||||
|
if (numHostsRetrieved.isPresent()) {
|
||||||
|
builder.setNumHostsRetrieved(numHostsRetrieved.get());
|
||||||
|
}
|
||||||
|
verify(rdapMetrics).updateMetrics(builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidPath_rejected() throws Exception {
|
public void testInvalidPath_rejected() throws Exception {
|
||||||
action.requestPath = RdapDomainSearchAction.PATH + "/path";
|
action.requestPath = RdapDomainSearchAction.PATH + "/path";
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(400);
|
assertThat(response.getStatus()).isEqualTo(400);
|
||||||
|
verifyErrorMetrics(Optional.empty(), 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -253,6 +351,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
generateExpectedJson(
|
generateExpectedJson(
|
||||||
"You must specify either name=XXXX or ip=YYYY", "rdap_error_400.json"));
|
"You must specify either name=XXXX or ip=YYYY", "rdap_error_400.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(400);
|
assertThat(response.getStatus()).isEqualTo(400);
|
||||||
|
verifyErrorMetrics(Optional.empty(), 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -264,6 +363,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
+ " name labels, e.g. exam*.tld, ns*.example.tld",
|
+ " name labels, e.g. exam*.tld, ns*.example.tld",
|
||||||
"rdap_error_422.json"));
|
"rdap_error_422.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(422);
|
assertThat(response.getStatus()).isEqualTo(422);
|
||||||
|
verifyErrorMetrics(Optional.empty(), 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -274,6 +374,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
"A suffix after a wildcard in a nameserver lookup must be an in-bailiwick domain",
|
"A suffix after a wildcard in a nameserver lookup must be an in-bailiwick domain",
|
||||||
"rdap_error_422.json"));
|
"rdap_error_422.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(422);
|
assertThat(response.getStatus()).isEqualTo(422);
|
||||||
|
verifyErrorMetrics(Optional.empty(), 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -281,6 +382,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithName("*.*"))
|
assertThat(generateActualJsonWithName("*.*"))
|
||||||
.isEqualTo(generateExpectedJson("Only one wildcard allowed", "rdap_error_422.json"));
|
.isEqualTo(generateExpectedJson("Only one wildcard allowed", "rdap_error_422.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(422);
|
assertThat(response.getStatus()).isEqualTo(422);
|
||||||
|
verifyErrorMetrics(Optional.empty(), 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -290,6 +392,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
generateExpectedJson(
|
generateExpectedJson(
|
||||||
"Initial search string must be at least 2 characters", "rdap_error_422.json"));
|
"Initial search string must be at least 2 characters", "rdap_error_422.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(422);
|
assertThat(response.getStatus()).isEqualTo(422);
|
||||||
|
verifyErrorMetrics(Optional.empty(), 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -299,6 +402,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
generateExpectedJson(
|
generateExpectedJson(
|
||||||
"Initial search string must be at least 2 characters", "rdap_error_422.json"));
|
"Initial search string must be at least 2 characters", "rdap_error_422.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(422);
|
assertThat(response.getStatus()).isEqualTo(422);
|
||||||
|
verifyErrorMetrics(Optional.empty(), 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -308,6 +412,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
generateExpectedJsonForNameserver(
|
generateExpectedJsonForNameserver(
|
||||||
"ns1.cat.lol", null, "2-ROID", "v4", "1.2.3.4", "rdap_host_linked.json"));
|
"ns1.cat.lol", null, "2-ROID", "v4", "1.2.3.4", "rdap_host_linked.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -317,6 +422,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
generateExpectedJsonForNameserver(
|
generateExpectedJsonForNameserver(
|
||||||
"ns1.cat.lol", null, "2-ROID", "v4", "1.2.3.4", "rdap_host_linked.json"));
|
"ns1.cat.lol", null, "2-ROID", "v4", "1.2.3.4", "rdap_host_linked.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -324,6 +430,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
action.registrarParam = Optional.of("TheRegistrar");
|
action.registrarParam = Optional.of("TheRegistrar");
|
||||||
generateActualJsonWithName("ns1.cat.lol");
|
generateActualJsonWithName("ns1.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -331,6 +438,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
action.registrarParam = Optional.of("unicoderegistrar");
|
action.registrarParam = Optional.of("unicoderegistrar");
|
||||||
generateActualJsonWithName("ns1.cat.lol");
|
generateActualJsonWithName("ns1.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics(Optional.of(0L), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -344,6 +452,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
"bad:f00d:cafe::15:beef",
|
"bad:f00d:cafe::15:beef",
|
||||||
"rdap_host_linked.json"));
|
"rdap_host_linked.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -351,6 +460,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
// 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");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -360,13 +470,17 @@ public class RdapNameserverSearchActionTest {
|
||||||
generateExpectedJsonForNameserver(
|
generateExpectedJsonForNameserver(
|
||||||
"ns1.cat.external", null, "8-ROID", null, null, "rdap_host_external.json"));
|
"ns1.cat.external", null, "8-ROID", null, null, "rdap_host_external.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatch_ns1_cat_idn_unicode_badRequest() throws Exception {
|
public void testNameMatch_ns1_cat_idn_unicode_badRequest() throws Exception {
|
||||||
// name must use punycode.
|
// name must use punycode.
|
||||||
generateActualJsonWithName("ns1.cat.みんな");
|
generateActualJsonWithName("ns1.cat.みんな");
|
||||||
|
metricWildcardType = WildcardType.INVALID;
|
||||||
|
metricPrefixLength = 0;
|
||||||
assertThat(response.getStatus()).isEqualTo(400);
|
assertThat(response.getStatus()).isEqualTo(400);
|
||||||
|
verifyErrorMetrics(Optional.empty(), 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -381,6 +495,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
"1.2.3.5",
|
"1.2.3.5",
|
||||||
"rdap_host_unicode.json"));
|
"rdap_host_unicode.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -390,12 +505,14 @@ public class RdapNameserverSearchActionTest {
|
||||||
generateExpectedJsonForNameserver(
|
generateExpectedJsonForNameserver(
|
||||||
"ns1.cat.1.test", null, "E-ROID", "v4", "1.2.3.6", "rdap_host.json"));
|
"ns1.cat.1.test", null, "E-ROID", "v4", "1.2.3.6", "rdap_host.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatch_nsstar_cat_lol_found() throws Exception {
|
public void testNameMatch_nsstar_cat_lol_found() throws Exception {
|
||||||
generateActualJsonWithName("ns*.cat.lol");
|
generateActualJsonWithName("ns*.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -403,6 +520,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
action.registrarParam = Optional.of("TheRegistrar");
|
action.registrarParam = Optional.of("TheRegistrar");
|
||||||
generateActualJsonWithName("ns*.cat.lol");
|
generateActualJsonWithName("ns*.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -410,18 +528,21 @@ public class RdapNameserverSearchActionTest {
|
||||||
action.registrarParam = Optional.of("unicoderegistrar");
|
action.registrarParam = Optional.of("unicoderegistrar");
|
||||||
generateActualJsonWithName("ns*.cat.lol");
|
generateActualJsonWithName("ns*.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics(Optional.of(2L), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatch_nstar_cat_lol_found() throws Exception {
|
public void testNameMatch_nstar_cat_lol_found() throws Exception {
|
||||||
generateActualJsonWithName("n*.cat.lol");
|
generateActualJsonWithName("n*.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatch_star_cat_lol_found() throws Exception {
|
public void testNameMatch_star_cat_lol_found() throws Exception {
|
||||||
generateActualJsonWithName("*.cat.lol");
|
generateActualJsonWithName("*.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -429,6 +550,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
action.registrarParam = Optional.of("TheRegistrar");
|
action.registrarParam = Optional.of("TheRegistrar");
|
||||||
generateActualJsonWithName("*.cat.lol");
|
generateActualJsonWithName("*.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -436,30 +558,35 @@ public class RdapNameserverSearchActionTest {
|
||||||
action.registrarParam = Optional.of("unicoderegistrar");
|
action.registrarParam = Optional.of("unicoderegistrar");
|
||||||
generateActualJsonWithName("*.cat.lol");
|
generateActualJsonWithName("*.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics(Optional.of(2L), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatch_nsstar_found() throws Exception {
|
public void testNameMatch_nsstar_found() throws Exception {
|
||||||
generateActualJsonWithName("ns*");
|
generateActualJsonWithName("ns*");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatch_ns1_cat_lstar_found() throws Exception {
|
public void testNameMatch_ns1_cat_lstar_found() throws Exception {
|
||||||
generateActualJsonWithName("ns1.cat.l*");
|
generateActualJsonWithName("ns1.cat.l*");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatch_ns1_castar_found() throws Exception {
|
public void testNameMatch_ns1_castar_found() throws Exception {
|
||||||
generateActualJsonWithName("ns1.ca*");
|
generateActualJsonWithName("ns1.ca*");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatch_dogstar_notFound() throws Exception {
|
public void testNameMatch_dogstar_notFound() throws Exception {
|
||||||
generateActualJsonWithName("dog*");
|
generateActualJsonWithName("dog*");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -468,6 +595,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithName("ns*.cat.lol"))
|
assertThat(generateActualJsonWithName("ns*.cat.lol"))
|
||||||
.isEqualTo(generateExpectedJson("rdap_nontruncated_hosts.json"));
|
.isEqualTo(generateExpectedJson("rdap_nontruncated_hosts.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -476,6 +604,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithName("ns*.cat.lol"))
|
assertThat(generateActualJsonWithName("ns*.cat.lol"))
|
||||||
.isEqualTo(generateExpectedJson("rdap_truncated_hosts.json"));
|
.isEqualTo(generateExpectedJson("rdap_truncated_hosts.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -484,6 +613,8 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithName("ns*.cat.lol"))
|
assertThat(generateActualJsonWithName("ns*.cat.lol"))
|
||||||
.isEqualTo(generateExpectedJson("rdap_truncated_hosts.json"));
|
.isEqualTo(generateExpectedJson("rdap_truncated_hosts.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
// When searching names, we look for additional matches, in case some are not visible.
|
||||||
|
verifyMetrics(9);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -500,6 +631,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
"bad:f00d:cafe::15:beef",
|
"bad:f00d:cafe::15:beef",
|
||||||
"rdap_host_linked.json"));
|
"rdap_host_linked.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -508,6 +640,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithName("ns1.cat.lol"))
|
assertThat(generateActualJsonWithName("ns1.cat.lol"))
|
||||||
.isEqualTo(generateExpectedJson("No nameservers found", "rdap_error_404.json"));
|
.isEqualTo(generateExpectedJson("No nameservers found", "rdap_error_404.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -516,6 +649,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithName("cat.lo*"))
|
assertThat(generateActualJsonWithName("cat.lo*"))
|
||||||
.isEqualTo(generateExpectedJson("No nameservers found", "rdap_error_404.json"));
|
.isEqualTo(generateExpectedJson("No nameservers found", "rdap_error_404.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -523,46 +657,46 @@ public class RdapNameserverSearchActionTest {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
generateActualJsonWithName("nsdeleted.cat.lol");
|
generateActualJsonWithName("nsdeleted.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatchDeleted_notFound_notLoggedIn() throws Exception {
|
public void testNameMatchDeleted_notFound_notLoggedIn() throws Exception {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(false);
|
|
||||||
generateActualJsonWithName("nsdeleted.cat.lol");
|
generateActualJsonWithName("nsdeleted.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatchDeleted_notFound_loggedInAsDifferentRegistrar() throws Exception {
|
public void testNameMatchDeleted_notFound_loggedInAsDifferentRegistrar() throws Exception {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
login("unicoderegistrar");
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("unicoderegistrar");
|
|
||||||
generateActualJsonWithName("nsdeleted.cat.lol");
|
generateActualJsonWithName("nsdeleted.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics(Optional.of(1L), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatchDeleted_found_loggedInAsCorrectRegistrar() throws Exception {
|
public void testNameMatchDeleted_found_loggedInAsCorrectRegistrar() throws Exception {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
login("TheRegistrar");
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("TheRegistrar");
|
|
||||||
generateActualJsonWithName("nsdeleted.cat.lol");
|
generateActualJsonWithName("nsdeleted.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameMatchDeleted_found_loggedInAsAdmin() throws Exception {
|
public void testNameMatchDeleted_found_loggedInAsAdmin() throws Exception {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
action.authResult = AuthResult.create(AuthLevel.USER, adminUserAuthInfo);
|
loginAsAdmin();
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, adminUserAuthInfo)).thenReturn(true);
|
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("irrelevant");
|
|
||||||
generateActualJsonWithName("nsdeleted.cat.lol");
|
generateActualJsonWithName("nsdeleted.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -570,10 +704,10 @@ public class RdapNameserverSearchActionTest {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.registrarParam = Optional.of("TheRegistrar");
|
action.registrarParam = Optional.of("TheRegistrar");
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
login("TheRegistrar");
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("TheRegistrar");
|
|
||||||
generateActualJsonWithName("nsdeleted.cat.lol");
|
generateActualJsonWithName("nsdeleted.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -582,16 +716,17 @@ public class RdapNameserverSearchActionTest {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.registrarParam = Optional.of("unicoderegistrar");
|
action.registrarParam = Optional.of("unicoderegistrar");
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
login("TheRegistrar");
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("TheRegistrar");
|
|
||||||
generateActualJsonWithName("nsdeleted.cat.lol");
|
generateActualJsonWithName("nsdeleted.cat.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddressMatch_invalidAddress() throws Exception {
|
public void testAddressMatch_invalidAddress() throws Exception {
|
||||||
generateActualJsonWithIp("It is to laugh");
|
generateActualJsonWithIp("It is to laugh");
|
||||||
assertThat(response.getStatus()).isEqualTo(400);
|
assertThat(response.getStatus()).isEqualTo(400);
|
||||||
|
verifyErrorMetrics(Optional.empty(), 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -601,6 +736,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
generateExpectedJsonForNameserver(
|
generateExpectedJsonForNameserver(
|
||||||
"ns1.cat.lol", null, "2-ROID", "v4", "1.2.3.4", "rdap_host_linked.json"));
|
"ns1.cat.lol", null, "2-ROID", "v4", "1.2.3.4", "rdap_host_linked.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -608,6 +744,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
action.registrarParam = Optional.of("TheRegistrar");
|
action.registrarParam = Optional.of("TheRegistrar");
|
||||||
generateActualJsonWithIp("1.2.3.4");
|
generateActualJsonWithIp("1.2.3.4");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -615,6 +752,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
action.registrarParam = Optional.of("unicoderegistrar");
|
action.registrarParam = Optional.of("unicoderegistrar");
|
||||||
generateActualJsonWithIp("1.2.3.4");
|
generateActualJsonWithIp("1.2.3.4");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -622,12 +760,14 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithIp("bad:f00d:cafe::15:beef"))
|
assertThat(generateActualJsonWithIp("bad:f00d:cafe::15:beef"))
|
||||||
.isEqualTo(generateExpectedJson("rdap_multiple_hosts.json"));
|
.isEqualTo(generateExpectedJson("rdap_multiple_hosts.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddressMatchLocalhost_notFound() throws Exception {
|
public void testAddressMatchLocalhost_notFound() throws Exception {
|
||||||
generateActualJsonWithIp("127.0.0.1");
|
generateActualJsonWithIp("127.0.0.1");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -636,6 +776,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithIp("1.2.3.4"))
|
assertThat(generateActualJsonWithIp("1.2.3.4"))
|
||||||
.isEqualTo(generateExpectedJson("No nameservers found", "rdap_error_404.json"));
|
.isEqualTo(generateExpectedJson("No nameservers found", "rdap_error_404.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -644,6 +785,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithIp("5.5.5.1"))
|
assertThat(generateActualJsonWithIp("5.5.5.1"))
|
||||||
.isEqualTo(generateExpectedJson("rdap_nontruncated_hosts.json"));
|
.isEqualTo(generateExpectedJson("rdap_nontruncated_hosts.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -652,6 +794,7 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithIp("5.5.5.1"))
|
assertThat(generateActualJsonWithIp("5.5.5.1"))
|
||||||
.isEqualTo(generateExpectedJson("rdap_truncated_hosts.json"));
|
.isEqualTo(generateExpectedJson("rdap_truncated_hosts.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -660,6 +803,9 @@ public class RdapNameserverSearchActionTest {
|
||||||
assertThat(generateActualJsonWithIp("5.5.5.1"))
|
assertThat(generateActualJsonWithIp("5.5.5.1"))
|
||||||
.isEqualTo(generateExpectedJson("rdap_truncated_hosts.json"));
|
.isEqualTo(generateExpectedJson("rdap_truncated_hosts.json"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
// When searching by address and not including deleted, we don't need to search for extra
|
||||||
|
// matches.
|
||||||
|
verifyMetrics(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -667,46 +813,46 @@ public class RdapNameserverSearchActionTest {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
generateActualJsonWithIp("4.3.2.1");
|
generateActualJsonWithIp("4.3.2.1");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddressMatchDeleted_notFound_notLoggedIn() throws Exception {
|
public void testAddressMatchDeleted_notFound_notLoggedIn() throws Exception {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(false);
|
|
||||||
generateActualJsonWithIp("4.3.2.1");
|
generateActualJsonWithIp("4.3.2.1");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddressMatchDeleted_notFound_loggedInAsDifferentRegistrar() throws Exception {
|
public void testAddressMatchDeleted_notFound_loggedInAsDifferentRegistrar() throws Exception {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
login("unicoderegistrar");
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("unicoderegistrar");
|
|
||||||
generateActualJsonWithIp("4.3.2.1");
|
generateActualJsonWithIp("4.3.2.1");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics(Optional.of(1L), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddressMatchDeleted_found_loggedInAsCorrectRegistrar() throws Exception {
|
public void testAddressMatchDeleted_found_loggedInAsCorrectRegistrar() throws Exception {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
login("TheRegistrar");
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("TheRegistrar");
|
|
||||||
generateActualJsonWithIp("4.3.2.1");
|
generateActualJsonWithIp("4.3.2.1");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddressMatchDeleted_found_loggedInAsAdmin() throws Exception {
|
public void testAddressMatchDeleted_found_loggedInAsAdmin() throws Exception {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
action.authResult = AuthResult.create(AuthLevel.USER, adminUserAuthInfo);
|
loginAsAdmin();
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, adminUserAuthInfo)).thenReturn(true);
|
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("irrelevant");
|
|
||||||
generateActualJsonWithIp("4.3.2.1");
|
generateActualJsonWithIp("4.3.2.1");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -714,10 +860,10 @@ public class RdapNameserverSearchActionTest {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.registrarParam = Optional.of("TheRegistrar");
|
action.registrarParam = Optional.of("TheRegistrar");
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
login("TheRegistrar");
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("TheRegistrar");
|
|
||||||
generateActualJsonWithIp("4.3.2.1");
|
generateActualJsonWithIp("4.3.2.1");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
verifyMetrics(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -726,9 +872,9 @@ public class RdapNameserverSearchActionTest {
|
||||||
createDeletedHost();
|
createDeletedHost();
|
||||||
action.registrarParam = Optional.of("unicoderegistrar");
|
action.registrarParam = Optional.of("unicoderegistrar");
|
||||||
action.includeDeletedParam = Optional.of(true);
|
action.includeDeletedParam = Optional.of(true);
|
||||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
login("TheRegistrar");
|
||||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("TheRegistrar");
|
|
||||||
generateActualJsonWithIp("4.3.2.1");
|
generateActualJsonWithIp("4.3.2.1");
|
||||||
assertThat(response.getStatus()).isEqualTo(404);
|
assertThat(response.getStatus()).isEqualTo(404);
|
||||||
|
verifyErrorMetrics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue