Search in sources :

Example 61 with MockWebServer

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

the class BasicDuoSecurityAuthenticationServiceTests method verifyPing.

@Test
public void verifyPing() throws Exception {
    var entity = MAPPER.writeValueAsString(Map.of("stat", "OK", "response", "pong"));
    try (val webServer = new MockWebServer(9310, new ByteArrayResource(entity.getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        val props = new DuoSecurityMultifactorAuthenticationProperties().setDuoApiHost("http://localhost:9310");
        val service = new BasicDuoSecurityAuthenticationService(props, httpClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
        assertTrue(service.ping());
    }
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) 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 62 with MockWebServer

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

the class BasicDuoSecurityAuthenticationServiceTests method verifyAuthNDirect.

@Test
public void verifyAuthNDirect() throws Exception {
    val service = new BasicDuoSecurityAuthenticationService(casProperties.getAuthn().getMfa().getDuo().get(0), httpClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
    try (val webServer = new MockWebServer(6342)) {
        webServer.start();
        val creds = new DuoSecurityDirectCredential(RegisteredServiceTestUtils.getAuthentication().getPrincipal(), "mfa-duo");
        assertFalse(service.authenticate(creds).isSuccess());
    }
}
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 63 with MockWebServer

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

the class OidcRestfulJsonWebKeystoreGeneratorServiceTests method setup.

@BeforeAll
public static void setup() {
    val webKey = OidcJsonWebKeyStoreUtils.generateJsonWebKey("rsa", 2048, OidcJsonWebKeyUsage.SIGNING);
    val data = webKey.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE);
    SERVER = new MockWebServer(9521, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE);
    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 64 with MockWebServer

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

the class OidcRestfulWebFingerUserInfoRepositoryTests method verifyFindByEmail.

@Test
public void verifyFindByEmail() throws Exception {
    var data = MAPPER.writeValueAsString(CollectionUtils.wrap("email", "cas@example.org"));
    try (val webServer = new MockWebServer(9312, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        this.webServer = webServer;
        this.webServer.start();
        assertTrue(this.webServer.isRunning());
        val props = new RestEndpointProperties();
        props.setUrl("http://localhost:9312");
        val repo = new OidcRestfulWebFingerUserInfoRepository(props);
        val results = repo.findByEmailAddress("cas@example.org");
        assertNotNull(results);
        assertTrue(results.containsKey("email"));
        assertEquals("cas@example.org", results.get("email"));
    }
}
Also used : lombok.val(lombok.val) RestEndpointProperties(org.apereo.cas.configuration.model.RestEndpointProperties) OidcRestfulWebFingerUserInfoRepository(org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 65 with MockWebServer

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

the class RestfulPasswordlessTokenRepositoryTests method verifySaveToken.

@Test
public void verifySaveToken() {
    val data = "THE_TOKEN";
    try (val webServer = new MockWebServer(9307, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val tokens = new CasConfigurationProperties().getAuthn().getPasswordless().getTokens();
        tokens.getRest().setUrl("http://localhost:9307");
        val passwordless = new RestfulPasswordlessTokenRepository(tokens.getExpireInSeconds(), tokens.getRest(), passwordlessCipherExecutor);
        passwordless.saveToken("casuser", data);
    }
}
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)

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