use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class CreateTicketGrantingTicketActionTests method verifySkipTgt.
@Test
public void verifySkipTgt() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val tgt = new MockTicketGrantingTicket("casuser-new");
getTicketRegistry().addTicket(tgt);
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
WebUtils.putRegisteredService(context, RegisteredServiceTestUtils.getRegisteredService());
prepareRequestContextForAuthentication(context, tgt.getAuthentication());
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, action.execute(context).getId());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket 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()));
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class QRAuthenticationChannelControllerTests method verifyFails.
@Test
public void verifyFails() throws Exception {
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
val payload = JwtBuilder.JwtRequest.builder().subject("unknown-user").jwtId(tgt.getId()).issuer(casProperties.getServer().getPrefix()).serviceAudience("https://example.com/normal/").validUntilDate(DateTimeUtils.dateOf(LocalDate.now(Clock.systemUTC()).plusDays(1))).build();
val jwt = jwtBuilder.build(payload);
val message = mock(Message.class);
val nativeHeaders = new LinkedMultiValueMap<>();
nativeHeaders.put(QRAuthenticationConstants.QR_AUTHENTICATION_CHANNEL_ID, List.of(UUID.randomUUID().toString()));
nativeHeaders.put(QRAuthenticationConstants.QR_AUTHENTICATION_DEVICE_ID, List.of(UUID.randomUUID().toString()));
val headers = new MessageHeaders(Map.of("nativeHeaders", nativeHeaders));
when(message.getHeaders()).thenReturn(headers);
val token = String.format("{\"token\": \"%s\"}", jwt);
when(message.getPayload()).thenReturn(token);
assertFalse(qrAuthenticationChannelController.verify(message));
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class DefaultQRAuthenticationTokenValidatorServiceTests method verifySuccess.
@Test
public void verifySuccess() throws Exception {
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
val deviceId = UUID.randomUUID().toString();
qrAuthenticationDeviceRepository.authorizeDeviceFor(deviceId, tgt.getAuthentication().getPrincipal().getId());
val payload = JwtBuilder.JwtRequest.builder().subject(tgt.getAuthentication().getPrincipal().getId()).jwtId(tgt.getId()).issuer(casProperties.getServer().getPrefix()).serviceAudience("https://example.com/normal/").validUntilDate(DateTimeUtils.dateOf(LocalDate.now(Clock.systemUTC()).plusDays(1))).attributes(Map.of(QRAuthenticationConstants.QR_AUTHENTICATION_DEVICE_ID, List.of(deviceId))).build();
val jwt = jwtBuilder.build(payload);
val request = QRAuthenticationTokenValidationRequest.builder().registeredService(Optional.empty()).token(jwt).deviceId(deviceId).build();
val res = qrAuthenticationTokenValidatorService.validate(request);
assertNotNull(res.getAuthentication());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class DefaultQRAuthenticationTokenValidatorServiceTests method verifyBadDeviceId.
@Test
public void verifyBadDeviceId() throws Exception {
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
val deviceId = UUID.randomUUID().toString();
qrAuthenticationDeviceRepository.authorizeDeviceFor(deviceId, tgt.getAuthentication().getPrincipal().getId());
val payload = JwtBuilder.JwtRequest.builder().subject(tgt.getAuthentication().getPrincipal().getId()).jwtId(tgt.getId()).issuer(casProperties.getServer().getPrefix()).serviceAudience("https://example.com/normal/").validUntilDate(DateTimeUtils.dateOf(LocalDate.now(Clock.systemUTC()).plusDays(1))).attributes(Map.of(QRAuthenticationConstants.QR_AUTHENTICATION_DEVICE_ID, List.of("mismatch"))).build();
val jwt = jwtBuilder.build(payload);
val request = QRAuthenticationTokenValidationRequest.builder().registeredService(Optional.empty()).token(jwt).deviceId(deviceId).build();
assertThrows(AuthenticationException.class, () -> qrAuthenticationTokenValidatorService.validate(request));
}
Aggregations