Search in sources :

Example 76 with MockWebServer

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

the class RestfulDelegatedClientFactoryTests method verifyWrongStatusCode.

@Test
public void verifyWrongStatusCode() {
    val props = new CasConfigurationProperties();
    props.getAuthn().getPac4j().getRest().setUrl("http://localhost:9212");
    val factory = new RestfulDelegatedClientFactory(props);
    try (val webServer = new MockWebServer(9212, HttpStatus.EXPECTATION_FAILED)) {
        webServer.start();
        val clientsFound = factory.build();
        assertNotNull(clientsFound);
        assertTrue(clientsFound.isEmpty());
    }
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MockWebServer(org.apereo.cas.util.MockWebServer) Test(org.junit.jupiter.api.Test)

Example 77 with MockWebServer

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

the class UrlResourceMetadataResolverTests method verifyResolverResolvesFailsAccess.

@Test
public void verifyResolverResolvesFailsAccess() throws Exception {
    try (val webServer = new MockWebServer(9155, new ClassPathResource("sample-metadata.xml"), HttpStatus.OK)) {
        webServer.start();
        val props = new SamlIdPProperties();
        props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
        val service = new SamlRegisteredService();
        service.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(false, false));
        val resolver = new UrlResourceMetadataResolver(props, openSamlConfigBean);
        service.setName("TestShib");
        service.setId(1000);
        service.setMetadataLocation("http://localhost:9155");
        assertThrows(SamlException.class, () -> resolver.resolve(service));
    }
}
Also used : lombok.val(lombok.val) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) MockWebServer(org.apereo.cas.util.MockWebServer) FileSystemResource(org.springframework.core.io.FileSystemResource) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 78 with MockWebServer

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

the class UrlResourceMetadataResolverTests method verifyResolverResolves.

@Test
public void verifyResolverResolves() throws Exception {
    try (val webServer = new MockWebServer(9155, new ClassPathResource("sample-metadata.xml"), HttpStatus.OK)) {
        webServer.start();
        val props = new SamlIdPProperties();
        props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
        val service = new SamlRegisteredService();
        val resolver = new UrlResourceMetadataResolver(props, openSamlConfigBean);
        service.setName("TestShib");
        service.setId(1000);
        service.setMetadataLocation("http://localhost:9155");
        val results = resolver.resolve(service);
        assertFalse(results.isEmpty());
        assertTrue(resolver.isAvailable(service));
        assertFalse(resolver.supports(null));
    }
}
Also used : lombok.val(lombok.val) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) MockWebServer(org.apereo.cas.util.MockWebServer) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 79 with MockWebServer

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

the class UrlResourceMetadataResolverTests method verifyResolverSupports.

@Test
public void verifyResolverSupports() throws Exception {
    try (val webServer = new MockWebServer(9155, new ClassPathResource("sample-metadata.xml"), HttpStatus.OK)) {
        webServer.start();
        val props = new SamlIdPProperties();
        props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
        val resolver = new UrlResourceMetadataResolver(props, openSamlConfigBean);
        val service = new SamlRegisteredService();
        service.setMetadataLocation("http://localhost:9155");
        assertTrue(resolver.supports(service));
        service.setMetadataLocation("classpath:sample-sp.xml");
        assertFalse(resolver.supports(service));
        service.setMetadataLocation(MDQ_URL);
        assertFalse(resolver.supports(service));
    }
}
Also used : lombok.val(lombok.val) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) MockWebServer(org.apereo.cas.util.MockWebServer) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 80 with MockWebServer

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

the class RestMultifactorAuthenticationTrustStorageTests method verifyRemovalByDate.

@Test
public void verifyRemovalByDate() {
    try (val webServer = new MockWebServer(9297, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        assertDoesNotThrow(new Executable() {

            @Override
            public void execute() {
                mfaTrustEngine.remove(ZonedDateTime.now(ZoneOffset.UTC));
            }
        });
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Executable(org.junit.jupiter.api.function.Executable) 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