Search in sources :

Example 1 with GoogleCaptchaV2Validator

use of org.apereo.cas.web.GoogleCaptchaV2Validator 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());
    }
}
Also used : lombok.val(lombok.val) GoogleCaptchaV2Validator(org.apereo.cas.web.GoogleCaptchaV2Validator) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) GoogleRecaptchaProperties(org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties) MockWebServer(org.apereo.cas.util.MockWebServer) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)1 GoogleRecaptchaProperties (org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties)1 MockWebServer (org.apereo.cas.util.MockWebServer)1 GoogleCaptchaV2Validator (org.apereo.cas.web.GoogleCaptchaV2Validator)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1 MockRequestContext (org.springframework.webflow.test.MockRequestContext)1