use of org.springframework.mock.web.MockHttpServletRequest 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();
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
use of org.springframework.mock.web.MockHttpServletRequest 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.MockHttpServletRequest 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.MockHttpServletRequest in project cas by apereo.
the class CentralAuthenticationServiceImplWithMockitoTests method getService.
private static Service getService(final String name) {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, name);
return new WebApplicationServiceFactory().createService(request);
}
use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.
the class DateTimeAuthenticationRequestRiskCalculatorTests method verifyTestWhenAuthnEventsFoundForUser.
@Test
public void verifyTestWhenAuthnEventsFoundForUser() {
final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
final MockHttpServletRequest request = new MockHttpServletRequest();
final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
assertTrue(score.isLowestRisk());
}
Aggregations