mirror of
https://github.com/google/nomulus.git
synced 2025-06-28 07:13:34 +02:00
Start using non-EPP-flow-wrapping implementation in CheckAPI
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=201620090
This commit is contained in:
parent
c8925555d4
commit
0422205d84
8 changed files with 261 additions and 604 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -15,35 +15,53 @@
|
|||
package google.registry.flows;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.monitoring.whitebox.CheckApiMetric.Availability.AVAILABLE;
|
||||
import static google.registry.monitoring.whitebox.CheckApiMetric.Availability.REGISTERED;
|
||||
import static google.registry.monitoring.whitebox.CheckApiMetric.Availability.RESERVED;
|
||||
import static google.registry.monitoring.whitebox.CheckApiMetric.Tier.PREMINUM;
|
||||
import static google.registry.monitoring.whitebox.CheckApiMetric.Tier.STANDARD;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.flows.EppTestComponent.FakesAndMocksModule;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.Registry.TldState;
|
||||
import google.registry.monitoring.whitebox.CheckApiMetric;
|
||||
import google.registry.monitoring.whitebox.CheckApiMetric.Availability;
|
||||
import google.registry.monitoring.whitebox.CheckApiMetric.Status;
|
||||
import google.registry.monitoring.whitebox.CheckApiMetric.Tier;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.testing.MockitoJUnitRule;
|
||||
import java.util.Map;
|
||||
import org.joda.time.DateTime;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
|
||||
/** Tests for {@link CheckApiAction}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class CheckApiActionTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
private static final DateTime START_TIME = DateTime.parse("2000-01-01T00:00:00.0Z");
|
||||
|
||||
final CheckApiAction action = new CheckApiAction();
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||
|
||||
@Mock private CheckApiMetrics checkApiMetrics;
|
||||
@Captor private ArgumentCaptor<CheckApiMetric> metricCaptor;
|
||||
|
||||
private DateTime endTime;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
|
@ -57,117 +75,190 @@ public class CheckApiActionTest {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> getCheckResponse(String domain) {
|
||||
CheckApiAction action = new CheckApiAction();
|
||||
action.domain = domain;
|
||||
action.response = new FakeResponse();
|
||||
action.checkApiServletRegistrarClientId = "TheRegistrar";
|
||||
action.eppController = DaggerEppTestComponent.builder()
|
||||
.fakesAndMocksModule(FakesAndMocksModule.create())
|
||||
.build()
|
||||
.startRequest()
|
||||
.eppController();
|
||||
FakeClock fakeClock = new FakeClock(START_TIME);
|
||||
action.clock = fakeClock;
|
||||
action.metricBuilder = CheckApiMetric.builder(fakeClock);
|
||||
action.checkApiMetrics = checkApiMetrics;
|
||||
fakeClock.advanceOneMilli();
|
||||
endTime = fakeClock.nowUtc();
|
||||
|
||||
action.run();
|
||||
return (Map<String, Object>) JSONValue.parse(((FakeResponse) action.response).getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nullDomain() {
|
||||
assertThat(getCheckResponse(null)).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
assertThat(getCheckResponse(null))
|
||||
.containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
|
||||
verifyFailureMetric(Status.INVALID_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_emptyDomain() {
|
||||
assertThat(getCheckResponse("")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
assertThat(getCheckResponse(""))
|
||||
.containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
|
||||
verifyFailureMetric(Status.INVALID_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidDomain() {
|
||||
assertThat(getCheckResponse("@#$%^")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
assertThat(getCheckResponse("@#$%^"))
|
||||
.containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
|
||||
verifyFailureMetric(Status.INVALID_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_singlePartDomain() {
|
||||
assertThat(getCheckResponse("foo")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
assertThat(getCheckResponse("foo"))
|
||||
.containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
|
||||
verifyFailureMetric(Status.INVALID_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nonExistentTld() {
|
||||
assertThat(getCheckResponse("foo.bar")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
assertThat(getCheckResponse("foo.bar"))
|
||||
.containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
|
||||
verifyFailureMetric(Status.INVALID_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_unauthorizedTld() {
|
||||
createTld("foo");
|
||||
persistResource(
|
||||
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of("foo")).build());
|
||||
assertThat(getCheckResponse("timmy.example")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Registrar is not authorized to access the TLD example");
|
||||
public void testFailure_invalidIdnTable() {
|
||||
assertThat(getCheckResponse("ΑΒΓ.example"))
|
||||
.containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Domain label is not allowed by IDN table");
|
||||
|
||||
verifyFailureMetric(Status.INVALID_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_tldInPredelegation() {
|
||||
createTld("predelegated", TldState.PREDELEGATION);
|
||||
assertThat(getCheckResponse("foo.predelegated"))
|
||||
.containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Check in this TLD is not allowed in the current registry phase");
|
||||
|
||||
verifyFailureMetric(Status.INVALID_REGISTRY_PHASE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availableStandard() {
|
||||
assertThat(getCheckResponse("somedomain.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
assertThat(getCheckResponse("somedomain.example"))
|
||||
.containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
|
||||
verifySuccessMetric(STANDARD, AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availableCapital() {
|
||||
assertThat(getCheckResponse("SOMEDOMAIN.EXAMPLE")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
assertThat(getCheckResponse("SOMEDOMAIN.EXAMPLE"))
|
||||
.containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
|
||||
verifySuccessMetric(STANDARD, AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availableUnicode() {
|
||||
assertThat(getCheckResponse("ééé.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
assertThat(getCheckResponse("ééé.example"))
|
||||
.containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
|
||||
verifySuccessMetric(STANDARD, AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availablePunycode() {
|
||||
assertThat(getCheckResponse("xn--9caaa.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
assertThat(getCheckResponse("xn--9caaa.example"))
|
||||
.containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
|
||||
verifySuccessMetric(STANDARD, AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availablePremium() {
|
||||
assertThat(getCheckResponse("rich.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "premium");
|
||||
assertThat(getCheckResponse("rich.example"))
|
||||
.containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "premium");
|
||||
|
||||
verifySuccessMetric(PREMINUM, AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_alreadyRegistered() {
|
||||
persistActiveDomain("somedomain.example");
|
||||
assertThat(getCheckResponse("somedomain.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", false,
|
||||
"reason", "In use");
|
||||
assertThat(getCheckResponse("somedomain.example"))
|
||||
.containsExactly(
|
||||
"status", "success",
|
||||
"available", false,
|
||||
"reason", "In use");
|
||||
|
||||
verifySuccessMetric(STANDARD, REGISTERED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_reserved() {
|
||||
assertThat(getCheckResponse("foo.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", false,
|
||||
"reason", "Reserved");
|
||||
assertThat(getCheckResponse("foo.example"))
|
||||
.containsExactly(
|
||||
"status", "success",
|
||||
"available", false,
|
||||
"reason", "Reserved");
|
||||
|
||||
verifySuccessMetric(STANDARD, RESERVED);
|
||||
}
|
||||
|
||||
private void verifySuccessMetric(Tier tier, Availability availability) {
|
||||
verify(checkApiMetrics).incrementCheckApiRequest(metricCaptor.capture());
|
||||
CheckApiMetric metric = metricCaptor.getValue();
|
||||
|
||||
verify(checkApiMetrics).recordProcessingTime(metric);
|
||||
assertThat(metric.availability()).hasValue(availability);
|
||||
assertThat(metric.tier()).hasValue(tier);
|
||||
assertThat(metric.status()).isEqualTo(Status.SUCCESS);
|
||||
assertThat(metric.startTimestamp()).isEqualTo(START_TIME);
|
||||
assertThat(metric.endTimestamp()).isEqualTo(endTime);
|
||||
}
|
||||
|
||||
private void verifyFailureMetric(Status status) {
|
||||
verify(checkApiMetrics).incrementCheckApiRequest(metricCaptor.capture());
|
||||
CheckApiMetric metric = metricCaptor.getValue();
|
||||
|
||||
verify(checkApiMetrics).recordProcessingTime(metric);
|
||||
assertThat(metric.availability()).isEmpty();
|
||||
assertThat(metric.tier()).isEmpty();
|
||||
assertThat(metric.status()).isEqualTo(status);
|
||||
assertThat(metric.startTimestamp()).isEqualTo(START_TIME);
|
||||
assertThat(metric.endTimestamp()).isEqualTo(endTime);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue