Search in sources :

Example 1 with WebApplicationServiceResponseBuilder

use of org.apereo.cas.authentication.principal.WebApplicationServiceResponseBuilder in project cas by apereo.

the class RedirectToServiceActionTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    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 RedirectToServiceAction(locator);
    val event = redirectToServiceAction.execute(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_REDIRECT, event.getId());
}
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) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with WebApplicationServiceResponseBuilder

use of org.apereo.cas.authentication.principal.WebApplicationServiceResponseBuilder 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 3 with WebApplicationServiceResponseBuilder

use of org.apereo.cas.authentication.principal.WebApplicationServiceResponseBuilder in project cas by apereo.

the class WebApplicationServiceResponseBuilderTests method verifyServiceUrlRedirectOverride.

@Test
public void verifyServiceUrlRedirectOverride() {
    val registeredService = mock(RegisteredService.class);
    when(registeredService.getId()).thenReturn(1L);
    when(registeredService.getServiceId()).thenReturn("https://www.google.com/.+");
    when(registeredService.getRedirectUrl()).thenReturn("https://example.org");
    val service = mock(WebApplicationService.class);
    when(service.getId()).thenReturn("https://www.google.org");
    when(service.getOriginalUrl()).thenReturn("https://www.google.org");
    val servicesManager = mock(ServicesManager.class);
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
    val builder = new WebApplicationServiceResponseBuilder(servicesManager, SimpleUrlValidator.getInstance());
    val response = builder.build(service, "SERVICE_TICKET_ID", mock(Authentication.class));
    assertNotNull(response);
    assertEquals("https://example.org?ticket=SERVICE_TICKET_ID", response.getUrl());
}
Also used : lombok.val(lombok.val) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service) RegisteredService(org.apereo.cas.services.RegisteredService) WebApplicationServiceResponseBuilder(org.apereo.cas.authentication.principal.WebApplicationServiceResponseBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)3 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)3 WebApplicationServiceResponseBuilder (org.apereo.cas.authentication.principal.WebApplicationServiceResponseBuilder)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)2 MockRequestContext (org.springframework.webflow.test.MockRequestContext)2 Service (org.apereo.cas.authentication.principal.Service)1 RegisteredService (org.apereo.cas.services.RegisteredService)1