Change registrar console login code in preparation for removing requireLogin

We are going to remove the requireLogin attribute from the action attribute, because it is specific to the UserService API. This is used by four actions:

ConsoleUIAction
RegistrarSettingsAction
RegistrarPaymentSetupAction
RegistrarPaymentAction

Instead, these four actions will now check the login status directly.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159562335
This commit is contained in:
mountford 2017-06-20 08:16:43 -07:00 committed by Ben McIlwain
parent 17697388b8
commit 2b7f78db98
17 changed files with 151 additions and 112 deletions

View file

@ -15,7 +15,9 @@
package google.registry.ui.server.registrar;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.persistResource;
import static java.util.Arrays.asList;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@ -23,10 +25,15 @@ import static org.mockito.Mockito.when;
import com.braintreegateway.BraintreeGateway;
import com.braintreegateway.ClientTokenGateway;
import com.google.appengine.api.users.User;
import com.google.common.collect.ImmutableMap;
import google.registry.braintree.BraintreeRegistrarSyncer;
import google.registry.model.registrar.Registrar;
import google.registry.request.auth.AuthLevel;
import google.registry.request.auth.AuthResult;
import google.registry.request.auth.UserAuthInfo;
import google.registry.testing.AppEngineRule;
import javax.servlet.http.HttpServletRequest;
import org.joda.money.CurrencyUnit;
import org.junit.Before;
import org.junit.Rule;
@ -46,17 +53,25 @@ public class RegistrarPaymentSetupActionTest {
private final BraintreeGateway braintreeGateway = mock(BraintreeGateway.class);
private final ClientTokenGateway clientTokenGateway = mock(ClientTokenGateway.class);
private final BraintreeRegistrarSyncer customerSyncer = mock(BraintreeRegistrarSyncer.class);
private final SessionUtils sessionUtils = mock(SessionUtils.class);
private final User user = new User("marla.singer@example.com", "gmail.com", "12345");
private final RegistrarPaymentSetupAction action = new RegistrarPaymentSetupAction();
@Before
public void before() throws Exception {
action.sessionUtils = sessionUtils;
action.authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false));
action.braintreeGateway = braintreeGateway;
action.customerSyncer = customerSyncer;
action.registrar =
Registrar.loadByClientId("TheRegistrar").asBuilder()
Registrar registrar = persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setBillingMethod(Registrar.BillingMethod.BRAINTREE)
.build();
.build());
when(sessionUtils.getRegistrarForAuthResult(
any(HttpServletRequest.class), any(AuthResult.class)))
.thenReturn(registrar);
when(braintreeGateway.clientToken()).thenReturn(clientTokenGateway);
}
@ -78,7 +93,7 @@ public class RegistrarPaymentSetupActionTest {
"token", blanketsOfSadness,
"currencies", asList("USD", "JPY"),
"brainframe", "/doodle")));
verify(customerSyncer).sync(eq(action.registrar));
verify(customerSyncer).sync(eq(Registrar.loadByClientId("TheRegistrar")));
}
@Test
@ -92,10 +107,14 @@ public class RegistrarPaymentSetupActionTest {
@Test
public void testNotOnCreditCardBillingTerms_showsErrorPage() throws Exception {
action.registrar =
Registrar.loadByClientId("TheRegistrar").asBuilder()
Registrar registrar = persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setBillingMethod(Registrar.BillingMethod.EXTERNAL)
.build();
.build());
when(sessionUtils.getRegistrarForAuthResult(
any(HttpServletRequest.class), any(AuthResult.class)))
.thenReturn(registrar);
assertThat(action.handleJsonRequest(ImmutableMap.<String, Object>of()))
.containsExactly(
"status", "ERROR",