Fix registrar security console

The registrar security console failed because it assumed the email is a
required field for the registrar, but it isn't (at least - create_registrar
doesn't require an email, and update_registrar lets you remove the email).

Fixed by allowing it to *remain* unset if it was unset originally, but if it was set - it's required.

There are more fixes needed, but they aren't related to the email, so they will wait for the next CL

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191623034
This commit is contained in:
guyben 2018-04-04 11:45:13 -07:00 committed by Ben McIlwain
parent e816913c61
commit ea891001d9
7 changed files with 44 additions and 14 deletions

View file

@ -88,6 +88,8 @@ public final class RegistryTestServer {
route("/registrar", google.registry.module.frontend.FrontendServlet.class),
route("/registrar-settings",
google.registry.module.frontend.FrontendServlet.class),
route("/registrar-premium-price-ack",
google.registry.module.frontend.FrontendServlet.class),
route("/registrar-payment",
google.registry.module.frontend.FrontendServlet.class),
route("/registrar-payment-setup",

View file

@ -16,6 +16,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.JUnitBackports.assertThrows;
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
@ -98,6 +99,16 @@ public class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase
assertNoTasksEnqueued("sheet");
}
@Test
public void testUpdate_emptyJsonObject_emailFieldNotRequiredWhenEmpty() throws Exception {
persistResource(loadRegistrar(CLIENT_ID).asBuilder().setEmailAddress(null).build());
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
"op", "update",
"args", ImmutableMap.of()));
assertThat(response).containsEntry("status", "SUCCESS");
}
@Test
public void testUpdate_badEmail_errorEmailField() throws Exception {
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(

View file

@ -106,8 +106,12 @@ public class RegistrarSettingsActionTestCase {
when(rsp.getWriter()).thenReturn(new PrintWriter(writer));
when(req.getContentType()).thenReturn("application/json");
when(req.getReader()).thenReturn(createJsonPayload(ImmutableMap.of("op", "read")));
// We mock getRegistrarForAuthResult to reload the registrar each time it's called. Otherwise -
// the result is out of date after mutations.
// (for example, if someone wants to change the registrar to prepare for a test, the function
// would still return the old value)
when(sessionUtils.getRegistrarForAuthResult(req, action.authResult))
.thenReturn(loadRegistrar(CLIENT_ID));
.thenAnswer(x -> loadRegistrar(CLIENT_ID));
when(modulesService.getVersionHostname("backend", null)).thenReturn("backend.hostname");
}