Search in sources :

Example 51 with MockWebServer

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

the class RestfulUrlTemplateResolverTests method verifyAction.

@Test
public void verifyAction() {
    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"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val props = new CasConfigurationProperties();
        props.getView().getRest().setUrl("http://localhost:9302");
        var themeResolver = new FixedThemeResolver();
        themeResolver.setDefaultThemeName("sample-theme");
        val r = new RestfulUrlTemplateResolver(props, themeResolver);
        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)

Example 52 with MockWebServer

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

the class RestMultifactorAuthenticationProviderBypassEvaluatorTests method verifyOperationFailsWithNoProvider.

@Test
public void verifyOperationFailsWithNoProvider() {
    try (val webServer = new MockWebServer(9316, new ByteArrayResource("Y".getBytes(StandardCharsets.UTF_8), "REST Output"), HttpStatus.ACCEPTED)) {
        webServer.start();
        val props = new MultifactorAuthenticationProviderBypassProperties();
        props.getRest().setUrl("http://localhost:9316");
        val provider = new TestMultifactorAuthenticationProvider();
        val r = new RestMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
        val res = r.shouldMultifactorAuthenticationProviderExecute(MultifactorAuthenticationTestUtils.getAuthentication("casuser"), MultifactorAuthenticationTestUtils.getRegisteredService(), null, new MockHttpServletRequest());
        assertTrue(res);
    }
}
Also used : lombok.val(lombok.val) MultifactorAuthenticationProviderBypassProperties(org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) RestMultifactorAuthenticationProviderBypassEvaluator(org.apereo.cas.authentication.bypass.RestMultifactorAuthenticationProviderBypassEvaluator) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 53 with MockWebServer

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

the class RestEndpointMultifactorAuthenticationTriggerTests method verifyOperationByProvider.

@Test
@Order(1)
public void verifyOperationByProvider() {
    val response = TestMultifactorAuthenticationProvider.ID.getBytes(StandardCharsets.UTF_8);
    try (val webServer = new MockWebServer(9313, new ByteArrayResource(response, "Output"), HttpStatus.OK)) {
        webServer.start();
        val props = new CasConfigurationProperties();
        props.getAuthn().getMfa().getTriggers().getRest().setUrl("http://localhost:9313");
        val trigger = new RestEndpointMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), applicationContext);
        val result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
        assertTrue(result.isPresent());
    }
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MockWebServer(org.apereo.cas.util.MockWebServer) Service(org.apereo.cas.authentication.principal.Service) DefaultMultifactorAuthenticationProviderResolver(org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver) ByteArrayResource(org.springframework.core.io.ByteArrayResource) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 54 with MockWebServer

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

the class RestEndpointMultifactorAuthenticationTriggerTests method verifyFailProvider.

@Test
@Order(2)
public void verifyFailProvider() {
    val response = TestMultifactorAuthenticationProvider.ID.getBytes(StandardCharsets.UTF_8);
    try (val webServer = new MockWebServer(9313, new ByteArrayResource(response, "Output"), HttpStatus.UNAUTHORIZED)) {
        webServer.start();
        val props = new CasConfigurationProperties();
        props.getAuthn().getMfa().getTriggers().getRest().setUrl("http://localhost:9313");
        val trigger = new RestEndpointMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), applicationContext);
        val result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
        assertTrue(result.isEmpty());
    }
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MockWebServer(org.apereo.cas.util.MockWebServer) Service(org.apereo.cas.authentication.principal.Service) DefaultMultifactorAuthenticationProviderResolver(org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver) ByteArrayResource(org.springframework.core.io.ByteArrayResource) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 55 with MockWebServer

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

the class SimpleHttpClientTests method verifyValidRejected.

@Test
public void verifyValidRejected() throws Exception {
    try (val webServer = new MockWebServer(8099, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.INTERNAL_SERVER_ERROR)) {
        webServer.start();
        val result = getHttpClient().isValidEndPoint(new URL("http://localhost:8099"));
        assertFalse(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)

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