Search in sources :

Example 11 with MockWebServer

use of org.apereo.cas.util.MockWebServer 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"));
    }
}
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)

Example 12 with MockWebServer

use of org.apereo.cas.util.MockWebServer in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyFailOps.

@Test
public void verifyFailOps() throws Exception {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8551");
    val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
    val entity = MAPPER.writeValueAsString(List.of("----"));
    try (val webServer = new MockWebServer(8551, new ByteArrayResource(entity.getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        assertNull(repo.get("casuser", 1));
        assertNull(repo.get(1));
        assertNull(repo.get("casuser"));
        assertEquals(0, repo.count());
        assertEquals(0, repo.count("casuser"));
        assertNull(repo.update(null));
    }
}
Also used : lombok.val(lombok.val) GoogleAuthenticatorMultifactorProperties(org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with MockWebServer

use of org.apereo.cas.util.MockWebServer in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyLoad.

@Test
public void verifyLoad() throws Exception {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8551");
    val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
    val account = repo.create(UUID.randomUUID().toString());
    val entity = MAPPER.writeValueAsString(CollectionUtils.wrapArrayList(account));
    try (val webServer = new MockWebServer(8551, new ByteArrayResource(entity.getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        assertFalse(repo.load().isEmpty());
    }
}
Also used : lombok.val(lombok.val) GoogleAuthenticatorMultifactorProperties(org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with MockWebServer

use of org.apereo.cas.util.MockWebServer in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyGetById.

@Test
public void verifyGetById() throws Exception {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8552");
    val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
    val account = repo.create(UUID.randomUUID().toString());
    val entity = MAPPER.writeValueAsString(account);
    try (val webServer = new MockWebServer(8552, new ByteArrayResource(entity.getBytes(UTF_8), "Results"), OK)) {
        webServer.start();
        assertNotNull(repo.get(account.getId()));
    }
}
Also used : lombok.val(lombok.val) GoogleAuthenticatorMultifactorProperties(org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with MockWebServer

use of org.apereo.cas.util.MockWebServer in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyGet.

@Test
public void verifyGet() throws Exception {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8552");
    val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
    val account = repo.create(UUID.randomUUID().toString());
    val entity = MAPPER.writeValueAsString(CollectionUtils.wrapList(account));
    try (val webServer = new MockWebServer(8552, new ByteArrayResource(entity.getBytes(UTF_8), "Results"), OK)) {
        webServer.start();
        assertFalse(repo.get(account.getUsername()).isEmpty());
    }
}
Also used : lombok.val(lombok.val) GoogleAuthenticatorMultifactorProperties(org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MockWebServer (org.apereo.cas.util.MockWebServer)175 lombok.val (lombok.val)173 Test (org.junit.jupiter.api.Test)157 ByteArrayResource (org.springframework.core.io.ByteArrayResource)151 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)82 MockRequestContext (org.springframework.webflow.test.MockRequestContext)36 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)32 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)31 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)26 MockServletContext (org.springframework.mock.web.MockServletContext)25 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)15 ClassPathResource (org.springframework.core.io.ClassPathResource)15 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)13 GoogleAuthenticatorMultifactorProperties (org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties)10 AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)9 Executable (org.junit.jupiter.api.function.Executable)8 RestEndpointProperties (org.apereo.cas.configuration.model.RestEndpointProperties)7 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)7 Service (org.apereo.cas.authentication.principal.Service)4 GoogleRecaptchaProperties (org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties)4