use of org.apereo.cas.util.MockOnlyOneTicketRegistry in project cas by apereo.
the class DefaultCentralAuthenticationServiceTests method verifyDestroyRemoteRegistry.
/**
* This test checks that the TGT destruction happens properly for a remote registry.
* It previously failed when the deletion happens before the ticket was marked expired because an update was necessary for that.
*/
@Test
public void verifyDestroyRemoteRegistry() throws Exception {
val registry = new MockOnlyOneTicketRegistry();
val expirationPolicy = mock(ExpirationPolicy.class);
when(expirationPolicy.getClock()).thenReturn(Clock.systemUTC());
val tgt = new TicketGrantingTicketImpl("TGT-1", mock(Authentication.class), expirationPolicy);
registry.addTicket(tgt);
val servicesManager = mock(ServicesManager.class);
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val context = CentralAuthenticationServiceContext.builder().applicationContext(applicationContext).ticketRegistry(registry).servicesManager(servicesManager).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).cipherExecutor(CipherExecutor.noOpOfStringToString()).registeredServiceAccessStrategyEnforcer(mock(AuditableExecution.class)).serviceMatchingStrategy(new DefaultServiceMatchingStrategy(servicesManager)).lockRepository(LockRepository.asDefault()).build();
val cas = new DefaultCentralAuthenticationService(context);
cas.deleteTicket(tgt.getId());
}
use of org.apereo.cas.util.MockOnlyOneTicketRegistry in project cas by apereo.
the class CentralAuthenticationServiceImplTests method verifyDestroyRemoteRegistry.
/**
* This test checks that the TGT destruction happens properly for a remote registry.
* It previously failed when the deletion happens before the ticket was marked expired because an update was necessary for that.
*/
@Test
public void verifyDestroyRemoteRegistry() throws AbstractTicketException, AuthenticationException {
final MockOnlyOneTicketRegistry registry = new MockOnlyOneTicketRegistry();
final TicketGrantingTicketImpl tgt = new TicketGrantingTicketImpl("TGT-1", mock(Authentication.class), mock(ExpirationPolicy.class));
final LogoutManager logoutManager = mock(LogoutManager.class);
when(logoutManager.performLogout(any(TicketGrantingTicket.class))).thenAnswer(invocation -> {
tgt.markTicketExpired();
registry.updateTicket(tgt);
return null;
});
registry.addTicket(tgt);
final DefaultCentralAuthenticationService cas = new DefaultCentralAuthenticationService(mock(ApplicationEventPublisher.class), registry, null, logoutManager, null, null, null, null, null, mock(AuditableExecution.class));
cas.destroyTicketGrantingTicket(tgt.getId());
}
Aggregations