use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.
the class AuthenticationViaFormActionTests method verifySuccessfulAuthenticationWithServiceAndWarn.
@Test
public void verifySuccessfulAuthenticationWithServiceAndWarn() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockRequestContext context = new MockRequestContext();
request.addParameter(USERNAME_PARAM, TEST);
request.addParameter(PASSWORD_PARAM, TEST);
request.addParameter("warn", "true");
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, TEST);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
putCredentialInRequestScope(context, c);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, this.action.execute(context).getId());
assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName()));
}
use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.
the class AuthenticationViaFormActionTests method verifyRenewWithServiceAndSameCredentials.
@Test
public void verifyRenewWithServiceAndSameCredentials() throws Exception {
final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
final Service service = RegisteredServiceTestUtils.getService(RegisteredServiceTestUtils.CONST_TEST_URL);
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), service, c);
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, RegisteredServiceTestUtils.getService(RegisteredServiceTestUtils.CONST_TEST_URL).getId());
putCredentialInRequestScope(context, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
context.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE, RegisteredServiceTestUtils.getService());
final Event ev = this.action.execute(context);
assertEquals(CasWebflowConstants.STATE_ID_SUCCESS, ev.getId());
}
use of org.springframework.mock.web.MockHttpServletRequest 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.MockHttpServletRequest in project cas by apereo.
the class FrontChannelLogoutActionTests method onSetUp.
@Before
public void onSetUp() throws Exception {
final DefaultSingleLogoutServiceMessageHandler handler = new DefaultSingleLogoutServiceMessageHandler(new SimpleHttpClientFactoryBean().getObject(), new SamlCompliantLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(), false, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
final LogoutManagerImpl logoutManager = new LogoutManagerImpl(new SamlCompliantLogoutMessageCreator(), handler, false);
this.frontChannelLogoutAction = new FrontChannelLogoutAction(logoutManager);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
this.requestContext = mock(RequestContext.class);
final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
when(this.requestContext.getExternalContext()).thenReturn(servletExternalContext);
when(servletExternalContext.getNativeRequest()).thenReturn(request);
when(servletExternalContext.getNativeResponse()).thenReturn(response);
final LocalAttributeMap flowScope = new LocalAttributeMap();
when(this.requestContext.getFlowScope()).thenReturn(flowScope);
final MockFlowExecutionKey mockFlowExecutionKey = new MockFlowExecutionKey(FLOW_EXECUTION_KEY);
final MockFlowExecutionContext mockFlowExecutionContext = new MockFlowExecutionContext();
mockFlowExecutionContext.setKey(mockFlowExecutionKey);
when(this.requestContext.getFlowExecutionContext()).thenReturn(mockFlowExecutionContext);
}
use of org.springframework.mock.web.MockHttpServletRequest 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());
}
Aggregations