mirror of
https://github.com/google/nomulus.git
synced 2025-07-06 03:03:34 +02:00
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:
parent
17697388b8
commit
2b7f78db98
17 changed files with 151 additions and 112 deletions
|
@ -24,7 +24,6 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.appengine.api.users.User;
|
||||
import com.google.appengine.api.users.UserService;
|
||||
import com.google.common.testing.NullPointerTester;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.RegistrarContact;
|
||||
|
@ -55,7 +54,6 @@ public class SessionUtilsTest {
|
|||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
private final UserService userService = mock(UserService.class);
|
||||
private final HttpServletRequest req = mock(HttpServletRequest.class);
|
||||
private final HttpServletResponse rsp = mock(HttpServletResponse.class);
|
||||
private final HttpSession session = mock(HttpSession.class);
|
||||
|
@ -66,22 +64,20 @@ public class SessionUtilsTest {
|
|||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
sessionUtils = new SessionUtils(userService);
|
||||
sessionUtils = new SessionUtils();
|
||||
when(req.getSession()).thenReturn(session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckRegistrarConsoleLogin_authedButNoSession_createsSession() throws Exception {
|
||||
when(userService.getCurrentUser()).thenReturn(jart);
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req)).isTrue();
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req, jart)).isTrue();
|
||||
verify(session).setAttribute(eq("clientId"), eq("TheRegistrar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckRegistrarConsoleLogin_authedWithValidSession_doesNothing() throws Exception {
|
||||
when(session.getAttribute("clientId")).thenReturn("TheRegistrar");
|
||||
when(userService.getCurrentUser()).thenReturn(jart);
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req)).isTrue();
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req, jart)).isTrue();
|
||||
verify(session).getAttribute("clientId");
|
||||
verifyNoMoreInteractions(session);
|
||||
}
|
||||
|
@ -92,16 +88,14 @@ public class SessionUtilsTest {
|
|||
Registrar.loadByClientId("TheRegistrar"),
|
||||
new java.util.HashSet<RegistrarContact>());
|
||||
when(session.getAttribute("clientId")).thenReturn("TheRegistrar");
|
||||
when(userService.getCurrentUser()).thenReturn(jart);
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req)).isFalse();
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req, jart)).isFalse();
|
||||
verify(session).invalidate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckRegistrarConsoleLogin_orphanedContactIsDenied() throws Exception {
|
||||
deleteResource(Registrar.loadByClientId("TheRegistrar"));
|
||||
when(userService.getCurrentUser()).thenReturn(jart);
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req)).isFalse();
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req, jart)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -109,13 +103,12 @@ public class SessionUtilsTest {
|
|||
throws Exception {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
@SuppressWarnings("unused")
|
||||
boolean unused = sessionUtils.checkRegistrarConsoleLogin(req);
|
||||
boolean unused = sessionUtils.checkRegistrarConsoleLogin(req, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckRegistrarConsoleLogin_notAllowed_returnsFalse() throws Exception {
|
||||
when(userService.getCurrentUser()).thenReturn(bozo);
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req)).isFalse();
|
||||
assertThat(sessionUtils.checkRegistrarConsoleLogin(req, bozo)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue