Search in sources :

Example 26 with MockServletContext

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

the class RenewAuthenticationRequestCheckActionTests method verifyRenew.

@Test
public void verifyRenew() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val strategy = new DefaultSingleSignOnParticipationStrategy(servicesManager, casProperties.getSso(), mock(TicketRegistrySupport.class), mock(AuthenticationServiceSelectionPlan.class));
    val action = new RenewAuthenticationRequestCheckAction(strategy);
    assertEquals(CasWebflowConstants.TRANSITION_ID_RENEW, action.execute(context).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) MockRequestContext(org.springframework.webflow.test.MockRequestContext) DefaultSingleSignOnParticipationStrategy(org.apereo.cas.web.flow.DefaultSingleSignOnParticipationStrategy) 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 27 with MockServletContext

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

the class SessionStoreTicketGrantingTicketActionTests 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));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    WebUtils.putTicketGrantingTicketInScopes(context, new MockTicketGrantingTicket("casuser"));
    val action = new SessionStoreTicketGrantingTicketAction(JEESessionStore.INSTANCE);
    val result = action.execute(context);
    assertNull(result);
    val webContext = new JEEContext(request, response);
    assertTrue(JEESessionStore.INSTANCE.get(webContext, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID).isPresent());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) SessionStoreTicketGrantingTicketAction(org.apereo.cas.web.flow.login.SessionStoreTicketGrantingTicketAction) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) JEEContext(org.pac4j.core.context.JEEContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 28 with MockServletContext

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

the class DelegatedAuthenticationClientFinishLogoutActionTests method verifyOperationFailsWithError.

@Test
public void verifyOperationFailsWithError() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.addParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, "SAML2Client");
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val samlClient = (SAML2Client) builtClients.findClient("SAML2Client").get();
    val handler = mock(SAML2ProfileHandler.class);
    when(handler.receive(any())).thenThrow(new FoundAction("https://google.com"));
    samlClient.setLogoutProfileHandler(handler);
    val result = delegatedAuthenticationClientFinishLogoutAction.execute(context);
    assertNull(result);
    assertEquals(HttpStatus.FOUND.value(), response.getStatus());
    assertEquals("https://google.com", response.getHeader("Location"));
}
Also used : lombok.val(lombok.val) FoundAction(org.pac4j.core.exception.http.FoundAction) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) SAML2Client(org.pac4j.saml.client.SAML2Client) 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 29 with MockServletContext

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

the class DelegatedAuthenticationClientFinishLogoutActionTests method verifyOperationWithRedirect.

@Test
public void verifyOperationWithRedirect() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    WebUtils.putDelegatedAuthenticationClientName(context, "SAML2Client");
    WebUtils.putLogoutRedirectUrl(context, "https://google.com");
    val result = delegatedAuthenticationClientFinishLogoutAction.execute(context);
    assertNull(result);
    val samlClient = (SAML2Client) builtClients.findClient("SAML2Client").get();
    assertEquals("https://google.com", samlClient.getLogoutValidator().getPostLogoutURL());
    assertNull(WebUtils.getLogoutRedirectUrl(context, String.class));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) SAML2Client(org.pac4j.saml.client.SAML2Client) 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 30 with MockServletContext

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

the class DelegatedAuthenticationClientRetryActionTests method verifyOperationWithRedirect.

@Test
public void verifyOperationWithRedirect() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    WebUtils.putDelegatedAuthenticationClientName(context, "SAML2Client");
    val result = retryAction.execute(context);
    assertNull(result);
    assertNotNull(response.getHeaderValue("Location"));
    assertEquals(HttpStatus.FOUND.value(), response.getStatus());
}
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)

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