Search in sources :

Example 86 with MockWebServer

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

the class RestfulSamlIdPMetadataGeneratorWithArtifactsTests method setup.

@BeforeAll
public static void setup() throws Exception {
    val document = new SamlIdPMetadataDocument(1000, "CAS", IOUtils.toString(new ClassPathResource("metadata/idp-metadata.xml").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.key").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.key").getInputStream(), StandardCharsets.UTF_8));
    val entity = MAPPER.writeValueAsString(document);
    val resource = new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output");
    SERVER = new MockWebServer(9443, resource, HttpStatus.OK);
    SERVER.start();
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClassPathResource(org.springframework.core.io.ClassPathResource) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 87 with MockWebServer

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

the class RestfulSamlRegisteredServiceMetadataResolverTests method verifyRestEndpointProducesMetadata.

@Test
public void verifyRestEndpointProducesMetadata() throws Exception {
    val service = new SamlRegisteredService();
    service.setName("SAML Wiki Service");
    service.setServiceId("https://carmenwiki.osu.edu/shibboleth");
    service.setDescription("Testing");
    service.setMetadataLocation("rest://");
    assertTrue(resolver.supports(service));
    assertFalse(resolver.supports(null));
    assertFalse(resolver.isAvailable(service));
    assertFalse(resolver.isAvailable(null));
    val doc = new SamlMetadataDocument();
    doc.setId(1);
    doc.setName("SAML Document");
    doc.setSignature(null);
    doc.setValue(IOUtils.toString(new ClassPathResource("sp-metadata.xml").getInputStream(), StandardCharsets.UTF_8));
    val entity = MAPPER.writeValueAsString(doc);
    try (val webServer = new MockWebServer(8078, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        assertTrue(resolver.isAvailable(service));
        val resolvers = resolver.resolve(service);
        assertEquals(1, resolvers.size());
    }
    try (val webServer = new MockWebServer(8078, new ByteArrayResource("@$@".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val resolvers = resolver.resolve(service);
        assertEquals(0, resolvers.size());
    }
}
Also used : lombok.val(lombok.val) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) MockWebServer(org.apereo.cas.util.MockWebServer) SamlMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 88 with MockWebServer

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

the class RestfulSamlIdPMetadataGeneratorTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    var document = new SamlIdPMetadataDocument();
    var entity = MAPPER.writeValueAsString(document);
    try (val webServer = new MockWebServer(9453, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        assertNotNull(samlIdPMetadataGenerator.generate(Optional.empty()));
    }
    document.setEncryptionCertificate(UUID.randomUUID().toString());
    document.setSigningKey(UUID.randomUUID().toString());
    document.setSigningCertificate(UUID.randomUUID().toString());
    document.setEncryptionKey(UUID.randomUUID().toString());
    document.setMetadata(UUID.randomUUID().toString());
    entity = MAPPER.writeValueAsString(document);
    try (val webServer = new MockWebServer(9453, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val service = new SamlRegisteredService();
        service.setName("TestShib");
        service.setId(1000);
        assertNotNull(samlIdPMetadataGenerator.generate(Optional.of(service)));
    }
    try (val webServer = new MockWebServer(9453, new ByteArrayResource("___".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        assertNotNull(samlIdPMetadataGenerator.generate(Optional.empty()));
    }
}
Also used : lombok.val(lombok.val) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument) Test(org.junit.jupiter.api.Test)

Example 89 with MockWebServer

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

the class RestfulSamlIdPMetadataLocatorTests method setup.

@BeforeAll
public static void setup() throws Exception {
    val document = new SamlIdPMetadataDocument(1000, "CAS", IOUtils.toString(new ClassPathResource("metadata/idp-metadata.xml").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.key").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.key").getInputStream(), StandardCharsets.UTF_8));
    val entity = MAPPER.writeValueAsString(document);
    val resource = new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output");
    SERVER = new MockWebServer(9433, resource, HttpStatus.OK);
    SERVER.start();
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClassPathResource(org.springframework.core.io.ClassPathResource) SamlIdPMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 90 with MockWebServer

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

the class PrincipalScimV2ProvisionerActionTests 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();
    user.setActive(true);
    user.setDisplayName("CASUser");
    user.setId("casuser");
    val name = new Name();
    name.setGivenName("casuser");
    user.setName(name);
    val meta = new Meta();
    meta.setResourceType("User");
    meta.setCreated(Calendar.getInstance());
    meta.setLocation(new URI("http://localhost:8218"));
    user.setMeta(meta);
    val data = MAPPER.writeValueAsString(user);
    try (val webServer = new MockWebServer(8218, 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.scim2.common.types.Meta) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) UserResource(com.unboundid.scim2.common.types.UserResource) MockWebServer(org.apereo.cas.util.MockWebServer) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ByteArrayResource(org.springframework.core.io.ByteArrayResource) URI(java.net.URI) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Name(com.unboundid.scim2.common.types.Name) 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