use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class CaptchaValidatorTests method verifySuccess.
@Test
public void verifySuccess() throws Exception {
val props = new GoogleRecaptchaProperties().setScore(.1).setSecret(UUID.randomUUID().toString()).setVerifyUrl("http://localhost:8812");
val validator = new GoogleCaptchaV2Validator(props);
val entity = MAPPER.writeValueAsString(Map.of("score", .5, "success", true));
try (val webServer = new MockWebServer(8812, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val response = UUID.randomUUID().toString();
assertTrue(validator.validate(response, "Mozilla/5.0"));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyFailOps.
@Test
public void verifyFailOps() throws Exception {
val props = new GoogleAuthenticatorMultifactorProperties();
props.getRest().setUrl("http://localhost:8551");
val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
val entity = MAPPER.writeValueAsString(List.of("----"));
try (val webServer = new MockWebServer(8551, new ByteArrayResource(entity.getBytes(UTF_8), "Output"), OK)) {
webServer.start();
assertNull(repo.get("casuser", 1));
assertNull(repo.get(1));
assertNull(repo.get("casuser"));
assertEquals(0, repo.count());
assertEquals(0, repo.count("casuser"));
assertNull(repo.update(null));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyLoad.
@Test
public void verifyLoad() throws Exception {
val props = new GoogleAuthenticatorMultifactorProperties();
props.getRest().setUrl("http://localhost:8551");
val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
val account = repo.create(UUID.randomUUID().toString());
val entity = MAPPER.writeValueAsString(CollectionUtils.wrapArrayList(account));
try (val webServer = new MockWebServer(8551, new ByteArrayResource(entity.getBytes(UTF_8), "Output"), OK)) {
webServer.start();
assertFalse(repo.load().isEmpty());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyGetById.
@Test
public void verifyGetById() throws Exception {
val props = new GoogleAuthenticatorMultifactorProperties();
props.getRest().setUrl("http://localhost:8552");
val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
val account = repo.create(UUID.randomUUID().toString());
val entity = MAPPER.writeValueAsString(account);
try (val webServer = new MockWebServer(8552, new ByteArrayResource(entity.getBytes(UTF_8), "Results"), OK)) {
webServer.start();
assertNotNull(repo.get(account.getId()));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyGet.
@Test
public void verifyGet() throws Exception {
val props = new GoogleAuthenticatorMultifactorProperties();
props.getRest().setUrl("http://localhost:8552");
val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
val account = repo.create(UUID.randomUUID().toString());
val entity = MAPPER.writeValueAsString(CollectionUtils.wrapList(account));
try (val webServer = new MockWebServer(8552, new ByteArrayResource(entity.getBytes(UTF_8), "Results"), OK)) {
webServer.start();
assertFalse(repo.get(account.getUsername()).isEmpty());
}
}
Aggregations