Search in sources :

Example 16 with MockTicketGrantingTicket

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));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) CachedData(net.spy.memcached.CachedData) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) MultiTimeUseOrTimeoutExpirationPolicy(org.apereo.cas.ticket.support.MultiTimeUseOrTimeoutExpirationPolicy) Test(org.junit.Test)

Example 17 with MockTicketGrantingTicket

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));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) CachedData(net.spy.memcached.CachedData) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test)

Example 18 with MockTicketGrantingTicket

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.");
    }
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) KryoException(com.esotericsoftware.kryo.KryoException) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) KryoException(com.esotericsoftware.kryo.KryoException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) Test(org.junit.Test)

Example 19 with MockTicketGrantingTicket

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());
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Health(org.springframework.boot.actuate.health.Health) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with MockTicketGrantingTicket

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());
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) TicketGrantingTicketCheckAction(org.apereo.cas.web.flow.login.TicketGrantingTicketCheckAction) Test(org.junit.Test)

Aggregations

MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)35 Test (org.junit.Test)30 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)21 Credential (org.apereo.cas.authentication.Credential)16 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)16 HashMap (java.util.HashMap)10 CachedData (net.spy.memcached.CachedData)10 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)9 Authentication (org.apereo.cas.authentication.Authentication)8 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)8 LinkedHashMap (java.util.LinkedHashMap)6 Principal (org.apereo.cas.authentication.principal.Principal)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)5 AlwaysExpiresExpirationPolicy (org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy)5 Service (org.apereo.cas.authentication.principal.Service)4 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)4 RegisteredService (org.apereo.cas.services.RegisteredService)4 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)4