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);
}
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);
}
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);
}
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;
}
Aggregations