use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class BaseCasSimpleMultifactorSendTokenActionTests method buildRequestContextFor.
protected MockRequestContext buildRequestContextFor(final String user) {
val context = new MockRequestContext();
val messageContext = (DefaultMessageContext) context.getMessageContext();
messageContext.setMessageSource(mock(MessageSource.class));
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
WebUtils.putServiceIntoFlashScope(context, RegisteredServiceTestUtils.getService());
val principal = RegisteredServiceTestUtils.getPrincipal(user, CollectionUtils.wrap("phone", List.of("123456789"), "mail", List.of("cas@example.org")));
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(principal), context);
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, casSimpleMultifactorAuthenticationProvider);
return context;
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class CasSimpleMultifactorAuthenticationHandlerTests method verifyFailsToFindToken.
@Test
public void verifyFailsToFindToken() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
val id = UUID.randomUUID().toString();
val credential = new CasSimpleMultifactorTokenCredential(id);
assertThrows(FailedLoginException.class, () -> casSimpleMultifactorAuthenticationHandler.authenticate(credential));
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class ServiceWarningActionTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addParameter(ServiceWarningAction.PARAMETER_NAME_IGNORE_WARNING, "true");
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
assertThrows(InvalidTicketException.class, () -> action.execute(context).getId());
val tgt = new MockTicketGrantingTicket("casuser");
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
assertThrows(InvalidTicketException.class, () -> action.execute(context).getId());
val service = RegisteredServiceTestUtils.getService("https://google.com");
getServicesManager().save(RegisteredServiceTestUtils.getRegisteredService(service.getId(), Map.of()));
WebUtils.putServiceIntoFlowScope(context, service);
WebUtils.putCredential(context, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
getTicketRegistry().addTicket(tgt);
assertEquals(CasWebflowConstants.STATE_ID_REDIRECT, action.execute(context).getId());
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class SetServiceUnauthorizedRedirectUrlActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val action = new SetServiceUnauthorizedRedirectUrlAction(getServicesManager());
val service = getWebApplicationServiceFactory().createService("https://github.com/apereo/cas");
WebUtils.putRegisteredService(context, getServicesManager().findServiceBy(service));
action.execute(context);
assertNotNull(WebUtils.getUnauthorizedRedirectUrlFromFlowScope(context));
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class VerifyRequiredServiceActionTests method onSetUp.
@BeforeEach
public void onSetUp() {
this.ticketRegistrySupport = mock(TicketRegistrySupport.class);
this.verifyRequiredServiceAction = new VerifyRequiredServiceAction(getServicesManager(), getTicketGrantingTicketCookieGenerator(), casProperties, ticketRegistrySupport);
val response = new MockHttpServletResponse();
this.requestContext = new MockRequestContext();
this.httpRequest = new MockHttpServletRequest();
this.requestContext.setExternalContext(new ServletExternalContext(new MockServletContext(), this.httpRequest, response));
}
Aggregations