Search in sources :

Example 1 with GenericSuccessViewAction

use of org.apereo.cas.web.flow.login.GenericSuccessViewAction in project cas by apereo.

the class GenericSuccessViewActionTests method verifyRedirect.

@Test
public void verifyRedirect() throws Exception {
    val cas = mock(CentralAuthenticationService.class);
    val servicesManager = mock(ServicesManager.class);
    val serviceFactory = mock(ServiceFactory.class);
    val service = RegisteredServiceTestUtils.getService("https://github.com/apereo/cas");
    when(serviceFactory.createService(anyString())).thenReturn(service);
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
    casProperties.getView().setDefaultRedirectUrl(service.getId());
    val action = new GenericSuccessViewAction(cas, servicesManager, serviceFactory, casProperties);
    val context = new MockRequestContext();
    context.setExternalContext(new MockExternalContext());
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val result = action.execute(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, result.getId());
    assertTrue(context.getMockExternalContext().getExternalRedirectRequested());
    assertEquals(service.getId(), context.getMockExternalContext().getExternalRedirectUrl());
}
Also used : lombok.val(lombok.val) MockExternalContext(org.springframework.webflow.test.MockExternalContext) GenericSuccessViewAction(org.apereo.cas.web.flow.login.GenericSuccessViewAction) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test)

Example 2 with GenericSuccessViewAction

use of org.apereo.cas.web.flow.login.GenericSuccessViewAction in project cas by apereo.

the class GenericSuccessViewActionTests method verifyPrincipalCanNotBeDetermined.

@Test
public void verifyPrincipalCanNotBeDetermined() throws InvalidTicketException {
    val cas = mock(CentralAuthenticationService.class);
    val mgr = mock(ServicesManager.class);
    val factory = mock(ServiceFactory.class);
    when(cas.getTicket(any(String.class), any())).thenThrow(new InvalidTicketException("TGT-1"));
    val action = new GenericSuccessViewAction(cas, mgr, factory, casProperties);
    val p = action.getAuthentication("TGT-1");
    assertNotNull(p);
    assertFalse(p.isPresent());
}
Also used : lombok.val(lombok.val) GenericSuccessViewAction(org.apereo.cas.web.flow.login.GenericSuccessViewAction) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) Test(org.junit.jupiter.api.Test)

Example 3 with GenericSuccessViewAction

use of org.apereo.cas.web.flow.login.GenericSuccessViewAction in project cas by apereo.

the class GenericSuccessViewActionTests method verifyAuthn.

@Test
public void verifyAuthn() throws Exception {
    val cas = mock(CentralAuthenticationService.class);
    val servicesManager = mock(ServicesManager.class);
    val serviceFactory = mock(ServiceFactory.class);
    val service = RegisteredServiceTestUtils.getService("https://github.com/apereo/cas");
    when(serviceFactory.createService(anyString())).thenReturn(service);
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
    val action = new GenericSuccessViewAction(cas, servicesManager, serviceFactory, casProperties);
    val context = new MockRequestContext();
    context.setExternalContext(new MockExternalContext());
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val tgt = new MockTicketGrantingTicket(CoreAuthenticationTestUtils.getAuthentication());
    when(cas.getTicket(any(String.class), any())).thenReturn(tgt);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    val result = action.execute(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, result.getId());
    assertNotNull(WebUtils.getAuthentication(context));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockExternalContext(org.springframework.webflow.test.MockExternalContext) GenericSuccessViewAction(org.apereo.cas.web.flow.login.GenericSuccessViewAction) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test)

Example 4 with GenericSuccessViewAction

use of org.apereo.cas.web.flow.login.GenericSuccessViewAction in project cas by apereo.

the class GenericSuccessViewActionTests method verifyValidPrincipal.

@Test
public void verifyValidPrincipal() throws InvalidTicketException {
    val cas = mock(CentralAuthenticationService.class);
    val mgr = mock(ServicesManager.class);
    val factory = mock(ServiceFactory.class);
    val authn = mock(Authentication.class);
    when(authn.getPrincipal()).thenReturn(CoreAuthenticationTestUtils.getPrincipal("cas"));
    val tgt = mock(TicketGrantingTicket.class);
    when(tgt.getAuthentication()).thenReturn(authn);
    when(cas.getTicket(any(String.class), any())).thenReturn(tgt);
    val action = new GenericSuccessViewAction(cas, mgr, factory, casProperties);
    val p = action.getAuthentication("TGT-1");
    assertNotNull(p);
    assertTrue(p.isPresent());
    assertEquals("cas", p.get().getPrincipal().getId());
}
Also used : lombok.val(lombok.val) GenericSuccessViewAction(org.apereo.cas.web.flow.login.GenericSuccessViewAction) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)4 GenericSuccessViewAction (org.apereo.cas.web.flow.login.GenericSuccessViewAction)4 Test (org.junit.jupiter.api.Test)4 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)2 Service (org.apereo.cas.authentication.principal.Service)2 MockExternalContext (org.springframework.webflow.test.MockExternalContext)2 MockRequestContext (org.springframework.webflow.test.MockRequestContext)2 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)1 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)1