Search in sources :

Example 46 with MockTicketGrantingTicket

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

the class TokenWebApplicationServiceResponseBuilderTests method verifyTokenBuilder.

@Test
public void verifyTokenBuilder() throws Exception {
    val service = CoreAuthenticationTestUtils.getWebApplicationService("jwtservice");
    val user = UUID.randomUUID().toString();
    val authentication = CoreAuthenticationTestUtils.getAuthentication(user);
    val tgt = new MockTicketGrantingTicket(authentication);
    val st = new MockServiceTicket("ST-123456", service, tgt);
    cas.addTicket(tgt);
    cas.addTicket(st);
    val result = responseBuilder.build(service, st.getId(), authentication);
    assertNotNull(result);
    assertTrue(result.getAttributes().containsKey(CasProtocolConstants.PARAMETER_TICKET));
    val ticket = result.getAttributes().get(CasProtocolConstants.PARAMETER_TICKET);
    assertNotNull(JWTParser.parse(ticket));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 47 with MockTicketGrantingTicket

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

the class JwtBuilderTests method verifyZonedDateTimeWorks.

@Test
public void verifyZonedDateTimeWorks() {
    val tgt = new MockTicketGrantingTicket("casuser");
    val jwt = tokenTicketBuilder.build(tgt, Map.of("date-time", List.of(ZonedDateTime.now(Clock.systemUTC()))));
    assertNotNull(jwt);
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Test(org.junit.jupiter.api.Test)

Example 48 with MockTicketGrantingTicket

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

the class ServiceWarningActionTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.addParameter(ServiceWarningAction.PARAMETER_NAME_IGNORE_WARNING, "true");
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    assertThrows(InvalidTicketException.class, () -> action.execute(context).getId());
    val tgt = new MockTicketGrantingTicket("casuser");
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    assertThrows(InvalidTicketException.class, () -> action.execute(context).getId());
    val service = RegisteredServiceTestUtils.getService("https://google.com");
    getServicesManager().save(RegisteredServiceTestUtils.getRegisteredService(service.getId(), Map.of()));
    WebUtils.putServiceIntoFlowScope(context, service);
    WebUtils.putCredential(context, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
    getTicketRegistry().addTicket(tgt);
    assertEquals(CasWebflowConstants.STATE_ID_REDIRECT, action.execute(context).getId());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 49 with MockTicketGrantingTicket

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

the class VerifyRequiredServiceActionTests method verifySkipWithSsoServicesMismatch.

@Test
public void verifySkipWithSsoServicesMismatch() {
    val service = RegisteredServiceTestUtils.getRegisteredService("^https://app2.com.+");
    getServicesManager().save(service);
    WebUtils.putServiceIntoFlowScope(this.requestContext, RegisteredServiceTestUtils.getService("https://app2.com/"));
    val tgt = new MockTicketGrantingTicket("casuser");
    tgt.grantServiceTicket(RegisteredServiceTestUtils.getService("https://google.com/"));
    when(ticketRegistrySupport.getTicketGrantingTicket(anyString())).thenReturn(tgt);
    this.httpRequest.setCookies(new Cookie(casProperties.getTgc().getName(), tgt.getId()));
    assertThrows(NoSuchFlowExecutionException.class, () -> verifyRequiredServiceAction.execute(this.requestContext));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Cookie(javax.servlet.http.Cookie) Test(org.junit.jupiter.api.Test)

Example 50 with MockTicketGrantingTicket

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

the class VerifyRequiredServiceActionTests method verifySkipNoSsoServices.

@Test
public void verifySkipNoSsoServices() throws Exception {
    val service = RegisteredServiceTestUtils.getRegisteredService("^https://app1.com.+");
    getServicesManager().save(service);
    WebUtils.putServiceIntoFlowScope(this.requestContext, RegisteredServiceTestUtils.getService("https://app1.com/"));
    val tgt = new MockTicketGrantingTicket("casuser");
    when(ticketRegistrySupport.getTicketGrantingTicket(anyString())).thenReturn(tgt);
    this.httpRequest.setCookies(new Cookie(casProperties.getTgc().getName(), tgt.getId()));
    val result = verifyRequiredServiceAction.execute(this.requestContext);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, result.getId());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Cookie(javax.servlet.http.Cookie) Test(org.junit.jupiter.api.Test)

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