Search in sources :

Example 56 with MockRequestContext

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

the class InjectResponseHeadersActionTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    val locator = mock(ResponseBuilderLocator.class);
    when(locator.locate(any(WebApplicationService.class))).thenReturn(new WebApplicationServiceResponseBuilder(this.servicesManager, this.urlValidator));
    val redirectToServiceAction = new InjectResponseHeadersAction(locator);
    val event = redirectToServiceAction.execute(context);
    assertEquals(CasWebflowConstants.STATE_ID_SUCCESS, event.getId());
    assertNotNull(response.getHeader(CasProtocolConstants.PARAMETER_SERVICE));
}
Also used : lombok.val(lombok.val) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) WebApplicationServiceResponseBuilder(org.apereo.cas.authentication.principal.WebApplicationServiceResponseBuilder) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 57 with MockRequestContext

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

the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifySsoWithHandlers.

@Test
public void verifySsoWithHandlers() throws Exception {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
    val policy = new DefaultRegisteredServiceAuthenticationPolicy();
    policy.setRequiredAuthenticationHandlers(Set.of(SimpleTestUsernamePasswordAuthenticationHandler.class.getSimpleName()));
    svc.setAuthenticationPolicy(policy);
    val ticketRegistry = new DefaultTicketRegistry();
    val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService("serviceid1"));
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.supports(ssoRequest));
    assertTrue(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTicketRegistry(org.apereo.cas.ticket.registry.DefaultTicketRegistry) DefaultRegisteredServiceAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy) 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 58 with MockRequestContext

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

the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifySsoWithExcludedHandlers.

@Test
public void verifySsoWithExcludedHandlers() throws Exception {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
    val policy = new DefaultRegisteredServiceAuthenticationPolicy();
    policy.setCriteria(new ExcludedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria());
    policy.setExcludedAuthenticationHandlers(Set.of(SimpleTestUsernamePasswordAuthenticationHandler.class.getName()));
    svc.setAuthenticationPolicy(policy);
    val ticketRegistry = new DefaultTicketRegistry();
    val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService("serviceid1"));
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.supports(ssoRequest));
    assertFalse(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTicketRegistry(org.apereo.cas.ticket.registry.DefaultTicketRegistry) DefaultRegisteredServiceAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ExcludedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria(org.apereo.cas.services.ExcludedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 59 with MockRequestContext

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

the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifyNoServiceOrPolicy.

@Test
public void verifyNoServiceOrPolicy() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
    val policy = new DefaultRegisteredServiceAuthenticationPolicy();
    policy.setCriteria(null);
    svc.setAuthenticationPolicy(policy);
    val ticketRegistry = new DefaultTicketRegistry();
    val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.isParticipating(ssoRequest));
    WebUtils.putRegisteredService(context, svc);
    assertEquals(0, strategy.getOrder());
    assertFalse(strategy.supports(ssoRequest));
    svc.setAuthenticationPolicy(null);
    assertTrue(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTicketRegistry(org.apereo.cas.ticket.registry.DefaultTicketRegistry) DefaultRegisteredServiceAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy) 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 60 with MockRequestContext

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

the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifySsoWithMismatchedHandlers.

@Test
public void verifySsoWithMismatchedHandlers() throws Exception {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
    val policy = new DefaultRegisteredServiceAuthenticationPolicy();
    policy.setRequiredAuthenticationHandlers(Set.of("SomeOtherHandler"));
    policy.setCriteria(new AllowedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria());
    svc.setAuthenticationPolicy(policy);
    val ticketRegistry = new DefaultTicketRegistry();
    val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService("serviceid1"));
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.supports(ssoRequest));
    assertFalse(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTicketRegistry(org.apereo.cas.ticket.registry.DefaultTicketRegistry) DefaultRegisteredServiceAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy) MockRequestContext(org.springframework.webflow.test.MockRequestContext) AllowedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria(org.apereo.cas.services.AllowedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) 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