use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class CasKryoTranscoderTests method verifySTWithServiceTicketExpirationPolicy.
@Test
public void verifySTWithServiceTicketExpirationPolicy() {
// ServiceTicketExpirationPolicy is not registered with Kryo...
transcoder.getKryo().getClassResolver().reset();
final TicketGrantingTicket tgt = new MockTicketGrantingTicket(USERNAME);
final MockServiceTicket expectedST = new MockServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), tgt);
final MultiTimeUseOrTimeoutExpirationPolicy.ServiceTicketExpirationPolicy step = new MultiTimeUseOrTimeoutExpirationPolicy.ServiceTicketExpirationPolicy(1, 600);
expectedST.setExpiration(step);
final CachedData result = transcoder.encode(expectedST);
assertEquals(expectedST, transcoder.decode(result));
// Test it a second time - Ensure there's no problem with subsequent de-serializations.
assertEquals(expectedST, transcoder.decode(result));
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithLinkedHashMap.
@Test
public void verifyEncodeDecodeTGTWithLinkedHashMap() {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, new LinkedHashMap<>(this.principalAttributes));
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
final CachedData result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeNonRegisteredClass.
@Test
public void verifyEncodeDecodeNonRegisteredClass() {
final TicketGrantingTicket tgt = new MockTicketGrantingTicket(USERNAME);
final MockServiceTicket expectedST = new MockServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), tgt);
// This class is not registered with Kryo
final UnregisteredServiceTicketExpirationPolicy step = new UnregisteredServiceTicketExpirationPolicy(1, 600);
expectedST.setExpiration(step);
try {
transcoder.encode(expectedST);
throw new AssertionError("Unregistered class is not allowed by Kryo");
} catch (final KryoException e) {
} catch (final Exception e) {
throw new AssertionError("Unexpected exception due to not resetting Kryo between de-serializations with unregistered class.");
}
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class EhCacheHealthIndicatorTests method verifyObserve.
@Test
public void verifyObserve() {
Health status = monitor.health();
assertEquals(Status.UP, status.getStatus());
// Fill cache 95% full, which is above 10% free WARN threshold
IntStream.range(0, 95).forEach(i -> this.ticketRegistry.addTicket(new MockServiceTicket("T" + i, RegisteredServiceTestUtils.getService(), new MockTicketGrantingTicket("test"))));
status = monitor.health();
assertEquals(Status.OUT_OF_SERVICE, status.getStatus());
// Exceed the capacity and force evictions which should report WARN status
IntStream.range(95, 110).forEach(i -> {
final MockServiceTicket st = new MockServiceTicket("T" + i, RegisteredServiceTestUtils.getService(), new MockTicketGrantingTicket("test"));
this.ticketRegistry.addTicket(st);
});
status = monitor.health();
assertEquals("WARN", status.getStatus().getCode());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class TicketGrantingTicketCheckActionTests method verifyInvalidTicket.
@Test
public void verifyInvalidTicket() throws Exception {
final MockRequestContext ctx = new MockRequestContext();
final MockTicketGrantingTicket tgt = new MockTicketGrantingTicket("user");
WebUtils.putTicketGrantingTicketInScopes(ctx, tgt);
final TicketGrantingTicketCheckAction action = new TicketGrantingTicketCheckAction(this.getCentralAuthenticationService());
final Event event = action.doExecute(ctx);
assertEquals(TicketGrantingTicketCheckAction.INVALID, event.getId());
}
Aggregations