Search in sources :

Example 81 with MockWebServer

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

the class RestMultifactorAuthenticationTrustStorageTests method verifySetAnExpireByKey.

@Test
public void verifySetAnExpireByKey() throws Exception {
    val r = MultifactorAuthenticationTrustRecord.newInstance("casuser", "geography", "fingerprint");
    val data = MAPPER.writeValueAsString(CollectionUtils.wrap(r));
    try (val webServer = new MockWebServer(9297, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        mfaTrustEngine.save(r);
        val records = mfaTrustEngine.get("casuser");
        assertNotNull(records);
    }
}
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 82 with MockWebServer

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

the class RestfulWebAuthnCredentialRepositoryTests method verifyUpdate.

@Test
public void verifyUpdate() {
    try (val webServer = new MockWebServer(9559, HttpStatus.OK)) {
        webServer.start();
        webAuthnCredentialRepository.removeAllRegistrations("casuser");
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) Test(org.junit.jupiter.api.Test)

Example 83 with MockWebServer

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

the class RestfulWebAuthnCredentialRepositoryTests method assertLoadIsFound.

private void assertLoadIsFound() throws JsonProcessingException {
    val records = getCredentialRegistration("casuser");
    val results = cipherExecutor.encode(WebAuthnUtils.getObjectMapper().writeValueAsString(CollectionUtils.wrapList(records)));
    try (val webServer = new MockWebServer(9559, new ByteArrayResource(results.getBytes(StandardCharsets.UTF_8), "REST Output"), HttpStatus.OK)) {
        webServer.start();
        val registration = webAuthnCredentialRepository.getRegistrationsByUserHandle(records.getUserIdentity().getId());
        assertFalse(registration.isEmpty());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource)

Example 84 with MockWebServer

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

the class RestfulWebAuthnCredentialRepositoryTests method assertLoadBadInput.

private void assertLoadBadInput() {
    val records = getCredentialRegistration("casuser");
    try (val webServer = new MockWebServer(9559, new ByteArrayResource("_-@@-_".getBytes(StandardCharsets.UTF_8), "REST Output"), HttpStatus.OK)) {
        webServer.start();
        val registration = webAuthnCredentialRepository.getRegistrationsByUserHandle(records.getUserIdentity().getId());
        assertTrue(registration.isEmpty());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource)

Example 85 with MockWebServer

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

the class RemoteEndpointServiceAccessStrategyTests method verifyFails.

@Test
public void verifyFails() {
    val strategy = new RemoteEndpointServiceAccessStrategy();
    strategy.setEndpointUrl("http://localhost:1234");
    strategy.setAcceptableResponseCodes("600");
    try (val webServer = new MockWebServer(8756, new ByteArrayResource("OK".getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        assertFalse(strategy.doPrincipalAttributesAllowServiceAccess("casuser", CoreAuthenticationTestUtils.getAttributes()));
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

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