use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class AuthenticationViaFormActionTests method verifyFailedAuthenticationWithNoService.
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
request.addParameter(USERNAME_PARAM, TEST);
request.addParameter(PASSWORD_PARAM, "test2");
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
final Credential c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword();
putCredentialInRequestScope(context, c);
context.getRequestScope().put("org.springframework.validation.BindException.credentials", new BindException(c, "credential"));
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class GenerateServiceTicketActionTests method verifyTicketGrantingTicketNotTgtButGateway.
@Test
public void verifyTicketGrantingTicketNotTgtButGateway() throws Exception {
final MockRequestContext context = new MockRequestContext();
context.getFlowScope().put(SERVICE_PARAM, RegisteredServiceTestUtils.getService());
final MockHttpServletRequest request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE_PARAM);
request.addParameter(CasProtocolConstants.PARAMETER_GATEWAY, "true");
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getId()).thenReturn("bleh");
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
assertEquals(CasWebflowConstants.STATE_ID_GATEWAY, this.action.execute(context).getId());
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class SendTicketGrantingTicketActionTests method verifyTgtToSet.
@Test
public void verifyTgtToSet() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr(LOCALHOST_IP);
request.setLocalAddr(LOCALHOST_IP);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
final MockHttpServletResponse response = new MockHttpServletResponse();
request.addHeader("User-Agent", "Test");
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getId()).thenReturn(TEST_STRING);
WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
assertEquals(SUCCESS, this.action.execute(this.context).getId());
request.setCookies(response.getCookies());
assertEquals(tgt.getId(), this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request));
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class SendTicketGrantingTicketActionTests method verifySsoSessionCookieOnServiceSsoDisallowed.
@Test
public void verifySsoSessionCookieOnServiceSsoDisallowed() throws Exception {
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockHttpServletRequest request = new MockHttpServletRequest();
final WebApplicationService svc = mock(WebApplicationService.class);
when(svc.getId()).thenReturn("TestSsoFalse");
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getId()).thenReturn(TEST_STRING);
request.setCookies(new Cookie("TGT", "test5"));
WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
this.context.getFlowScope().put("service", svc);
final SendTicketGrantingTicketAction action = new SendTicketGrantingTicketAction(centralAuthenticationService, servicesManager, ticketGrantingTicketCookieGenerator, false);
assertEquals(SUCCESS, action.execute(this.context).getId());
assertEquals(0, response.getCookies().length);
}
use of org.springframework.mock.web.MockServletContext in project JessMA by ldcsaa.
the class TestRest method main.
public static void main(String[] args) throws Exception {
MockServletContext servletContext = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
response.setCharacterEncoding(GeneralHelper.DEFAULT_ENCODING);
RestContext context = new RestContext(RequestType.PUT, "/aaa/111;12|34|56,伤神小怪兽", RenderType.XML);
MyAction action = new MyAction();
action.setServletContext(servletContext);
action.setRequest(request);
action.setResponse(response);
action.setRequestAttribute(Rest.Constant.REQ_ATTR_REST_CONTEXT, context);
action.execute();
response.getWriter().println("\n-------------------------");
context = new RestContext(RequestType.PUT, "/大家好/12|34|56", RenderType.JSON);
action.setRequestAttribute(Rest.Constant.REQ_ATTR_REST_CONTEXT, context);
action.execute();
response.getWriter().println("\n-------------------------");
context = new RestContext(RequestType.GET, "/173/edit", RenderType.XML);
action.setRequestAttribute(Rest.Constant.REQ_ATTR_REST_CONTEXT, context);
action.execute();
String result = response.getContentAsString();
System.out.println(result);
}
Aggregations