use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class BlackDotIPAddressIntelligenceServiceTests method verifyErrorStatusOperation.
@Test
public void verifyErrorStatusOperation() throws Exception {
val data = MAPPER.writeValueAsString(Collections.singletonMap("status", "error"));
try (val webServer = new MockWebServer(9356, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getBlackDot().setUrl("http://localhost:9356?ip=%s");
props.getIpIntel().getBlackDot().setEmailAddress("cas@apereo.org");
val service = new BlackDotIPAddressIntelligenceService(props);
val response = service.examine(new MockRequestContext(), "37.58.59.181");
assertTrue(response.isBanned());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class BlackDotIPAddressIntelligenceServiceTests method verifySuccessStatus.
@Test
public void verifySuccessStatus() throws Exception {
val data = MAPPER.writeValueAsString(CollectionUtils.wrap("status", "success", "result", 0));
try (val webServer = new MockWebServer(9358, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getBlackDot().setUrl("http://localhost:9358?ip=%s");
props.getIpIntel().getBlackDot().setEmailAddress("cas@apereo.org");
val service = new BlackDotIPAddressIntelligenceService(props);
val response = service.examine(new MockRequestContext(), "37.58.59.181");
assertFalse(response.isBanned());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class ValidateCaptchaActionTests method verifyCaptchaFails.
@Test
public void verifyCaptchaFails() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
try (val webServer = new MockWebServer(9305, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val props = new GoogleRecaptchaProperties().setVerifyUrl("http://localhost:9305");
val validateAction = new ValidateCaptchaAction(new GoogleCaptchaV2Validator(props), captchaActivationStrategy);
val result = validateAction.execute(context);
assertNotNull(result);
assertEquals(CasWebflowConstants.TRANSITION_ID_CAPTCHA_ERROR, result.getId());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class ValidateCaptchaActionTests method verifyCaptchaValidated.
@Test
public void verifyCaptchaValidated() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val data = "{\"success\": true }";
request.addParameter(GoogleCaptchaV2Validator.REQUEST_PARAM_RECAPTCHA_RESPONSE, data);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
try (val webServer = new MockWebServer(9294, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val result = validateCaptchaAction.execute(context);
assertNull(result);
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class CaptchaValidatorTests method verifyLowScore.
@Test
public void verifyLowScore() throws Exception {
val secret = UUID.randomUUID().toString();
val props = new GoogleRecaptchaProperties().setScore(1).setSecret(secret).setVerifyUrl("http://localhost:8812");
val validator = new GoogleCaptchaV2Validator(props);
val entity = MAPPER.writeValueAsString(Map.of("score", .5));
try (val webServer = new MockWebServer(8812, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val response = UUID.randomUUID().toString();
assertFalse(validator.validate(response, "Mozilla/5.0"));
}
}
Aggregations