Search in sources :

Example 46 with MockWebServer

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

the class RestfulYubiKeyAccountRegistryTests method verifyAccounts.

@Test
public void verifyAccounts() throws Exception {
    val pubKey = getYubiKeyAccountRegistry().getAccountValidator().getTokenPublicId(AbstractYubiKeyAccountRegistryTests.OTP);
    val registeredDevice = YubiKeyRegisteredDevice.builder().id(System.currentTimeMillis()).name("first-device").publicId(getYubikeyAccountCipherExecutor().encode(pubKey).toString()).registrationDate(ZonedDateTime.now(Clock.systemUTC())).build();
    val account = YubiKeyAccount.builder().devices(CollectionUtils.wrapList(registeredDevice)).username("casuser").build();
    try (val webServer = new MockWebServer(6591, new ByteArrayResource(MAPPER.writeValueAsString(CollectionUtils.wrapList(account)).getBytes(StandardCharsets.UTF_8), "Output"), OK)) {
        webServer.start();
        assertFalse(getYubiKeyAccountRegistry().getAccounts().isEmpty());
    }
}
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 47 with MockWebServer

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

the class RestfulYubiKeyAccountRegistryTests method verifyFailsAccount.

@Test
public void verifyFailsAccount() {
    try (val webServer = new MockWebServer(6591, new ByteArrayResource("...".getBytes(StandardCharsets.UTF_8), "Output"), OK)) {
        webServer.start();
        assertTrue(getYubiKeyAccountRegistry().getAccounts().isEmpty());
    }
}
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 48 with MockWebServer

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

the class ReturnRestfulAttributeReleasePolicyTests method verifyBadPolicy.

@Test
public void verifyBadPolicy() {
    try (val webServer = new MockWebServer(9298, new ByteArrayResource("---".getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val policy = new ReturnRestfulAttributeReleasePolicy("http://localhost:9298");
        val releasePolicyContext = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(CoreAuthenticationTestUtils.getRegisteredService()).service(CoreAuthenticationTestUtils.getService()).principal(CoreAuthenticationTestUtils.getPrincipal()).build();
        val attributes = policy.getAttributes(releasePolicyContext);
        assertTrue(attributes.isEmpty());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 49 with MockWebServer

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

the class ReturnRestfulAttributeReleasePolicyTests method verifyPolicy.

@Test
public void verifyPolicy() throws IOException {
    val data = MAPPER.writeValueAsString(CollectionUtils.wrap("givenName", "CASUSER", "familyName", "CAS"));
    try (val webServer = new MockWebServer(9299, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val policyWritten = new ReturnRestfulAttributeReleasePolicy("http://localhost:9299");
        val releasePolicyContext = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(CoreAuthenticationTestUtils.getRegisteredService()).service(CoreAuthenticationTestUtils.getService()).principal(CoreAuthenticationTestUtils.getPrincipal()).build();
        val attributes = policyWritten.getAttributes(releasePolicyContext);
        assertFalse(attributes.isEmpty());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 50 with MockWebServer

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

the class RestfulUrlTemplateResolverTests method verifyUnknownErrorAction.

@Test
public void verifyUnknownErrorAction() {
    val request = new MockHttpServletRequest();
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, new MockHttpServletResponse()));
    try (val webServer = new MockWebServer(9302, new ByteArrayResource("template".getBytes(StandardCharsets.UTF_8), "REST Output"), HttpStatus.NO_CONTENT)) {
        webServer.start();
        val props = new CasConfigurationProperties();
        props.getView().getRest().setUrl("http://localhost:9302");
        val r = new RestfulUrlTemplateResolver(props, new FixedThemeResolver());
        val res = r.resolveTemplate(mock(IEngineConfiguration.class), "cas", "template", new LinkedHashMap<>());
        assertNotNull(res);
    }
}
Also used : lombok.val(lombok.val) IEngineConfiguration(org.thymeleaf.IEngineConfiguration) FixedThemeResolver(org.springframework.web.servlet.theme.FixedThemeResolver) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) 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