use of org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties 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.configuration.model.support.captcha.GoogleRecaptchaProperties in project cas by apereo.
the class GoogleCaptchaV2ValidatorTests method verifyOperation.
@Test
public void verifyOperation() {
val props = new GoogleRecaptchaProperties().setScore(.1).setSecret(UUID.randomUUID().toString()).setVerifyUrl("http://localhost:8812");
val validator = new GoogleCaptchaV2Validator(props);
val request = new MockHttpServletRequest();
request.addParameter(GoogleCaptchaV2Validator.REQUEST_PARAM_RECAPTCHA_RESPONSE, UUID.randomUUID().toString());
assertNotNull(validator.getRecaptchaResponse(request));
}
use of org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties in project cas by apereo.
the class HCaptchaValidatorTests method verifyOperation.
@Test
public void verifyOperation() {
val props = new GoogleRecaptchaProperties().setScore(.1).setSecret(UUID.randomUUID().toString()).setVerifyUrl("http://localhost:8812");
val validator = new HCaptchaValidator(props);
val request = new MockHttpServletRequest();
request.addParameter(HCaptchaValidator.REQUEST_PARAM_HCAPTCHA_RESPONSE, UUID.randomUUID().toString());
assertNotNull(validator.getRecaptchaResponse(request));
}
use of org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties in project cas by apereo.
the class WebUtilsTests method verifyOperation.
@Test
public void verifyOperation() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val flow = new Flow("mockFlow");
val flowSession = new MockFlowSession(flow);
flowSession.setParent(new MockFlowSession(flow));
val mockExecutionContext = new MockFlowExecutionContext(flowSession);
context.setFlowExecutionContext(mockExecutionContext);
WebUtils.putLogoutRedirectUrl(context, URL);
assertNotNull(WebUtils.getLogoutRedirectUrl(context, String.class));
WebUtils.removeLogoutRedirectUrl(context);
assertNull(WebUtils.getLogoutRedirectUrl(context, String.class));
assertNull(WebUtils.getHttpServletRequestUserAgentFromRequestContext(context));
assertNull(WebUtils.getHttpServletRequestUserAgentFromRequestContext(request));
assertNull(WebUtils.getAuthenticationResult(context));
assertNull(WebUtils.getHttpServletRequestGeoLocationFromRequestContext());
assertNull(WebUtils.getAcceptableUsagePolicyTermsFromFlowScope(context, Object.class));
assertFalse(WebUtils.hasSurrogateAuthenticationRequest(context));
assertNotNull(WebUtils.produceUnauthorizedErrorView(new RuntimeException()));
assertNotNull(WebUtils.produceErrorView(new IllegalArgumentException()));
assertNotNull(WebUtils.produceErrorView("error-view", new IllegalArgumentException()));
assertNotNull(WebUtils.getHttpRequestFullUrl(context));
request.setQueryString("param=value");
assertNotNull(WebUtils.getHttpRequestFullUrl(request));
assertFalse(WebUtils.isGraphicalUserAuthenticationEnabled(context));
assertTrue(WebUtils.getDelegatedAuthenticationProviderConfigurations(context).isEmpty());
assertNull(WebUtils.getAvailableAuthenticationHandleNames(context));
assertDoesNotThrow(new Executable() {
@Override
public void execute() {
WebUtils.putYubiKeyMultipleDeviceRegistrationEnabled(context, true);
WebUtils.putInitialHttpRequestPostParameters(context);
WebUtils.putExistingSingleSignOnSessionAvailable(context, true);
WebUtils.putExistingSingleSignOnSessionPrincipal(context, CoreAuthenticationTestUtils.getPrincipal());
WebUtils.putAvailableAuthenticationHandleNames(context, List.of());
WebUtils.putPasswordManagementEnabled(context, true);
WebUtils.putRecaptchaPropertiesFlowScope(context, new GoogleRecaptchaProperties().setEnabled(true));
WebUtils.putLogoutUrls(context, Map.of());
val ac = OneTimeTokenAccount.builder().validationCode(123456).username("casuser").name("Example").build();
WebUtils.putOneTimeTokenAccount(context, ac);
assertNotNull(WebUtils.getOneTimeTokenAccount(context, OneTimeTokenAccount.class));
WebUtils.putOneTimeTokenAccounts(context, List.of(ac));
WebUtils.putWarnCookieIfRequestParameterPresent(null, context);
WebUtils.putTicketGrantingTicketInScopes(context, "ticket-id");
}
});
WebUtils.putCredential(context, new UsernamePasswordCredential("casuser", "password"));
assertThrows(ClassCastException.class, () -> WebUtils.getCredential(context, OneTimeTokenCredential.class));
WebUtils.putTicketGrantingTicketInScopes(context, StringUtils.EMPTY);
WebUtils.putTicketGrantingTicketInScopes(context, (TicketGrantingTicket) null);
WebUtils.putTicketGrantingTicketInScopes(context, (String) null);
assertNull(WebUtils.getTicketGrantingTicket(context));
assertThrows(IllegalArgumentException.class, () -> WebUtils.getPrincipalFromRequestContext(context, null));
request.addParameter(WebUtils.PUBLIC_WORKSTATION_ATTRIBUTE, "true");
WebUtils.putPublicWorkstationToFlowIfRequestParameterPresent(context);
assertTrue(WebUtils.isAuthenticatingAtPublicWorkstation(context));
val ticketRegistrySupport = mock(TicketRegistrySupport.class);
WebUtils.putTicketGrantingTicketInScopes(context, "TGT-XYZ123");
assertNull(WebUtils.getPrincipalFromRequestContext(context, ticketRegistrySupport));
WebUtils.putLogoutPostUrl(context, URL);
assertEquals(URL, WebUtils.getLogoutPostUrl(context));
val data = new HashMap<String, Object>();
data.put("SAMLResponse", "xxx");
WebUtils.putLogoutPostData(context, data);
assertEquals(data, WebUtils.getLogoutPostData(context));
}
use of org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties in project cas by apereo.
the class DefaultCaptchaActivationStrategyTests method verifyByIpPatternPerService.
@Test
public void verifyByIpPatternPerService() {
val servicesManager = mock(ServicesManager.class);
val strategy = new DefaultCaptchaActivationStrategy(servicesManager);
val request = new MockHttpServletRequest();
val context = getRequestContext(request);
request.setRemoteAddr("185.86.151.99");
request.setLocalAddr("195.88.151.11");
ClientInfoHolder.setClientInfo(new ClientInfo(request));
val service = RegisteredServiceTestUtils.getService(UUID.randomUUID().toString());
val registeredService = RegisteredServiceTestUtils.getRegisteredService(service.getId());
registeredService.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.CAPTCHA_ENABLED.getPropertyName(), new DefaultRegisteredServiceProperty("true"));
registeredService.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.CAPTCHA_IP_ADDRESS_PATTERN.getPropertyName(), new DefaultRegisteredServiceProperty("no-match1", "no-match2", "\\d\\d\\.8.+\\.99"));
when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
WebUtils.putServiceIntoFlowScope(context, service);
val properties = new GoogleRecaptchaProperties().setEnabled(false);
assertTrue(strategy.shouldActivate(context, properties).isPresent());
}
Aggregations