Search in sources :

Example 36 with MockServletContext

use of org.apereo.cas.util.MockServletContext in project cas by apereo.

the class DelegatedClientAuthenticationActionTests method verifyServerSideRedirectAuthentication.

@Test
public void verifyServerSideRedirectAuthentication() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val service = CoreAuthenticationTestUtils.getService("https://delegated2.example.org");
    servicesManager.save(RegisteredServiceTestUtils.getRegisteredService(service.getId(), Map.of()));
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    setRequestContext(context);
    setExternalContext(context.getExternalContext());
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, delegatedAuthenticationAction.execute(context).getId());
    assertEquals(HttpStatus.FOUND.value(), response.getStatus());
    assertEquals(DelegatedClientIdentityProviderConfigurationFactory.ENDPOINT_URL_REDIRECT + "?client_name=CasClient", response.getHeader("Location"));
}
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) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with MockServletContext

use of org.apereo.cas.util.MockServletContext in project cas by apereo.

the class DelegatedClientIdentityProviderConfigurationProducerTests method verifyOperationAutoRedirect.

@Test
public void verifyOperationAutoRedirect() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val accessStrategy = new DefaultRegisteredServiceAccessStrategy();
    accessStrategy.setDelegatedAuthenticationPolicy(new DefaultRegisteredServiceDelegatedAuthenticationPolicy(List.of("SAML2Client"), false, false));
    val registeredService = RegisteredServiceTestUtils.getRegisteredService("https://delegated2.example.org");
    registeredService.setAccessStrategy(accessStrategy);
    servicesManager.save(registeredService);
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService("https://delegated2.example.org"));
    assertNotNull(producer.produce(context));
    assertNotNull(WebUtils.getDelegatedAuthenticationProviderConfigurations(context));
    assertNotNull(WebUtils.getDelegatedAuthenticationProviderPrimary(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) DefaultRegisteredServiceDelegatedAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceDelegatedAuthenticationPolicy) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 38 with MockServletContext

use of org.apereo.cas.util.MockServletContext in project cas by apereo.

the class DelegatedClientIdentityProviderConfigurationProducerTests method verifyOperationPrimaryProvider.

@Test
public void verifyOperationPrimaryProvider() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val accessStrategy = new DefaultRegisteredServiceAccessStrategy();
    accessStrategy.setDelegatedAuthenticationPolicy(new DefaultRegisteredServiceDelegatedAuthenticationPolicy(List.of("CasClient"), false, true));
    val registeredService = RegisteredServiceTestUtils.getRegisteredService("https://delegated.example.org");
    registeredService.setAccessStrategy(accessStrategy);
    servicesManager.save(registeredService);
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService("https://delegated.example.org"));
    assertNotNull(producer.produce(context));
    assertNotNull(WebUtils.getDelegatedAuthenticationProviderConfigurations(context));
    assertNotNull(WebUtils.getDelegatedAuthenticationProviderPrimary(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) DefaultRegisteredServiceDelegatedAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceDelegatedAuthenticationPolicy) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 39 with MockServletContext

use of org.apereo.cas.util.MockServletContext in project cas by apereo.

the class DelegatedClientAuthenticationDynamicDiscoveryExecutionActionTests method verifyOperationWithClient.

@Test
public void verifyOperationWithClient() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.addParameter("username", "cas@example.org");
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val result = delegatedAuthenticationDiscoveryAction.execute(context);
    assertNotNull(result);
    assertEquals(CasWebflowConstants.TRANSITION_ID_REDIRECT, result.getId());
    assertTrue(context.getRequestScope().contains(DelegatedClientAuthenticationDynamicDiscoveryExecutionAction.REQUEST_SCOPE_ATTR_PROVIDER_REDIRECT_URL, String.class));
}
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) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 40 with MockServletContext

use of org.apereo.cas.util.MockServletContext in project cas by apereo.

the class CasEurekaServerServletInitializerTests method verifyInitializer.

@Test
public void verifyInitializer() {
    val servletContext = new MockServletContext();
    val servletInitializer = new CasEurekaServerServletInitializer();
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Throwable {
            servletInitializer.onStartup(servletContext);
        }
    });
}
Also used : lombok.val(lombok.val) Executable(org.junit.jupiter.api.function.Executable) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)50 MockServletContext (org.apereo.cas.util.MockServletContext)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)46 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)46 MockRequestContext (org.springframework.webflow.test.MockRequestContext)46 Test (org.junit.jupiter.api.Test)45 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)44 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)30 JEEContext (org.pac4j.core.context.JEEContext)10 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)7 Executable (org.junit.jupiter.api.function.Executable)5 DefaultRegisteredServiceAccessStrategy (org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy)4 SAML2Client (org.pac4j.saml.client.SAML2Client)4 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)4 Flow (org.springframework.webflow.engine.Flow)3 Cookie (javax.servlet.http.Cookie)2 SneakyThrows (lombok.SneakyThrows)2 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)2 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)2 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)2