use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class InitialFlowSetupActionSsoTests method disableFlowIfNoService.
@Test
public void disableFlowIfNoService() throws Exception {
final MockRequestContext context = new MockRequestContext();
final MockHttpServletRequest request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
this.thrown.expect(NoSuchFlowExecutionException.class);
this.action.execute(context);
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class SendTicketGrantingTicketActionSsoTests method verifySsoSessionCookieOnRenewAsParameter.
@Test
public void verifySsoSessionCookieOnRenewAsParameter() throws Exception {
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
request.setRemoteAddr(LOCALHOST_IP);
request.setLocalAddr(LOCALHOST_IP);
request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "test");
ClientInfoHolder.setClientInfo(new ClientInfo(request));
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));
assertEquals(SUCCESS, action.execute(this.context).getId());
assertEquals(0, response.getCookies().length);
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class Cas20ResponseViewTests method verifyView.
@Test
public void verifyView() throws Exception {
final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));
final MockHttpServletResponse resp = new MockHttpServletResponse();
final View delegatedView = new View() {
@Override
public String getContentType() {
return "text/html";
}
@Override
public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) {
map.forEach(request::setAttribute);
}
};
final Cas20ResponseView view = new Cas20ResponseView(true, null, null, "attribute", delegatedView, new DefaultAuthenticationAttributeReleasePolicy(), new DefaultAuthenticationServiceSelectionPlan());
view.render(modelAndView.getModel(), req, resp);
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_CHAINED_AUTHENTICATIONS));
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRIMARY_AUTHENTICATION));
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL));
assertNotNull(req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_PROXY_GRANTING_TICKET_IOU));
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class Cas30ResponseViewTests method renderView.
protected Map<?, ?> renderView() throws Exception {
final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
LOGGER.debug("Retrieved model and view [{}]", modelAndView.getModel());
final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));
final ProtocolAttributeEncoder encoder = new DefaultCasProtocolAttributeEncoder(this.servicesManager, CipherExecutor.noOpOfStringToString());
final View viewDelegated = new View() {
@Override
public String getContentType() {
return MediaType.TEXT_HTML_VALUE;
}
@Override
public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) {
LOGGER.warn("Setting attribute [{}]", map.keySet());
map.forEach(request::setAttribute);
}
};
final AbstractCasView view = getCasViewToRender(encoder, viewDelegated);
final MockHttpServletResponse resp = new MockHttpServletResponse();
view.render(modelAndView.getModel(), req, resp);
return getRenderedViewModelMap(req);
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class OpenIdSingleSignOnActionTests method verifyNoService.
@Test
public void verifyNoService() throws Exception {
final MockRequestContext context = new MockRequestContext();
final MockHttpServletRequest request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
final Event event = this.action.execute(context);
assertNotNull(event);
assertEquals("error", this.action.execute(context).getId());
}
Aggregations