Search in sources :

Example 91 with MockWebServer

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

the class PrincipalScimV1ProvisionerActionTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val resources = new Resources(CollectionUtils.wrapList());
    val stream = new ByteArrayOutputStream();
    resources.marshal(new JsonMarshaller(), stream);
    val data = stream.toString(StandardCharsets.UTF_8);
    try (val webServer = new MockWebServer(8215, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val results = scimProvisioner.provision(RegisteredServiceTestUtils.getPrincipal(), RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"));
        assertFalse(results);
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) Resources(com.unboundid.scim.sdk.Resources) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayResource(org.springframework.core.io.ByteArrayResource) JsonMarshaller(com.unboundid.scim.marshal.json.JsonMarshaller) Test(org.junit.jupiter.api.Test)

Example 92 with MockWebServer

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

the class PrincipalScimV1ProvisionerActionTests method verifyActionUserNotFound.

@Test
public void verifyActionUserNotFound() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
    WebUtils.putCredential(context, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
    val resources = new Resources(CollectionUtils.wrapList());
    val stream = new ByteArrayOutputStream();
    resources.marshal(new JsonMarshaller(), stream);
    val data = stream.toString(StandardCharsets.UTF_8);
    try (val webServer = new MockWebServer(8215, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, principalScimProvisionerAction.execute(context).getId());
    }
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockWebServer(org.apereo.cas.util.MockWebServer) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Resources(com.unboundid.scim.sdk.Resources) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) JsonMarshaller(com.unboundid.scim.marshal.json.JsonMarshaller) Test(org.junit.jupiter.api.Test)

Example 93 with MockWebServer

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

the class PrincipalScimV1ProvisionerActionTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
    WebUtils.putCredential(context, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
    val user = new UserResource(CoreSchema.USER_DESCRIPTOR);
    user.setActive(true);
    user.setDisplayName("CASUser");
    user.setId("casuser");
    val name = new Name("formatted", "family", "middle", "givenMame", "prefix", "prefix2");
    name.setGivenName("casuser");
    user.setName(name);
    val meta = new Meta(new Date(), new Date(), new URI("http://localhost:8215"), "1");
    meta.setCreated(new Date());
    user.setMeta(meta);
    val resources = new Resources(CollectionUtils.wrapList(user));
    val stream = new ByteArrayOutputStream();
    resources.marshal(new JsonMarshaller(), stream);
    val data = stream.toString(StandardCharsets.UTF_8);
    try (val webServer = new MockWebServer(8215, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, principalScimProvisionerAction.execute(context).getId());
    }
}
Also used : lombok.val(lombok.val) Meta(com.unboundid.scim.data.Meta) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UserResource(com.unboundid.scim.data.UserResource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayResource(org.springframework.core.io.ByteArrayResource) URI(java.net.URI) MockServletContext(org.springframework.mock.web.MockServletContext) Date(java.util.Date) Name(com.unboundid.scim.data.Name) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockWebServer(org.apereo.cas.util.MockWebServer) Resources(com.unboundid.scim.sdk.Resources) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) JsonMarshaller(com.unboundid.scim.marshal.json.JsonMarshaller) Test(org.junit.jupiter.api.Test)

Example 94 with MockWebServer

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

the class SurrogateRestAuthenticationServiceTests method verifyUserAllowedToProxy.

@Override
@Test
public void verifyUserAllowedToProxy() throws Exception {
    var data = MAPPER.writeValueAsString(CollectionUtils.wrapList("casuser", "otheruser"));
    try (val webServer = new MockWebServer(9301, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        this.webServer = webServer;
        this.webServer.start();
        assertTrue(this.webServer.isRunning());
        super.verifyUserAllowedToProxy();
    }
}
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 95 with MockWebServer

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

the class SurrogateRestAuthenticationServiceTests method verifyProxying.

@Override
@Test
public void verifyProxying() throws Exception {
    var data = MAPPER.writeValueAsString(CollectionUtils.wrapList("casuser", "otheruser"));
    try (val webServer = new MockWebServer(9310, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val props = new CasConfigurationProperties();
        props.getAuthn().getSurrogate().getRest().setUrl("http://localhost:9310");
        val surrogateService = new SurrogateRestAuthenticationService(props.getAuthn().getSurrogate().getRest(), servicesManager);
        val result = surrogateService.canAuthenticateAs("cassurrogate", CoreAuthenticationTestUtils.getPrincipal("casuser"), Optional.of(CoreAuthenticationTestUtils.getService()));
        /*
             * Can't use super() until the REST classes are
             * completely refactored and don't need an actual server to connect to.
             */
        assertTrue(result);
    }
}
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) 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