use of org.craftercms.commons.http.RequestContext in project engine by craftercms.
the class ConfigAwareUrlAccessRestrictionCheckingProcessorTest method testProcessRequest.
@Test(expected = AccessDeniedException.class)
public void testProcessRequest() throws Exception {
RequestContext requestContext = RequestContext.getCurrent();
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
SecurityUtils.setAuthentication(requestContext.getRequest(), new DefaultAuthentication(ObjectId.get().toString(), new Profile()));
processor.processRequest(requestContext, chain);
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RestAccessDeniedHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/admin.json");
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
handler.handle(context, new AccessDeniedException(ERROR_MESSAGE));
assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
assertEquals(EXPECTED_RESPONSE_CONTENT, response.getContentAsString());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class CurrentAuthenticationResolvingProcessorTest method testGetAuthentication.
@Test
public void testGetAuthentication() 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()));
request.setCookies(ticketCookie, profileLastModifiedCookie);
Profile profile = new Profile();
profile.setLastModified(profileLastModified);
Authentication auth = new DefaultAuthentication(TICKET, profile);
when(authenticationManager.getAuthentication(TICKET, false)).thenReturn(auth);
processor.processRequest(context, chain);
verify(chain).processRequest(context);
Authentication newAuth = SecurityUtils.getAuthentication(request);
assertNotNull(newAuth);
assertEquals(auth.getTicket(), newAuth.getTicket());
assertEquals(auth.getProfile().getLastModified(), newAuth.getProfile().getLastModified());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class LogoutProcessorTest method testLogout.
@Test
public void testLogout() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(LogoutProcessor.DEFAULT_LOGOUT_METHOD, LogoutProcessor.DEFAULT_LOGOUT_URL);
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
Profile profile = new Profile();
profile.setUsername(USERNAME);
Authentication auth = new DefaultAuthentication(new ObjectId().toString(), profile);
SecurityUtils.setAuthentication(request, auth);
processor.processRequest(context, chain);
verify(chain, never()).processRequest(context);
assertNull(SecurityUtils.getAuthentication(request));
verify(logoutSuccessHandler).handle(context);
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RememberMeAutoLoginProcessorTest method testProcessRequest.
@Test
public void testProcessRequest() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
processor.processRequest(context, chain);
assertNotNull(SecurityUtils.getAuthentication(request));
assertEquals(authentication, SecurityUtils.getAuthentication(request));
verify(rememberMeManager).autoLogin(context);
verify(chain).processRequest(context);
}
Aggregations