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());
}
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());
}
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));
}
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());
}
Aggregations