use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class BasicDuoSecurityAuthenticationServiceTests method verifyPing.
@Test
public void verifyPing() throws Exception {
var entity = MAPPER.writeValueAsString(Map.of("stat", "OK", "response", "pong"));
try (val webServer = new MockWebServer(9310, new ByteArrayResource(entity.getBytes(UTF_8), "Output"), OK)) {
webServer.start();
val props = new DuoSecurityMultifactorAuthenticationProperties().setDuoApiHost("http://localhost:9310");
val service = new BasicDuoSecurityAuthenticationService(props, httpClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
assertTrue(service.ping());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class BasicDuoSecurityAuthenticationServiceTests method verifyAuthNDirect.
@Test
public void verifyAuthNDirect() throws Exception {
val service = new BasicDuoSecurityAuthenticationService(casProperties.getAuthn().getMfa().getDuo().get(0), httpClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
try (val webServer = new MockWebServer(6342)) {
webServer.start();
val creds = new DuoSecurityDirectCredential(RegisteredServiceTestUtils.getAuthentication().getPrincipal(), "mfa-duo");
assertFalse(service.authenticate(creds).isSuccess());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class OidcRestfulJsonWebKeystoreGeneratorServiceTests method setup.
@BeforeAll
public static void setup() {
val webKey = OidcJsonWebKeyStoreUtils.generateJsonWebKey("rsa", 2048, OidcJsonWebKeyUsage.SIGNING);
val data = webKey.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE);
SERVER = new MockWebServer(9521, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE);
SERVER.start();
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class OidcRestfulWebFingerUserInfoRepositoryTests method verifyFindByEmail.
@Test
public void verifyFindByEmail() throws Exception {
var data = MAPPER.writeValueAsString(CollectionUtils.wrap("email", "cas@example.org"));
try (val webServer = new MockWebServer(9312, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
this.webServer = webServer;
this.webServer.start();
assertTrue(this.webServer.isRunning());
val props = new RestEndpointProperties();
props.setUrl("http://localhost:9312");
val repo = new OidcRestfulWebFingerUserInfoRepository(props);
val results = repo.findByEmailAddress("cas@example.org");
assertNotNull(results);
assertTrue(results.containsKey("email"));
assertEquals("cas@example.org", results.get("email"));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulPasswordlessTokenRepositoryTests method verifySaveToken.
@Test
public void verifySaveToken() {
val data = "THE_TOKEN";
try (val webServer = new MockWebServer(9307, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val tokens = new CasConfigurationProperties().getAuthn().getPasswordless().getTokens();
tokens.getRest().setUrl("http://localhost:9307");
val passwordless = new RestfulPasswordlessTokenRepository(tokens.getExpireInSeconds(), tokens.getRest(), passwordlessCipherExecutor);
passwordless.saveToken("casuser", data);
}
}
Aggregations