Search in sources :

Example 66 with MockWebServer

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

the class RestfulPasswordlessTokenRepositoryTests method verifyClean.

@Test
public void verifyClean() {
    try (val webServer = new MockWebServer(9293, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        passwordlessTokenRepository.clean();
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 67 with MockWebServer

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

the class RestfulPasswordlessTokenRepositoryTests method verifyFindTokenFails.

@Test
public void verifyFindTokenFails() {
    try (val webServer = new MockWebServer(9306, new ByteArrayResource("token".getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val tokens = new CasConfigurationProperties().getAuthn().getPasswordless().getTokens();
        tokens.getRest().setUrl("http://localhost:9306");
        val passwordless = new RestfulPasswordlessTokenRepository(tokens.getExpireInSeconds(), tokens.getRest(), passwordlessCipherExecutor);
        val foundToken = passwordless.findToken("casuser");
        assertTrue(foundToken.isEmpty());
    }
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 68 with MockWebServer

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

the class RestfulPasswordlessTokenRepositoryTests method verifyDeleteToken.

@Test
public void verifyDeleteToken() {
    try (val webServer = new MockWebServer(9293, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        passwordlessTokenRepository.deleteToken("casuser", "123456");
        passwordlessTokenRepository.deleteTokens("casuser");
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 69 with MockWebServer

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

the class ClickatellSmsSenderTests method verifyError.

@Test
public void verifyError() {
    val data = '{' + "\"messages\": [" + "]," + "\"error\": \"error message\"," + "\"accepted\": \"false\"" + '}';
    try (val webServer = new MockWebServer(8099, new ByteArrayResource(data.getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        assertFalse(smsSender.send("123-456-7890", "123-456-7890", "TEST"));
    }
}
Also used : lombok.val(lombok.val) 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 70 with MockWebServer

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

the class SmsModeSmsSenderTests method verifyOperation.

@Test
public void verifyOperation() {
    assertNotNull(smsSender);
    assertFalse(smsSender.send("123-456-7890", "123-456-7890", "TEST"));
    try (val webServer = new MockWebServer(8099, new ByteArrayResource("0".getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        assertTrue(smsSender.send("123-456-7890", "123-456-7890", "TEST"));
    }
}
Also used : lombok.val(lombok.val) 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