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));
}
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);
}
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());
}
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));
}
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());
}
Aggregations