Search in sources :

Example 86 with MockRequestContext

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

the class InterruptSingleSignOnParticipationStrategyTests method verifyStrategyWithoutInterrupt.

@Test
public void verifyStrategyWithoutInterrupt() {
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(new MockHttpServletRequest()).requestContext(new MockRequestContext()).build();
    assertFalse(interruptSingleSignOnParticipationStrategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 87 with MockRequestContext

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

the class FinalizeInterruptFlowActionTests method verifyFinalizedInterruptNonBlocked.

@Test
public void verifyFinalizedInterruptNonBlocked() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val interrupt = InterruptResponse.interrupt();
    InterruptUtils.putInterruptIn(context, interrupt);
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
    WebUtils.putRegisteredService(context, CoreAuthenticationTestUtils.getRegisteredService());
    val action = new FinalizeInterruptFlowAction(mock(CasCookieBuilder.class));
    val event = action.doExecute(context);
    assertEquals(event.getId(), CasWebflowConstants.TRANSITION_ID_SUCCESS);
    val authn = WebUtils.getAuthentication(context);
    assertTrue(authn.getAttributes().containsKey(InquireInterruptAction.AUTHENTICATION_ATTRIBUTE_FINALIZED_INTERRUPT));
}
Also used : lombok.val(lombok.val) CasCookieBuilder(org.apereo.cas.web.cookie.CasCookieBuilder) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 88 with MockRequestContext

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

the class FinalizeInterruptFlowActionTests method verifyFinalizedInterruptBlocked.

@Test
public void verifyFinalizedInterruptBlocked() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val interrupt = InterruptResponse.interrupt();
    interrupt.setBlock(true);
    InterruptUtils.putInterruptIn(context, interrupt);
    WebUtils.putRegisteredService(context, CoreAuthenticationTestUtils.getRegisteredService());
    val action = new FinalizeInterruptFlowAction(mock(CasCookieBuilder.class));
    assertThrows(UnauthorizedServiceException.class, () -> action.doExecute(context));
}
Also used : lombok.val(lombok.val) CasCookieBuilder(org.apereo.cas.web.cookie.CasCookieBuilder) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 89 with MockRequestContext

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

the class RegexAttributeInterruptInquirerTests method verifyInterruptSkippedWithServicePolicy.

@Test
public void verifyInterruptSkippedWithServicePolicy() {
    val q = new RegexAttributeInterruptInquirer("member..", "CA.|system");
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    registeredService.setWebflowInterruptPolicy(new DefaultRegisteredServiceWebflowInterruptPolicy().setEnabled(false));
    val response = q.inquire(CoreAuthenticationTestUtils.getAuthentication("casuser"), registeredService, CoreAuthenticationTestUtils.getService(), CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), new MockRequestContext());
    assertNotNull(response);
    assertFalse(response.isInterrupt());
}
Also used : lombok.val(lombok.val) DefaultRegisteredServiceWebflowInterruptPolicy(org.apereo.cas.services.DefaultRegisteredServiceWebflowInterruptPolicy) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test)

Example 90 with MockRequestContext

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

the class RestEndpointInterruptInquirerTests method verifyResponseCanBeFoundFromRest.

@Test
public void verifyResponseCanBeFoundFromRest() {
    val restProps = new RestfulInterruptProperties();
    restProps.setUrl("http://localhost:8888");
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.addHeader("accept-language", "fr");
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    val q = new RestEndpointInterruptInquirer(restProps);
    val response = q.inquire(CoreAuthenticationTestUtils.getAuthentication("casuser"), CoreAuthenticationTestUtils.getRegisteredService(), CoreAuthenticationTestUtils.getService(), CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), context);
    assertNotNull(response);
    assertTrue(response.isBlock());
    assertTrue(response.isSsoEnabled());
    assertEquals(2, response.getLinks().size());
    assertEquals(getClass().getSimpleName(), response.getMessage());
}
Also used : lombok.val(lombok.val) RestfulInterruptProperties(org.apereo.cas.configuration.model.support.interrupt.RestfulInterruptProperties) 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)

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