Search in sources :

Example 96 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class DynamoDbTicketRegistryTests method verifyAccessTokenCanBeAdded.

@RepeatedTest(2)
public void verifyAccessTokenCanBeAdded() throws Exception {
    val code = createOAuthCode();
    val jwtBuilder = new JwtBuilder(CipherExecutor.noOpOfSerializableToString(), servicesManager, RegisteredServiceCipherExecutor.noOp());
    val token = new OAuth20DefaultAccessTokenFactory(neverExpiresExpirationPolicyBuilder(), jwtBuilder, servicesManager).create(RegisteredServiceTestUtils.getService(), RegisteredServiceTestUtils.getAuthentication(), new MockTicketGrantingTicket("casuser"), CollectionUtils.wrapSet("1", "2"), code.getId(), "clientId1234567", new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
    newTicketRegistry.addTicket(token);
    assertSame(1, newTicketRegistry.deleteTicket(token.getId()), "Wrong ticket count");
    assertNull(newTicketRegistry.getTicket(token.getId()));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) JwtBuilder(org.apereo.cas.token.JwtBuilder) OAuth20DefaultAccessTokenFactory(org.apereo.cas.ticket.accesstoken.OAuth20DefaultAccessTokenFactory) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 97 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class EhCacheHealthIndicatorTests method verifyObserve.

@Test
public void verifyObserve() {
    var status = monitor.health();
    assertEquals(Status.UP, status.getStatus());
    /*
         * Fill cache 95% full, which is
         * above 10% free WARN threshold
         */
    IntStream.range(0, 95).forEach(Unchecked.intConsumer(i -> this.ticketRegistry.addTicket(new MockServiceTicket("ST-" + 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(Unchecked.intConsumer(i -> {
        val st = new MockServiceTicket("ST-" + i, RegisteredServiceTestUtils.getService(), new MockTicketGrantingTicket("test"));
        this.ticketRegistry.addTicket(st);
    }));
    status = monitor.health();
    assertEquals("WARN", status.getStatus().getCode());
}
Also used : IntStream(java.util.stream.IntStream) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) Autowired(org.springframework.beans.factory.annotation.Autowired) EhcacheTicketRegistryTicketCatalogConfiguration(org.apereo.cas.config.EhcacheTicketRegistryTicketCatalogConfiguration) CasWebApplicationServiceFactoryConfiguration(org.apereo.cas.config.support.CasWebApplicationServiceFactoryConfiguration) TicketRegistry(org.apereo.cas.ticket.registry.TicketRegistry) RefreshAutoConfiguration(org.springframework.cloud.autoconfigure.RefreshAutoConfiguration) CasCoreNotificationsConfiguration(org.apereo.cas.config.CasCoreNotificationsConfiguration) RegisteredServiceTestUtils(org.apereo.cas.services.RegisteredServiceTestUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Tag(org.junit.jupiter.api.Tag) EhCacheMonitorConfiguration(org.apereo.cas.monitor.config.EhCacheMonitorConfiguration) Status(org.springframework.boot.actuate.health.Status) CasCoreWebConfiguration(org.apereo.cas.config.CasCoreWebConfiguration) CasCoreHttpConfiguration(org.apereo.cas.config.CasCoreHttpConfiguration) CasCoreServicesConfiguration(org.apereo.cas.config.CasCoreServicesConfiguration) Unchecked(org.jooq.lambda.Unchecked) CasCoreTicketIdGeneratorsConfiguration(org.apereo.cas.config.CasCoreTicketIdGeneratorsConfiguration) lombok.val(lombok.val) EhcacheTicketRegistryConfiguration(org.apereo.cas.config.EhcacheTicketRegistryConfiguration) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) Test(org.junit.jupiter.api.Test) CasCoreTicketCatalogConfiguration(org.apereo.cas.config.CasCoreTicketCatalogConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions(org.junit.jupiter.api.Assertions) CasCoreTicketsConfiguration(org.apereo.cas.config.CasCoreTicketsConfiguration) CasCoreUtilConfiguration(org.apereo.cas.config.CasCoreUtilConfiguration) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) lombok.val(lombok.val) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 98 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class MemcachedTicketRegistryTests method verifyOAuthCodeIsAddedToMemcached.

@RepeatedTest(2)
public void verifyOAuthCodeIsAddedToMemcached() throws Exception {
    val factory = new OAuth20DefaultOAuthCodeFactory(neverExpiresExpirationPolicyBuilder(), servicesManager);
    val code = factory.create(RegisteredServiceTestUtils.getService(), CoreAuthenticationTestUtils.getAuthentication(), new MockTicketGrantingTicket("casuser"), CollectionUtils.wrapList("openid"), "code-challenge", "plain", "clientId123456", new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
    this.newTicketRegistry.addTicket(code);
    val ticket = this.newTicketRegistry.getTicket(code.getId(), OAuth20Code.class);
    assertNotNull(ticket);
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) OAuth20DefaultOAuthCodeFactory(org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 99 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class CasKryoTranscoderTests method internalProxyTest.

private void internalProxyTest() {
    val expectedTGT = new MockTicketGrantingTicket(USERNAME);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    val result = transcoder.encode(expectedTGT);
    assertEquals(expectedTGT, transcoder.decode(result));
    assertEquals(expectedTGT, transcoder.decode(result));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket)

Example 100 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class CasKryoTranscoderTests method verifyEncodeDecodeNonRegisteredClass.

@Test
public void verifyEncodeDecodeNonRegisteredClass() {
    val tgt = new MockTicketGrantingTicket(USERNAME);
    val expectedST = new MockServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), tgt);
    val step = new UnregisteredServiceTicketExpirationPolicy(1, 600);
    expectedST.setExpirationPolicy(step);
    try {
        transcoder.encode(expectedST);
        throw new AssertionError("Unregistered class is not allowed by Kryo");
    } catch (final KryoException e) {
        LOGGER.trace(e.getMessage(), e);
    } catch (final Exception e) {
        throw new AssertionError("Not resetting Kryo between de-serializations with unregistered class.");
    }
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) KryoException(com.esotericsoftware.kryo.KryoException) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) KryoException(com.esotericsoftware.kryo.KryoException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)224 lombok.val (lombok.val)199 Test (org.junit.jupiter.api.Test)164 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)93 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)92 MockRequestContext (org.springframework.webflow.test.MockRequestContext)42 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)39 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)36 JEEContext (org.pac4j.core.context.JEEContext)33 MockServletContext (org.springframework.mock.web.MockServletContext)33 HashMap (java.util.HashMap)31 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)18 Test (org.junit.Test)18 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)13 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)12 CasProfile (org.pac4j.cas.profile.CasProfile)11 Authentication (org.apereo.cas.authentication.Authentication)10 HardTimeoutExpirationPolicy (org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy)10 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)10 RedirectView (org.springframework.web.servlet.view.RedirectView)10