mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 10:46:10 +02:00
Clean up registrar console login flow
Replaced the plethora of inter winding access functions and inputs in SessionUtils with just 2 functions, that both accept the same type for the user (AuthResult): guessRegistrarForUser: given an AuthResult, finds a registrar that they have access to. If none is found - a ForbiddenException is thrown. getRegistrarForUser[Cached]: (maybe should be called getRegistrarOnBehalfOfUser?) given an AuthResult and a clientId, loads and returns the registrar ONLY IF the user has access to it. Otherwise throws a ForbiddenException. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=214630657
This commit is contained in:
parent
6bddd5a8cb
commit
84a0ace2ea
16 changed files with 431 additions and 523 deletions
|
@ -53,7 +53,6 @@ import google.registry.ui.server.registrar.SessionUtils;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.joda.time.DateTime;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Before;
|
||||
|
@ -74,13 +73,9 @@ public class RdapEntityActionTest {
|
|||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
private final FakeResponse response = new FakeResponse();
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
|
||||
private final SessionUtils sessionUtils = mock(SessionUtils.class);
|
||||
private final User user = new User("rdap.user@example.com", "gmail.com", "12345");
|
||||
private final UserAuthInfo userAuthInfo = UserAuthInfo.create(user, false);
|
||||
private final UserAuthInfo adminUserAuthInfo = UserAuthInfo.create(user, true);
|
||||
private final RdapMetrics rdapMetrics = mock(RdapMetrics.class);
|
||||
|
||||
private RdapEntityAction action;
|
||||
|
@ -92,6 +87,16 @@ public class RdapEntityActionTest {
|
|||
private ContactResource disconnectedContact;
|
||||
private ContactResource deletedContact;
|
||||
|
||||
private static final AuthResult AUTH_RESULT =
|
||||
AuthResult.create(
|
||||
AuthLevel.USER,
|
||||
UserAuthInfo.create(new User("rdap.user@user.com", "gmail.com", "12345"), false));
|
||||
|
||||
private static final AuthResult AUTH_RESULT_ADMIN =
|
||||
AuthResult.create(
|
||||
AuthLevel.USER,
|
||||
UserAuthInfo.create(new User("rdap.user@google.com", "gmail.com", "12345"), true));
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
|
@ -163,7 +168,6 @@ public class RdapEntityActionTest {
|
|||
clock.nowUtc().minusMonths(6));
|
||||
action = new RdapEntityAction();
|
||||
action.clock = clock;
|
||||
action.request = request;
|
||||
action.requestMethod = Action.Method.GET;
|
||||
action.fullServletPath = "https://example.com/rdap";
|
||||
action.response = response;
|
||||
|
@ -173,19 +177,17 @@ public class RdapEntityActionTest {
|
|||
action.rdapJsonFormatter = RdapTestHelper.getTestRdapJsonFormatter();
|
||||
action.rdapWhoisServer = null;
|
||||
action.sessionUtils = sessionUtils;
|
||||
action.authResult = AuthResult.create(AuthLevel.USER, userAuthInfo);
|
||||
action.authResult = AUTH_RESULT;
|
||||
action.rdapMetrics = rdapMetrics;
|
||||
}
|
||||
|
||||
private void login(String registrar) {
|
||||
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
|
||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn(registrar);
|
||||
when(sessionUtils.guessClientIdForUser(AUTH_RESULT)).thenReturn(registrar);
|
||||
}
|
||||
|
||||
private void loginAsAdmin() {
|
||||
action.authResult = AuthResult.create(AuthLevel.USER, adminUserAuthInfo);
|
||||
when(sessionUtils.checkRegistrarConsoleLogin(request, adminUserAuthInfo)).thenReturn(true);
|
||||
when(sessionUtils.getRegistrarClientId(request)).thenReturn("irrelevant");
|
||||
action.authResult = AUTH_RESULT_ADMIN;
|
||||
when(sessionUtils.guessClientIdForUser(AUTH_RESULT_ADMIN)).thenReturn("irrelevant");
|
||||
}
|
||||
|
||||
private Object generateActualJson(String name) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue