Search in sources :

Example 21 with MockWebServer

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

the class RestAuthenticationHandlerTests method verifyConditionFail.

@Test
public void verifyConditionFail() {
    try (val webServer = new MockWebServer(8081, HttpStatus.PRECONDITION_FAILED)) {
        webServer.start();
        assertThrows(AccountExpiredException.class, () -> authenticationHandler.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword()));
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with MockWebServer

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

the class RestAuthenticationHandlerTests method verifyLocked.

@Test
public void verifyLocked() {
    try (val webServer = new MockWebServer(8081, HttpStatus.LOCKED)) {
        webServer.start();
        assertThrows(AccountLockedException.class, () -> authenticationHandler.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword()));
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with MockWebServer

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

the class RestAuthenticationHandlerTests method verifyConditionReq.

@Test
public void verifyConditionReq() {
    try (val webServer = new MockWebServer(8081, HttpStatus.PRECONDITION_REQUIRED)) {
        webServer.start();
        assertThrows(AccountPasswordMustChangeException.class, () -> authenticationHandler.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword()));
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with MockWebServer

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

the class RestAuthenticationHandlerTests method verifyDisabledAccount.

@Test
public void verifyDisabledAccount() {
    try (val webServer = new MockWebServer(8081, HttpStatus.FORBIDDEN)) {
        webServer.start();
        assertThrows(AccountDisabledException.class, () -> authenticationHandler.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword()));
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with MockWebServer

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

the class SwivelTuringImageGeneratorControllerTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val bytes = IOUtils.toByteArray(new ClassPathResource("logo.png").getInputStream());
    try (val webServer = new MockWebServer(9991, new ByteArrayResource(bytes, "Output"), OK)) {
        webServer.start();
        val request = new MockHttpServletRequest();
        request.addParameter("principal", "casuser");
        val response = new MockHttpServletResponse();
        assertDoesNotThrow(new Executable() {

            @Override
            public void execute() throws Throwable {
                controller.generate(response, request);
            }
        });
    }
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Executable(org.junit.jupiter.api.function.Executable) ClassPathResource(org.springframework.core.io.ClassPathResource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) 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