Search in sources :

Example 41 with MockWebServer

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

the class AccepttoMultifactorAuthenticationHandlerTests method verifyOperationApproved.

@Test
public void verifyOperationApproved() throws Exception {
    val data = MAPPER.writeValueAsString(CollectionUtils.wrap("device_id", "deviceid-test", "status", "approved"));
    try (val webServer = new MockWebServer(5002, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val handler = buildHandler();
        val credential = new AccepttoMultifactorTokenCredential("test-channel");
        assertTrue(handler.supports(credential));
        assertTrue(handler.supports(AccepttoMultifactorTokenCredential.class));
        val result = handler.authenticate(credential);
        assertNotNull(result.getPrincipal());
    }
}
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 42 with MockWebServer

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

the class RestfulAccountRegistrationProvisionerTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    try (val webServer = new MockWebServer(5002, HttpStatus.OK)) {
        webServer.start();
        val registrationRequest = new AccountRegistrationRequest(Map.of("username", "casuser"));
        val results = accountMgmtRegistrationProvisioner.provision(registrationRequest);
        assertTrue(results.isSuccess());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) AccountRegistrationRequest(org.apereo.cas.acct.AccountRegistrationRequest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 43 with MockWebServer

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

the class RestfulAccountRegistrationProvisionerTests method verifyOperationFails.

@Test
public void verifyOperationFails() throws Exception {
    try (val webServer = new MockWebServer(5002, HttpStatus.INTERNAL_SERVER_ERROR)) {
        webServer.start();
        val registrationRequest = new AccountRegistrationRequest(Map.of("username", "casuser"));
        val results = accountMgmtRegistrationProvisioner.provision(registrationRequest);
        assertFalse(results.isSuccess());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) AccountRegistrationRequest(org.apereo.cas.acct.AccountRegistrationRequest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 44 with MockWebServer

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

the class RestfulCloudConfigBootstrapConfigurationTests method setup.

@BeforeAll
public static void setup() throws Exception {
    val response = MAPPER.writeValueAsString(Map.of("cas.authn.accept.users", STATIC_AUTHN_USERS));
    System.setProperty(RestfulPropertySourceLocator.CAS_CONFIGURATION_PREFIX + '.' + "url", "http://localhost:9345");
    SERVER = new MockWebServer(9345, new ByteArrayResource(response.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.TOO_MANY_REQUESTS);
    SERVER.start();
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 45 with MockWebServer

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

the class OktaConfigurationFactoryTests method verifyOperation.

@Test
public void verifyOperation() {
    try (val webServer = new MockWebServer(8923, HttpStatus.OK)) {
        webServer.start();
        assertNotNull(OktaConfigurationFactory.buildAuthenticationClient(casProperties.getAuthn().getOkta()));
        assertThrows(OAuth2TokenRetrieverException.class, () -> OktaConfigurationFactory.buildClient(casProperties.getAuthn().getAttributeRepository().getOkta()));
    }
}
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)

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