Search in sources :

Example 11 with GoogleRecaptchaProperties

use of org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties in project cas by apereo.

the class GoogleCaptchaV3ValidatorTests method verifyOperation.

@Test
public void verifyOperation() {
    val props = new GoogleRecaptchaProperties().setScore(.1).setSecret(UUID.randomUUID().toString()).setVerifyUrl("http://localhost:8812");
    val validator = new GoogleCaptchaV3Validator(props);
    val request = new MockHttpServletRequest();
    request.addParameter(GoogleCaptchaV3Validator.REQUEST_PARAM_RECAPTCHA_TOKEN, UUID.randomUUID().toString());
    assertNotNull(validator.getRecaptchaResponse(request));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) GoogleRecaptchaProperties(org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties) Test(org.junit.jupiter.api.Test)

Example 12 with GoogleRecaptchaProperties

use of org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties in project cas by apereo.

the class CaptchaValidatorTests method verifyBadResponse.

@Test
public void verifyBadResponse() {
    val secret = UUID.randomUUID().toString();
    val props = new GoogleRecaptchaProperties().setScore(1).setSecret(secret).setVerifyUrl("http://localhost:8812");
    val validator = new GoogleCaptchaV2Validator(props);
    try (val webServer = new MockWebServer(8812, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val response = UUID.randomUUID().toString();
        assertFalse(validator.validate(response, "Mozilla/5.0"));
    }
}
Also used : lombok.val(lombok.val) GoogleRecaptchaProperties(org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)12 GoogleRecaptchaProperties (org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties)12 Test (org.junit.jupiter.api.Test)12 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 MockWebServer (org.apereo.cas.util.MockWebServer)4 ByteArrayResource (org.springframework.core.io.ByteArrayResource)4 Service (org.apereo.cas.authentication.principal.Service)2 DefaultRegisteredServiceProperty (org.apereo.cas.services.DefaultRegisteredServiceProperty)2 ServicesManager (org.apereo.cas.services.ServicesManager)2 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)2 MockRequestContext (org.springframework.webflow.test.MockRequestContext)2 HashMap (java.util.HashMap)1 OneTimeTokenCredential (org.apereo.cas.authentication.credential.OneTimeTokenCredential)1 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)1 MockServletContext (org.apereo.cas.util.MockServletContext)1 GoogleCaptchaV2Validator (org.apereo.cas.web.GoogleCaptchaV2Validator)1 Executable (org.junit.jupiter.api.function.Executable)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1