Search in sources :

Example 1 with DefaultTicketDefinition

use of org.apereo.cas.ticket.DefaultTicketDefinition in project cas by apereo.

the class HazelcastTicketRegistryTests method verifyBadTicketInCatalog.

@RepeatedTest(1)
public void verifyBadTicketInCatalog() {
    val ticket = new MockTicketGrantingTicket("casuser");
    val instance = mock(HazelcastInstance.class);
    when(instance.getMap(anyString())).thenThrow(new RuntimeException());
    val catalog = mock(TicketCatalog.class);
    val defn = new DefaultTicketDefinition(ticket.getClass(), ticket.getPrefix(), 0);
    defn.getProperties().setStorageName("Tickets");
    when(catalog.find(any(Ticket.class))).thenReturn(defn);
    val registry = new HazelcastTicketRegistry(instance, catalog, 0);
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Exception {
            registry.addTicket(ticket);
        }
    });
    assertNull(registry.getTicket(ticket.getId()));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) DefaultTicketDefinition(org.apereo.cas.ticket.DefaultTicketDefinition) Executable(org.junit.jupiter.api.function.Executable) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 2 with DefaultTicketDefinition

use of org.apereo.cas.ticket.DefaultTicketDefinition in project cas by apereo.

the class MongoDbTicketRegistryTests method verifyBadTicketInCatalog.

@RepeatedTest(1)
public void verifyBadTicketInCatalog() throws Exception {
    val ticket = new MockTicketGrantingTicket("casuser");
    val catalog = mock(TicketCatalog.class);
    val defn = new DefaultTicketDefinition(ticket.getClass(), ticket.getPrefix(), 0);
    when(catalog.find(any(Ticket.class))).thenReturn(null);
    val mgr = mock(TicketSerializationManager.class);
    when(mgr.serializeTicket(any())).thenReturn("{}");
    val registry = new MongoDbTicketRegistry(catalog, mongoDbTicketRegistryTemplate, mgr);
    registry.addTicket(ticket);
    assertNull(registry.updateTicket(ticket));
    when(catalog.find(any(Ticket.class))).thenReturn(defn);
    defn.getProperties().setStorageName(null);
    registry.addTicket(ticket);
    assertNull(registry.updateTicket(ticket));
    when(catalog.find(any(Ticket.class))).thenThrow(new RuntimeException());
    defn.getProperties().setStorageName(null);
    registry.addTicket(ticket);
    assertNull(registry.updateTicket(ticket));
    when(catalog.find(anyString())).thenThrow(new RuntimeException());
    assertNull(registry.getTicket(ticket.getId()));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) DefaultTicketDefinition(org.apereo.cas.ticket.DefaultTicketDefinition) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Aggregations

lombok.val (lombok.val)2 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)2 DefaultTicketDefinition (org.apereo.cas.ticket.DefaultTicketDefinition)2 Ticket (org.apereo.cas.ticket.Ticket)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 Executable (org.junit.jupiter.api.function.Executable)1