use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RememberMeManagerImplTest method testAutoLogin.
@Test
public void testAutoLogin() 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, getSerializedLogin()));
Authentication auth = rememberMeManager.autoLogin(context);
assertNotNull(auth);
assertEquals(getProfile(), auth.getProfile());
String cookieValue = response.getCookie(REMEMBER_ME_COOKIE_NAME).getValue();
assertEquals(getSerializedLoginWithRefreshedToken(), cookieValue);
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RememberMeManagerImplTest method testDisableRememberMe.
@Test
public void testDisableRememberMe() 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, getSerializedLogin()));
rememberMeManager.disableRememberMe(context);
assertNull(response.getCookie(REMEMBER_ME_COOKIE_NAME).getValue());
verify(authenticationService).deletePersistentLogin(LOGIN_ID);
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RestLogoutSuccessHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/logout.json");
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
handler.handle(context);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertEquals(EXPECTED_RESPONSE_CONTENT, response.getContentAsString());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class CurrentAuthenticationResolvingProcessorTest method testGetAuthenticationProfileLastModifiedChanged.
@Test
public void testGetAuthenticationProfileLastModifiedChanged() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
Date profileLastModified = new Date();
Cookie ticketCookie = new Cookie(SecurityUtils.TICKET_COOKIE_NAME, TICKET);
Cookie profileLastModifiedCookie = new Cookie(SecurityUtils.PROFILE_LAST_MODIFIED_COOKIE_NAME, String.valueOf(profileLastModified.getTime() + 60000));
request.setCookies(ticketCookie, profileLastModifiedCookie);
Profile profile = new Profile();
profile.setLastModified(profileLastModified);
Profile modifiedProfile = new Profile();
modifiedProfile.setLastModified(new Date(profileLastModified.getTime() + 60000));
Authentication auth = new DefaultAuthentication(TICKET, profile);
Authentication modifiedAuth = new DefaultAuthentication(TICKET, modifiedProfile);
when(authenticationManager.getAuthentication(TICKET, false)).thenReturn(auth);
when(authenticationManager.getAuthentication(TICKET, true)).thenReturn(modifiedAuth);
processor.processRequest(context, chain);
verify(chain).processRequest(context);
Authentication newAuth = SecurityUtils.getAuthentication(request);
assertNotNull(newAuth);
assertEquals(modifiedAuth.getTicket(), newAuth.getTicket());
assertEquals(modifiedAuth.getProfile().getLastModified(), newAuth.getProfile().getLastModified());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class UrlAccessRestrictionCheckingProcessorTest method testUnAllowedAccess.
@Test(expected = AccessDeniedException.class)
public void testUnAllowedAccess() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", URL);
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
SecurityUtils.setAuthentication(request, new DefaultAuthentication(new ObjectId().toString(), new Profile()));
processor.processRequest(context, chain);
}
Aggregations