Search in sources :

Example 1 with RecaptchaResponse

use of eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse in project CzechIdMng by bcvsolutions.

the class DefaultRecaptchaServiceUnitTest method testNotValid2.

@Test()
public void testNotValid2() {
    RecaptchaResponse response = getRecaptchaResponse(TEST_HOSTNAME, false, "a");
    when(config.getSecretKey()).thenReturn(new GuardedString(TEST_SECRET_KEY));
    when(template.postForEntity(anyString(), any(), eq(RecaptchaResponse.class))).thenReturn(getResponse(response, HttpStatus.OK));
    try {
        service.checkRecaptcha(getRecaptchaRequest(TEST_REMOTE_IP, TEST_REQUEST));
    } catch (ResultCodeException O_o) {
        Assert.assertEquals(O_o.getStatus(), CoreResultCode.RECAPTCHA_CHECK_FAILED.getStatus());
    }
    verify(template).postForEntity(anyString(), any(), eq(RecaptchaResponse.class));
    verifyNoMoreInteractions(template);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RecaptchaTestUtil.getRecaptchaResponse(eu.bcvsolutions.idm.core.security.service.impl.RecaptchaTestUtil.getRecaptchaResponse) RecaptchaResponse(eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 2 with RecaptchaResponse

use of eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse in project CzechIdMng by bcvsolutions.

the class DefaultRecaptchaServiceUnitTest method testValid.

@Test()
public void testValid() {
    RecaptchaResponse response = getRecaptchaResponse(TEST_HOSTNAME, true);
    when(config.getSecretKey()).thenReturn(new GuardedString(TEST_SECRET_KEY));
    when(template.postForEntity(anyString(), any(), eq(RecaptchaResponse.class))).thenReturn(getResponse(response, HttpStatus.OK));
    RecaptchaResponse returned = service.checkRecaptcha(getRecaptchaRequest(TEST_REMOTE_IP, TEST_REQUEST));
    // 
    verify(template).postForEntity(anyString(), any(), eq(RecaptchaResponse.class));
    verifyNoMoreInteractions(template);
    Assert.assertNotNull(returned);
    Assert.assertEquals(returned.getHostname(), TEST_HOSTNAME);
}
Also used : RecaptchaTestUtil.getRecaptchaResponse(eu.bcvsolutions.idm.core.security.service.impl.RecaptchaTestUtil.getRecaptchaResponse) RecaptchaResponse(eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 3 with RecaptchaResponse

use of eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse in project CzechIdMng by bcvsolutions.

the class DefaultRecaptchaServiceUnitTest method testNotValid.

@Test()
public void testNotValid() {
    RecaptchaResponse response = getRecaptchaResponse(TEST_HOSTNAME, false, "a", "b");
    when(config.getSecretKey()).thenReturn(new GuardedString(TEST_SECRET_KEY));
    when(template.postForEntity(anyString(), any(), eq(RecaptchaResponse.class))).thenReturn(getResponse(response, HttpStatus.OK));
    try {
        service.checkRecaptcha(getRecaptchaRequest(TEST_REMOTE_IP, TEST_REQUEST));
    } catch (ResultCodeException O_o) {
        Assert.assertEquals(O_o.getStatus(), CoreResultCode.RECAPTCHA_CHECK_FAILED.getStatus());
    }
    verify(template).postForEntity(anyString(), any(), eq(RecaptchaResponse.class));
    verifyNoMoreInteractions(template);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RecaptchaTestUtil.getRecaptchaResponse(eu.bcvsolutions.idm.core.security.service.impl.RecaptchaTestUtil.getRecaptchaResponse) RecaptchaResponse(eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 4 with RecaptchaResponse

use of eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse in project CzechIdMng by bcvsolutions.

the class RecaptchaTestUtil method getRecaptchaResponse.

public static RecaptchaResponse getRecaptchaResponse(String hostName, boolean success, String... errorCodes) {
    final RecaptchaResponse response = new RecaptchaResponse();
    response.setErrorCodes(Arrays.asList(errorCodes));
    response.setHostname(hostName);
    response.setSuccess(success);
    return response;
}
Also used : RecaptchaResponse(eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse)

Aggregations

RecaptchaResponse (eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse)4 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)3 RecaptchaTestUtil.getRecaptchaResponse (eu.bcvsolutions.idm.core.security.service.impl.RecaptchaTestUtil.getRecaptchaResponse)3 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)3 Test (org.junit.Test)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2