use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class AuthenticationRequiredHandlerImplTest method testRedirectToLoginFormUrl.
@Test
public void testRedirectToLoginFormUrl() throws Exception {
handler.setLoginFormUrl(LOGIN_FORM_URL);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
handler.handle(context, new AuthenticationRequiredException(""));
verify(requestCache).saveRequest(request, response);
assertEquals(LOGIN_FORM_URL, response.getRedirectedUrl());
assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
assertTrue(response.isCommitted());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class LoginSuccessHandleImplTest method testRedirectToSavedRequest.
@Test
public void testRedirectToSavedRequest() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
SavedRequest savedRequest = mock(SavedRequest.class);
when(savedRequest.getRedirectUrl()).thenReturn(SAVED_REQUEST_URL);
when(requestCache.getRequest(request, response)).thenReturn(savedRequest);
handler.handle(context, mock(Authentication.class));
assertEquals(SAVED_REQUEST_URL, response.getRedirectedUrl());
assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
assertTrue(response.isCommitted());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RememberMeManagerImplTest method testAutoLoginWithInvalidId.
@Test
public void testAutoLoginWithInvalidId() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
request.setCookies(new Cookie(REMEMBER_ME_COOKIE_NAME, getSerializedLoginWithInvalidId()));
Authentication auth = rememberMeManager.autoLogin(context);
assertNull(auth);
assertNull(response.getCookie(REMEMBER_ME_COOKIE_NAME).getValue());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RememberMeManagerImplTest method testEnableRememberMe.
@Test
public void testEnableRememberMe() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
rememberMeManager.enableRememberMe(getAuthentication(), context);
String cookieValue = response.getCookie(REMEMBER_ME_COOKIE_NAME).getValue();
assertEquals(getSerializedLogin(), cookieValue);
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RememberMeManagerImplTest method testAutoLoginWithInvalidToken.
@Test(expected = CookieTheftException.class)
public void testAutoLoginWithInvalidToken() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
request.setCookies(new Cookie(REMEMBER_ME_COOKIE_NAME, getSerializedLoginWithInvalidToken()));
rememberMeManager.autoLogin(context);
}
Aggregations