Search in sources :

Example 56 with MockWebServer

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

the class SimpleHttpClientTests method verifyMessageSent.

@Test
public void verifyMessageSent() throws Exception {
    try (val webServer = new MockWebServer(8165, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val result = getHttpClient().sendMessageToEndPoint(new URL("http://localhost:8165"));
        assertNotNull(result);
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 57 with MockWebServer

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

the class JsonWebKeySetStringCipherExecutorTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val jwksKeystore = new ClassPathResource("sample.jwks");
    val data = IOUtils.toString(jwksKeystore.getInputStream(), StandardCharsets.UTF_8);
    val keystoreFile = getKeystoreFile();
    try (val webServer = new MockWebServer(8435, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE);
        val cipher = new JsonWebKeySetStringCipherExecutor(keystoreFile, "http://localhost:8435")) {
        webServer.start();
        val token = cipher.encode("Misagh");
        assertEquals("Misagh", cipher.decode(token));
        Files.setLastModifiedTime(keystoreFile.toPath(), FileTime.from(Instant.now()));
        Thread.sleep(5_000);
        cipher.destroy();
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 58 with MockWebServer

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

the class RestAuditTrailManagerTests method verifyGet.

@Test
public void verifyGet() throws Exception {
    val audit = new AuditActionContext("casuser", "resource", "action", "CAS", new Date(), "123.456.789.000", "123.456.789.000", "GoogleChrome");
    val data = MAPPER.writeValueAsString(CollectionUtils.wrapSet(audit));
    try (val webServer = new MockWebServer(9296, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8)), HttpStatus.OK)) {
        webServer.start();
        assertTrue(webServer.isRunning());
        auditTrailManager.record(audit);
        val time = LocalDate.now(ZoneOffset.UTC).minusDays(2);
        val results = auditTrailManager.getAuditRecordsSince(time);
        assertFalse(results.isEmpty());
    }
}
Also used : lombok.val(lombok.val) AuditActionContext(org.apereo.inspektr.audit.AuditActionContext) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 59 with MockWebServer

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

the class DefaultDuoSecurityAdminApiServiceTests method verifyCodes.

@Test
public void verifyCodes() throws Exception {
    val service = new DefaultDuoSecurityAdminApiService(this.httpClient, properties);
    try (val webServer = new MockWebServer(8443)) {
        webServer.responseBodySupplier(() -> new ClassPathResource("duoAdminApiResponse-bypassCodes.json"));
        webServer.start();
        val codes = service.getDuoSecurityBypassCodesFor("DU3RP9I2WOC59VZX672N");
        assertFalse(codes.isEmpty());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 60 with MockWebServer

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

the class DuoSecurityAuthenticationServiceTests method verifyPingFails.

@Test
public void verifyPingFails() throws Exception {
    val duoProperties = casProperties.getAuthn().getMfa().getDuo().get(0);
    duoProperties.setDuoApiHost("http://localhost:6556");
    val results = MAPPER.writeValueAsString(Map.of("response", "pong", "stat", "FAIL"));
    val service = new BasicDuoSecurityAuthenticationService(duoProperties, httpClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
    try (val webServer = new MockWebServer(6556, new ByteArrayResource(results.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        assertFalse(service.ping());
    }
    assertFalse(service.ping());
}
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