use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class LoginFailureHandlerImplTest method testSendError.
@Test
public void testSendError() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
handler.handle(context, new AuthenticationException());
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
assertTrue(response.isCommitted());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class LogoutSuccessHandlerImplTest method testRedirectToTargetUrl.
@Test
public void testRedirectToTargetUrl() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
handler.handle(context);
assertEquals(TARGET_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 RestAuthenticationRequiredHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/profile.json");
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
handler.handle(context, new AuthenticationRequiredException(ERROR_MESSAGE));
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
assertEquals(EXPECTED_RESPONSE_CONTENT, response.getContentAsString());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RestLoginSuccessHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/login.json");
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
String ticket = UUID.randomUUID().toString();
ObjectId profileId = new ObjectId();
Profile profile = new Profile();
profile.setId(profileId);
profile.setUsername("jdoe");
profile.setPassword("1234");
profile.setEmail("jdoe@craftercms.org");
Authentication auth = new DefaultAuthentication(ticket.toString(), profile);
handler.handle(context, auth);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertEquals("{\"ticket\":\"" + ticket + "\",\"profile\":{\"username\":\"jdoe\"," + "\"password\":\"1234\",\"email\":\"jdoe@craftercms.org\",\"verified\":false," + "\"enabled\":false,\"createdOn\":null,\"lastModified\":null,\"tenant\":null,\"roles\":[]," + "\"attributes\":{},\"failedLoginAttempts\":0,\"lastFailedLogin\":null,\"id\":\"" + profileId.toString() + "\"},\"remembered\":false}", response.getContentAsString());
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class AccessTokenServiceImplTest method setCurrentRequestContext.
private void setCurrentRequestContext() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestContext.setCurrent(context);
}
Aggregations