mirror of
https://github.com/google/nomulus.git
synced 2025-06-30 00:03:37 +02:00
Make Registrar load methods return Optionals instead of Nullables
This makes the code more understandable from callsites, and also forces users of this function to deal with the situation where the registrar with a given client ID might not be present (it was previously silently NPEing from some of the callsites). This also adds a test helper method loadRegistrar(clientId) that retains the old functionality for terseness in tests. It also fixes some instances of using the load method with the wrong cachedness -- some uses in high- traffic situations (WHOIS) that should have caching, but also low-traffic reporting that don't benefit from caching so might as well always be current. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=162990468
This commit is contained in:
parent
84fdeebc2f
commit
d536cef20f
81 changed files with 707 additions and 602 deletions
|
@ -15,6 +15,7 @@
|
|||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
|
||||
|
||||
|
@ -48,14 +49,14 @@ public class ContactSettingsTest extends RegistrarSettingsActionTestCase {
|
|||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, ?>> results = (List<Map<String, ?>>) response.get("results");
|
||||
assertThat(results.get(0).get("contacts"))
|
||||
.isEqualTo(Registrar.loadByClientId(CLIENT_ID).toJsonMap().get("contacts"));
|
||||
.isEqualTo(loadRegistrar(CLIENT_ID).toJsonMap().get("contacts"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost_loadSaveRegistrar_success() throws Exception {
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", Registrar.loadByClientId(CLIENT_ID).toJsonMap()));
|
||||
"args", loadRegistrar(CLIENT_ID).toJsonMap()));
|
||||
assertThat(response).containsEntry("status", "SUCCESS");
|
||||
}
|
||||
|
||||
|
@ -70,12 +71,11 @@ public class ContactSettingsTest extends RegistrarSettingsActionTestCase {
|
|||
// Have to keep ADMIN or else expect FormException for at-least-one.
|
||||
adminContact1.put("types", "ADMIN");
|
||||
|
||||
Registrar registrar = Registrar.loadByClientId(CLIENT_ID);
|
||||
Registrar registrar = loadRegistrar(CLIENT_ID);
|
||||
Map<String, Object> regMap = registrar.toJsonMap();
|
||||
regMap.put("contacts", ImmutableList.of(adminContact1));
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", regMap));
|
||||
Map<String, Object> response =
|
||||
action.handleJsonRequest(ImmutableMap.of("op", "update", "args", regMap));
|
||||
assertThat(response).containsEntry("status", "SUCCESS");
|
||||
|
||||
RegistrarContact newContact = new RegistrarContact.Builder()
|
||||
|
@ -85,13 +85,12 @@ public class ContactSettingsTest extends RegistrarSettingsActionTestCase {
|
|||
.setPhoneNumber((String) adminContact1.get("phoneNumber"))
|
||||
.setTypes(ImmutableList.of(RegistrarContact.Type.ADMIN))
|
||||
.build();
|
||||
assertThat(Registrar.loadByClientId(CLIENT_ID).getContacts())
|
||||
.containsExactlyElementsIn(ImmutableSet.of(newContact));
|
||||
assertThat(loadRegistrar(CLIENT_ID).getContacts()).containsExactly(newContact);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost_updateContacts_requiredTypes_error() throws Exception {
|
||||
Map<String, Object> reqJson = Registrar.loadByClientId(CLIENT_ID).toJsonMap();
|
||||
Map<String, Object> reqJson = loadRegistrar(CLIENT_ID).toJsonMap();
|
||||
reqJson.put("contacts",
|
||||
ImmutableList.of(AppEngineRule.makeRegistrarContact2()
|
||||
.asBuilder()
|
||||
|
@ -108,7 +107,7 @@ public class ContactSettingsTest extends RegistrarSettingsActionTestCase {
|
|||
@Test
|
||||
public void testPost_updateContacts_requireTechPhone_error() throws Exception {
|
||||
// First make the contact a tech contact as well.
|
||||
Registrar registrar = Registrar.loadByClientId(CLIENT_ID);
|
||||
Registrar registrar = loadRegistrar(CLIENT_ID);
|
||||
RegistrarContact rc = AppEngineRule.makeRegistrarContact2()
|
||||
.asBuilder()
|
||||
.setTypes(ImmutableSet.of(RegistrarContact.Type.ADMIN, RegistrarContact.Type.TECH))
|
||||
|
@ -132,7 +131,7 @@ public class ContactSettingsTest extends RegistrarSettingsActionTestCase {
|
|||
@Test
|
||||
public void testPost_updateContacts_cannotRemoveWhoisAbuseContact_error() throws Exception {
|
||||
// First make the contact's info visible in whois as abuse contact info.
|
||||
Registrar registrar = Registrar.loadByClientId(CLIENT_ID);
|
||||
Registrar registrar = loadRegistrar(CLIENT_ID);
|
||||
RegistrarContact rc =
|
||||
AppEngineRule.makeRegistrarContact2()
|
||||
.asBuilder()
|
||||
|
@ -158,7 +157,7 @@ public class ContactSettingsTest extends RegistrarSettingsActionTestCase {
|
|||
public void testPost_updateContacts_whoisAbuseContactMustHavePhoneNumber_error()
|
||||
throws Exception {
|
||||
// First make the contact's info visible in whois as abuse contact info.
|
||||
Registrar registrar = Registrar.loadByClientId(CLIENT_ID);
|
||||
Registrar registrar = loadRegistrar(CLIENT_ID);
|
||||
RegistrarContact rc =
|
||||
AppEngineRule.makeRegistrarContact2()
|
||||
.asBuilder()
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.ReflectiveFieldExtractor.extractField;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
@ -33,7 +34,6 @@ import com.braintreegateway.ValidationErrorCode;
|
|||
import com.braintreegateway.ValidationErrors;
|
||||
import com.google.appengine.api.users.User;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.request.auth.AuthLevel;
|
||||
import google.registry.request.auth.AuthResult;
|
||||
import google.registry.request.auth.UserAuthInfo;
|
||||
|
@ -94,7 +94,7 @@ public class RegistrarPaymentActionTest {
|
|||
when(transactionGateway.sale(any(TransactionRequest.class))).thenReturn(result);
|
||||
when(sessionUtils.getRegistrarForAuthResult(
|
||||
any(HttpServletRequest.class), any(AuthResult.class)))
|
||||
.thenReturn(Registrar.loadByClientId("TheRegistrar"));
|
||||
.thenReturn(loadRegistrar("TheRegistrar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
@ -45,10 +46,7 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class RegistrarPaymentSetupActionTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
|
||||
private final BraintreeGateway braintreeGateway = mock(BraintreeGateway.class);
|
||||
private final ClientTokenGateway clientTokenGateway = mock(ClientTokenGateway.class);
|
||||
|
@ -65,7 +63,7 @@ public class RegistrarPaymentSetupActionTest {
|
|||
action.braintreeGateway = braintreeGateway;
|
||||
action.customerSyncer = customerSyncer;
|
||||
Registrar registrar = persistResource(
|
||||
Registrar.loadByClientId("TheRegistrar")
|
||||
loadRegistrar("TheRegistrar")
|
||||
.asBuilder()
|
||||
.setBillingMethod(Registrar.BillingMethod.BRAINTREE)
|
||||
.build());
|
||||
|
@ -93,7 +91,7 @@ public class RegistrarPaymentSetupActionTest {
|
|||
"token", blanketsOfSadness,
|
||||
"currencies", asList("USD", "JPY"),
|
||||
"brainframe", "/doodle")));
|
||||
verify(customerSyncer).sync(eq(Registrar.loadByClientId("TheRegistrar")));
|
||||
verify(customerSyncer).sync(eq(loadRegistrar("TheRegistrar")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -108,7 +106,7 @@ public class RegistrarPaymentSetupActionTest {
|
|||
@Test
|
||||
public void testNotOnCreditCardBillingTerms_showsErrorPage() throws Exception {
|
||||
Registrar registrar = persistResource(
|
||||
Registrar.loadByClientId("TheRegistrar")
|
||||
loadRegistrar("TheRegistrar")
|
||||
.asBuilder()
|
||||
.setBillingMethod(Registrar.BillingMethod.EXTERNAL)
|
||||
.build());
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||
|
@ -28,7 +29,6 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.export.sheet.SyncRegistrarsSheetAction;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.request.HttpException.ForbiddenException;
|
||||
import google.registry.request.auth.AuthResult;
|
||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||
|
@ -88,8 +88,7 @@ public class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase
|
|||
public void testRead_authorized_returnsRegistrarJson() throws Exception {
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.<String, Object>of());
|
||||
assertThat(response).containsEntry("status", "SUCCESS");
|
||||
assertThat(response).containsEntry("results", asList(
|
||||
Registrar.loadByClientId(CLIENT_ID).toJsonMap()));
|
||||
assertThat(response).containsEntry("results", asList(loadRegistrar(CLIENT_ID).toJsonMap()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,6 +18,7 @@ import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailAddres
|
|||
import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailDisplayName;
|
||||
import static google.registry.security.JsonHttpTestUtils.createJsonPayload;
|
||||
import static google.registry.security.JsonHttpTestUtils.createJsonResponseSupplier;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -29,7 +30,6 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.export.sheet.SyncRegistrarsSheetAction;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.request.JsonActionRunner;
|
||||
import google.registry.request.JsonResponse;
|
||||
import google.registry.request.ResponseImpl;
|
||||
|
@ -107,7 +107,7 @@ public class RegistrarSettingsActionTestCase {
|
|||
when(req.getContentType()).thenReturn("application/json");
|
||||
when(req.getReader()).thenReturn(createJsonPayload(ImmutableMap.of("op", "read")));
|
||||
when(sessionUtils.getRegistrarForAuthResult(req, action.authResult))
|
||||
.thenReturn(Registrar.loadByClientId(CLIENT_ID));
|
||||
.thenReturn(loadRegistrar(CLIENT_ID));
|
||||
when(modulesService.getVersionHostname("backend", null)).thenReturn("backend.hostname");
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import static google.registry.testing.CertificateSamples.SAMPLE_CERT;
|
|||
import static google.registry.testing.CertificateSamples.SAMPLE_CERT2;
|
||||
import static google.registry.testing.CertificateSamples.SAMPLE_CERT2_HASH;
|
||||
import static google.registry.testing.CertificateSamples.SAMPLE_CERT_HASH;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static java.util.Arrays.asList;
|
||||
|
@ -44,9 +45,11 @@ public class SecuritySettingsTest extends RegistrarSettingsActionTestCase {
|
|||
|
||||
@Test
|
||||
public void testPost_updateCert_success() throws Exception {
|
||||
Registrar modified = Registrar.loadByClientId(CLIENT_ID).asBuilder()
|
||||
.setClientCertificate(SAMPLE_CERT, clock.nowUtc())
|
||||
.build();
|
||||
Registrar modified =
|
||||
loadRegistrar(CLIENT_ID)
|
||||
.asBuilder()
|
||||
.setClientCertificate(SAMPLE_CERT, clock.nowUtc())
|
||||
.build();
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", modified.toJsonMap()));
|
||||
|
@ -59,12 +62,12 @@ public class SecuritySettingsTest extends RegistrarSettingsActionTestCase {
|
|||
.build();
|
||||
assertThat(response).containsEntry("status", "SUCCESS");
|
||||
assertThat(response).containsEntry("results", asList(modified.toJsonMap()));
|
||||
assertThat(Registrar.loadByClientId(CLIENT_ID)).isEqualTo(modified);
|
||||
assertThat(loadRegistrar(CLIENT_ID)).isEqualTo(modified);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost_updateCert_failure() throws Exception {
|
||||
Map<String, Object> reqJson = Registrar.loadByClientId(CLIENT_ID).toJsonMap();
|
||||
Map<String, Object> reqJson = loadRegistrar(CLIENT_ID).toJsonMap();
|
||||
reqJson.put("clientCertificate", "BLAH");
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update",
|
||||
|
@ -75,13 +78,13 @@ public class SecuritySettingsTest extends RegistrarSettingsActionTestCase {
|
|||
|
||||
@Test
|
||||
public void testChangeCertificates() throws Exception {
|
||||
Map<String, Object> jsonMap = Registrar.loadByClientId(CLIENT_ID).toJsonMap();
|
||||
Map<String, Object> jsonMap = loadRegistrar(CLIENT_ID).toJsonMap();
|
||||
jsonMap.put("clientCertificate", SAMPLE_CERT);
|
||||
jsonMap.put("failoverClientCertificate", null);
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update", "args", jsonMap));
|
||||
assertThat(response).containsEntry("status", "SUCCESS");
|
||||
Registrar registrar = Registrar.loadByClientId(CLIENT_ID);
|
||||
Registrar registrar = loadRegistrar(CLIENT_ID);
|
||||
assertThat(registrar.getClientCertificate()).isEqualTo(SAMPLE_CERT);
|
||||
assertThat(registrar.getClientCertificateHash()).isEqualTo(SAMPLE_CERT_HASH);
|
||||
assertThat(registrar.getFailoverClientCertificate()).isNull();
|
||||
|
@ -90,23 +93,25 @@ public class SecuritySettingsTest extends RegistrarSettingsActionTestCase {
|
|||
|
||||
@Test
|
||||
public void testChangeFailoverCertificate() throws Exception {
|
||||
Map<String, Object> jsonMap = Registrar.loadByClientId(CLIENT_ID).toJsonMap();
|
||||
Map<String, Object> jsonMap = loadRegistrar(CLIENT_ID).toJsonMap();
|
||||
jsonMap.put("failoverClientCertificate", SAMPLE_CERT2);
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update", "args", jsonMap));
|
||||
assertThat(response).containsEntry("status", "SUCCESS");
|
||||
Registrar registrar = Registrar.loadByClientId(CLIENT_ID);
|
||||
Registrar registrar = loadRegistrar(CLIENT_ID);
|
||||
assertThat(registrar.getFailoverClientCertificate()).isEqualTo(SAMPLE_CERT2);
|
||||
assertThat(registrar.getFailoverClientCertificateHash()).isEqualTo(SAMPLE_CERT2_HASH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyOrNullCertificate_doesNotClearOutCurrentOne() throws Exception {
|
||||
Registrar initialRegistrar = persistResource(
|
||||
Registrar.loadByClientId(CLIENT_ID).asBuilder()
|
||||
.setClientCertificate(SAMPLE_CERT, START_OF_TIME)
|
||||
.setFailoverClientCertificate(SAMPLE_CERT2, START_OF_TIME)
|
||||
.build());
|
||||
Registrar initialRegistrar =
|
||||
persistResource(
|
||||
loadRegistrar(CLIENT_ID)
|
||||
.asBuilder()
|
||||
.setClientCertificate(SAMPLE_CERT, START_OF_TIME)
|
||||
.setFailoverClientCertificate(SAMPLE_CERT2, START_OF_TIME)
|
||||
.build());
|
||||
when(sessionUtils.getRegistrarForAuthResult(req, action.authResult))
|
||||
.thenReturn(initialRegistrar);
|
||||
Map<String, Object> jsonMap = initialRegistrar.toJsonMap();
|
||||
|
@ -115,7 +120,7 @@ public class SecuritySettingsTest extends RegistrarSettingsActionTestCase {
|
|||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update", "args", jsonMap));
|
||||
assertThat(response).containsEntry("status", "SUCCESS");
|
||||
Registrar registrar = Registrar.loadByClientId(CLIENT_ID);
|
||||
Registrar registrar = loadRegistrar(CLIENT_ID);
|
||||
assertThat(registrar.getClientCertificate()).isEqualTo(SAMPLE_CERT);
|
||||
assertThat(registrar.getClientCertificateHash()).isEqualTo(SAMPLE_CERT_HASH);
|
||||
assertThat(registrar.getFailoverClientCertificate()).isEqualTo(SAMPLE_CERT2);
|
||||
|
@ -124,20 +129,24 @@ public class SecuritySettingsTest extends RegistrarSettingsActionTestCase {
|
|||
|
||||
@Test
|
||||
public void testToJsonMap_containsCertificate() throws Exception {
|
||||
Map<String, Object> jsonMap = Registrar.loadByClientId(CLIENT_ID).asBuilder()
|
||||
.setClientCertificate(SAMPLE_CERT2, START_OF_TIME)
|
||||
.build()
|
||||
.toJsonMap();
|
||||
Map<String, Object> jsonMap =
|
||||
loadRegistrar(CLIENT_ID)
|
||||
.asBuilder()
|
||||
.setClientCertificate(SAMPLE_CERT2, START_OF_TIME)
|
||||
.build()
|
||||
.toJsonMap();
|
||||
assertThat(jsonMap).containsEntry("clientCertificate", SAMPLE_CERT2);
|
||||
assertThat(jsonMap).containsEntry("clientCertificateHash", SAMPLE_CERT2_HASH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToJsonMap_containsFailoverCertificate() throws Exception {
|
||||
Map<String, Object> jsonMap = Registrar.loadByClientId(CLIENT_ID).asBuilder()
|
||||
.setFailoverClientCertificate(SAMPLE_CERT2, START_OF_TIME)
|
||||
.build()
|
||||
.toJsonMap();
|
||||
Map<String, Object> jsonMap =
|
||||
loadRegistrar(CLIENT_ID)
|
||||
.asBuilder()
|
||||
.setFailoverClientCertificate(SAMPLE_CERT2, START_OF_TIME)
|
||||
.build()
|
||||
.toJsonMap();
|
||||
assertThat(jsonMap).containsEntry("failoverClientCertificate", SAMPLE_CERT2);
|
||||
assertThat(jsonMap).containsEntry("failoverClientCertificateHash", SAMPLE_CERT2_HASH);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.ui.server.registrar;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.AppEngineRule.THE_REGISTRAR_GAE_USER_ID;
|
||||
import static google.registry.testing.DatastoreHelper.deleteResource;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -25,7 +26,6 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
import com.google.appengine.api.users.User;
|
||||
import com.google.common.testing.NullPointerTester;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.RegistrarContact;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
|
@ -85,8 +85,7 @@ public class SessionUtilsTest {
|
|||
@Test
|
||||
public void testCheckRegistrarConsoleLogin_sessionRevoked_invalidates() throws Exception {
|
||||
RegistrarContact.updateContacts(
|
||||
Registrar.loadByClientId("TheRegistrar"),
|
||||
new java.util.HashSet<RegistrarContact>());
|
||||
loadRegistrar("TheRegistrar"), new java.util.HashSet<RegistrarContact>());
|
||||
when(session.getAttribute("clientId")).thenReturn("TheRegistrar");
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req, jart)).isFalse();
|
||||
verify(session).invalidate();
|
||||
|
@ -94,7 +93,7 @@ public class SessionUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testCheckRegistrarConsoleLogin_orphanedContactIsDenied() throws Exception {
|
||||
deleteResource(Registrar.loadByClientId("TheRegistrar"));
|
||||
deleteResource(loadRegistrar("TheRegistrar"));
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req, jart)).isFalse();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.ui.server.registrar;
|
|||
|
||||
import static com.google.common.base.Strings.repeat;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -37,86 +38,90 @@ public class WhoisSettingsTest extends RegistrarSettingsActionTestCase {
|
|||
|
||||
@Test
|
||||
public void testPost_update_success() throws Exception {
|
||||
Registrar modified = Registrar.loadByClientId(CLIENT_ID).asBuilder()
|
||||
.setEmailAddress("hello.kitty@example.com")
|
||||
.setPhoneNumber("+1.2125650000")
|
||||
.setFaxNumber("+1.2125650001")
|
||||
.setReferralUrl("http://acme.com/")
|
||||
.setWhoisServer("ns1.foo.bar")
|
||||
.setLocalizedAddress(new RegistrarAddress.Builder()
|
||||
.setStreet(ImmutableList.of("76 Ninth Avenue", "Eleventh Floor"))
|
||||
.setCity("New York")
|
||||
.setState("NY")
|
||||
.setZip("10009")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build();
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", modified.toJsonMap()));
|
||||
Registrar modified =
|
||||
loadRegistrar(CLIENT_ID)
|
||||
.asBuilder()
|
||||
.setEmailAddress("hello.kitty@example.com")
|
||||
.setPhoneNumber("+1.2125650000")
|
||||
.setFaxNumber("+1.2125650001")
|
||||
.setReferralUrl("http://acme.com/")
|
||||
.setWhoisServer("ns1.foo.bar")
|
||||
.setLocalizedAddress(
|
||||
new RegistrarAddress.Builder()
|
||||
.setStreet(ImmutableList.of("76 Ninth Avenue", "Eleventh Floor"))
|
||||
.setCity("New York")
|
||||
.setState("NY")
|
||||
.setZip("10009")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build();
|
||||
Map<String, Object> response =
|
||||
action.handleJsonRequest(ImmutableMap.of("op", "update", "args", modified.toJsonMap()));
|
||||
assertThat(response.get("status")).isEqualTo("SUCCESS");
|
||||
assertThat(response.get("results")).isEqualTo(asList(modified.toJsonMap()));
|
||||
assertThat(Registrar.loadByClientId(CLIENT_ID)).isEqualTo(modified);
|
||||
assertThat(loadRegistrar(CLIENT_ID)).isEqualTo(modified);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost_badUsStateCode_returnsFormFieldError() throws Exception {
|
||||
Registrar modified = Registrar.loadByClientId(CLIENT_ID).asBuilder()
|
||||
.setEmailAddress("hello.kitty@example.com")
|
||||
.setPhoneNumber("+1.2125650000")
|
||||
.setFaxNumber("+1.2125650001")
|
||||
.setLocalizedAddress(new RegistrarAddress.Builder()
|
||||
.setStreet(ImmutableList.of("76 Ninth Avenue", "Eleventh Floor"))
|
||||
.setCity("New York")
|
||||
.setState("ZZ")
|
||||
.setZip("10009")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build();
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", modified.toJsonMap()));
|
||||
Registrar modified =
|
||||
loadRegistrar(CLIENT_ID)
|
||||
.asBuilder()
|
||||
.setEmailAddress("hello.kitty@example.com")
|
||||
.setPhoneNumber("+1.2125650000")
|
||||
.setFaxNumber("+1.2125650001")
|
||||
.setLocalizedAddress(
|
||||
new RegistrarAddress.Builder()
|
||||
.setStreet(ImmutableList.of("76 Ninth Avenue", "Eleventh Floor"))
|
||||
.setCity("New York")
|
||||
.setState("ZZ")
|
||||
.setZip("10009")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build();
|
||||
Map<String, Object> response =
|
||||
action.handleJsonRequest(ImmutableMap.of("op", "update", "args", modified.toJsonMap()));
|
||||
assertThat(response.get("status")).isEqualTo("ERROR");
|
||||
assertThat(response.get("field")).isEqualTo("localizedAddress.state");
|
||||
assertThat(response.get("message")).isEqualTo("Unknown US state code.");
|
||||
assertThat(Registrar.loadByClientId(CLIENT_ID)).isNotEqualTo(modified);
|
||||
assertThat(loadRegistrar(CLIENT_ID)).isNotEqualTo(modified);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost_badAddress_returnsFormFieldError() throws Exception {
|
||||
Registrar modified = Registrar.loadByClientId(CLIENT_ID).asBuilder()
|
||||
.setEmailAddress("hello.kitty@example.com")
|
||||
.setPhoneNumber("+1.2125650000")
|
||||
.setFaxNumber("+1.2125650001")
|
||||
.setLocalizedAddress(new RegistrarAddress.Builder()
|
||||
.setStreet(ImmutableList.of("76 Ninth Avenue", repeat("lol", 200)))
|
||||
.setCity("New York")
|
||||
.setState("NY")
|
||||
.setZip("10009")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build();
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", modified.toJsonMap()));
|
||||
Registrar modified =
|
||||
loadRegistrar(CLIENT_ID)
|
||||
.asBuilder()
|
||||
.setEmailAddress("hello.kitty@example.com")
|
||||
.setPhoneNumber("+1.2125650000")
|
||||
.setFaxNumber("+1.2125650001")
|
||||
.setLocalizedAddress(
|
||||
new RegistrarAddress.Builder()
|
||||
.setStreet(ImmutableList.of("76 Ninth Avenue", repeat("lol", 200)))
|
||||
.setCity("New York")
|
||||
.setState("NY")
|
||||
.setZip("10009")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build();
|
||||
Map<String, Object> response =
|
||||
action.handleJsonRequest(ImmutableMap.of("op", "update", "args", modified.toJsonMap()));
|
||||
assertThat(response.get("status")).isEqualTo("ERROR");
|
||||
assertThat(response.get("field")).isEqualTo("localizedAddress.street[1]");
|
||||
assertThat((String) response.get("message"))
|
||||
.contains("Number of characters (600) not in range");
|
||||
assertThat(Registrar.loadByClientId(CLIENT_ID)).isNotEqualTo(modified);
|
||||
assertThat(loadRegistrar(CLIENT_ID)).isNotEqualTo(modified);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost_badWhoisServer_returnsFormFieldError() throws Exception {
|
||||
Registrar modified = Registrar.loadByClientId(CLIENT_ID).asBuilder()
|
||||
.setWhoisServer("tears@dry.tragical.lol")
|
||||
.build();
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", modified.toJsonMap()));
|
||||
Registrar modified =
|
||||
loadRegistrar(CLIENT_ID).asBuilder().setWhoisServer("tears@dry.tragical.lol").build();
|
||||
Map<String, Object> response =
|
||||
action.handleJsonRequest(ImmutableMap.of("op", "update", "args", modified.toJsonMap()));
|
||||
assertThat(response.get("status")).isEqualTo("ERROR");
|
||||
assertThat(response.get("field")).isEqualTo("whoisServer");
|
||||
assertThat(response.get("message")).isEqualTo("Not a valid hostname.");
|
||||
assertThat(Registrar.loadByClientId(CLIENT_ID)).isNotEqualTo(modified);
|
||||
assertThat(loadRegistrar(CLIENT_ID)).isNotEqualTo(modified);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue