use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class SimpleHttpClientTests method verifyMessageSent.
@Test
public void verifyMessageSent() throws Exception {
try (val webServer = new MockWebServer(8165, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val result = getHttpClient().sendMessageToEndPoint(new URL("http://localhost:8165"));
assertNotNull(result);
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class JsonWebKeySetStringCipherExecutorTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val jwksKeystore = new ClassPathResource("sample.jwks");
val data = IOUtils.toString(jwksKeystore.getInputStream(), StandardCharsets.UTF_8);
val keystoreFile = getKeystoreFile();
try (val webServer = new MockWebServer(8435, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE);
val cipher = new JsonWebKeySetStringCipherExecutor(keystoreFile, "http://localhost:8435")) {
webServer.start();
val token = cipher.encode("Misagh");
assertEquals("Misagh", cipher.decode(token));
Files.setLastModifiedTime(keystoreFile.toPath(), FileTime.from(Instant.now()));
Thread.sleep(5_000);
cipher.destroy();
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestAuditTrailManagerTests method verifyGet.
@Test
public void verifyGet() throws Exception {
val audit = new AuditActionContext("casuser", "resource", "action", "CAS", new Date(), "123.456.789.000", "123.456.789.000", "GoogleChrome");
val data = MAPPER.writeValueAsString(CollectionUtils.wrapSet(audit));
try (val webServer = new MockWebServer(9296, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8)), HttpStatus.OK)) {
webServer.start();
assertTrue(webServer.isRunning());
auditTrailManager.record(audit);
val time = LocalDate.now(ZoneOffset.UTC).minusDays(2);
val results = auditTrailManager.getAuditRecordsSince(time);
assertFalse(results.isEmpty());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class DefaultDuoSecurityAdminApiServiceTests method verifyCodes.
@Test
public void verifyCodes() throws Exception {
val service = new DefaultDuoSecurityAdminApiService(this.httpClient, properties);
try (val webServer = new MockWebServer(8443)) {
webServer.responseBodySupplier(() -> new ClassPathResource("duoAdminApiResponse-bypassCodes.json"));
webServer.start();
val codes = service.getDuoSecurityBypassCodesFor("DU3RP9I2WOC59VZX672N");
assertFalse(codes.isEmpty());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class DuoSecurityAuthenticationServiceTests method verifyPingFails.
@Test
public void verifyPingFails() throws Exception {
val duoProperties = casProperties.getAuthn().getMfa().getDuo().get(0);
duoProperties.setDuoApiHost("http://localhost:6556");
val results = MAPPER.writeValueAsString(Map.of("response", "pong", "stat", "FAIL"));
val service = new BasicDuoSecurityAuthenticationService(duoProperties, httpClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
try (val webServer = new MockWebServer(6556, new ByteArrayResource(results.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
assertFalse(service.ping());
}
assertFalse(service.ping());
}
Aggregations