Search in sources :

Example 81 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class RenderLoginActionTests method verifyGroovyRender.

@Test
public void verifyGroovyRender() throws Exception {
    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());
    val properties = new CasConfigurationProperties();
    properties.getWebflow().getLoginDecorator().getGroovy().setLocation(new ClassPathResource("GroovyLoginDecorator.groovy"));
    val action = new RenderLoginAction(getServicesManager(), properties, applicationContext);
    assertNull(action.execute(context));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) RenderLoginAction(org.apereo.cas.web.flow.login.RenderLoginAction) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 82 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class ServiceAuthorizationCheckActionTests method verifyNoServiceFound.

@Test
public void verifyNoServiceFound() {
    val request = new MockHttpServletRequest();
    val context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService("invalid-service-123"));
    assertThrows(UnauthorizedServiceException.class, () -> this.action.execute(context));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 83 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class JdbcAcceptableUsagePolicyRepositoryAdvancedTests method raiseException.

private void raiseException(final Map<String, List<Object>> profileAttributes) {
    val aupProperties = casProperties.getAcceptableUsagePolicy();
    val jdbcAupRepository = new JdbcAcceptableUsagePolicyRepository(ticketRegistrySupport, aupProperties, acceptableUsagePolicyDataSource, jdbcAcceptableUsagePolicyTransactionTemplate);
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    val c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("casuser");
    val principal = CoreAuthenticationTestUtils.getPrincipal(c.getId(), profileAttributes);
    val auth = CoreAuthenticationTestUtils.getAuthentication(principal);
    WebUtils.putAuthentication(auth, context);
    assertNotNull(jdbcAupRepository.determinePrincipalId(principal));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 84 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class InitialFlowSetupCookieActionTests method verifySettingContextPath.

@Test
public void verifySettingContextPath() {
    val request = new MockHttpServletRequest();
    request.setContextPath(CONST_CONTEXT_PATH);
    val 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());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 85 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class InterruptSingleSignOnParticipationStrategyTests method verifyStrategyWithInterruptDisabled.

@Test
public void verifyStrategyWithInterruptDisabled() {
    val ctx = new MockRequestContext();
    val response = new InterruptResponse();
    response.setSsoEnabled(false);
    InterruptUtils.putInterruptIn(ctx, response);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(new MockHttpServletRequest()).requestContext(ctx).build();
    assertTrue(interruptSingleSignOnParticipationStrategy.supports(ssoRequest));
    assertFalse(interruptSingleSignOnParticipationStrategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) InterruptResponse(org.apereo.cas.interrupt.InterruptResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MockRequestContext (org.springframework.webflow.test.MockRequestContext)517 lombok.val (lombok.val)483 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)466 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)458 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)454 Test (org.junit.jupiter.api.Test)450 MockServletContext (org.springframework.mock.web.MockServletContext)404 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)132 MockServletContext (org.apereo.cas.util.MockServletContext)46 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)43 MockWebServer (org.apereo.cas.util.MockWebServer)36 ByteArrayResource (org.springframework.core.io.ByteArrayResource)36 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)35 Test (org.junit.Test)29 Event (org.springframework.webflow.execution.Event)26 Transition (org.springframework.webflow.engine.Transition)25 LiteralExpression (org.springframework.binding.expression.support.LiteralExpression)23 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)23 DefaultTargetStateResolver (org.springframework.webflow.engine.support.DefaultTargetStateResolver)23 DefaultTransitionCriteria (org.springframework.webflow.engine.support.DefaultTransitionCriteria)23