use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class SpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldBeChecked.
@Test
public void ensureRemoteIpShouldBeChecked() {
final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("^192\\.158\\..+"), "", 0);
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr("192.158.5.781");
final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class OpenIdSingleSignOnActionTests method verifySuccessfulServiceTicket.
@Test
public void verifySuccessfulServiceTicket() throws Exception {
final MockRequestContext context = new MockRequestContext();
final MockHttpServletRequest request = new MockHttpServletRequest();
final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("scootman28");
final TicketGrantingTicket t = new TicketGrantingTicketImpl("TGT-11", authentication, new NeverExpiresExpirationPolicy());
this.ticketRegistry.addTicket(t);
request.setParameter(OpenIdProtocolConstants.OPENID_IDENTITY, "http://openid.aol.com/scootman28");
request.setParameter(OpenIdProtocolConstants.OPENID_RETURNTO, "http://www.cnn.com");
final OpenIdService service = new OpenIdServiceFactory("").createService(request);
context.getFlowScope().put("service", service);
context.getFlowScope().put(WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, t.getId());
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
assertEquals("success", this.action.execute(context).getId());
}
use of org.springframework.mock.web.MockServletContext in project gocd by gocd.
the class DelegatingServletTest method shouldDelegateToTheGivenServlet.
@Test
public void shouldDelegateToTheGivenServlet() throws IOException, ServletException {
MockServletContext ctx = new MockServletContext();
ctx.addInitParameter(DelegatingListener.DELEGATE_SERVLET, DummyServlet.class.getCanonicalName());
ServletContextEvent evt = new ServletContextEvent(ctx);
DelegatingListener listener = new DelegatingListener();
listener.contextInitialized(evt);
assertThat((DummyServlet) ctx.getAttribute(DelegatingListener.DELEGATE_SERVLET), isA(DummyServlet.class));
DelegatingServlet servlet = new DelegatingServlet();
servlet.init(new MockServletConfig(ctx));
servlet.service(httpServletRequest, new MockHttpServletResponse());
verify(servletRequestWrapper).setRequestURI("/go/stuff/action");
}
use of org.springframework.mock.web.MockServletContext in project cas by apereo.
the class GenerateServiceTicketActionTests method verifyTicketGrantingTicketExpiredTgt.
@Test
public void verifyTicketGrantingTicketExpiredTgt() 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);
WebUtils.putTicketGrantingTicketInScopes(context, this.ticketGrantingTicket);
this.ticketGrantingTicket.markTicketExpired();
getTicketRegistry().updateTicket(this.ticketGrantingTicket);
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 InitialFlowSetupActionCookieTests method verifySettingContextPath.
@Test
public void verifySettingContextPath() {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath(CONST_CONTEXT_PATH);
final MockRequestContext context = new MockRequestContext();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
this.action.doExecute(context);
assertEquals(CONST_CONTEXT_PATH + '/', this.warnCookieGenerator.getCookiePath());
assertEquals(CONST_CONTEXT_PATH + '/', this.tgtCookieGenerator.getCookiePath());
}
Aggregations