Search in sources :

Example 16 with AdaptiveAuthenticationProperties

use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.

the class BlackDotIPAddressIntelligenceServiceTests method verifyBadResponse.

@Test
public void verifyBadResponse() {
    try (val webServer = new MockWebServer(9319, new ByteArrayResource("${bad-json$".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val props = new AdaptiveAuthenticationProperties();
        props.getIpIntel().getBlackDot().setUrl("http://localhost:9319?ip=%s");
        props.getIpIntel().getBlackDot().setMode("DYNA_CHECK");
        props.getIpIntel().getBlackDot().setEmailAddress("cas@apereo.org");
        val service = new BlackDotIPAddressIntelligenceService(props);
        val response = service.examine(new MockRequestContext(), "37.58.59.181");
        assertTrue(response.isBanned());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test)

Example 17 with AdaptiveAuthenticationProperties

use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.

the class GroovyIPAddressIntelligenceServiceTests method verifyOperation.

@Test
public void verifyOperation() {
    val script = new ClassPathResource("GroovyIPAddressIntelligenceService.groovy");
    val props = new AdaptiveAuthenticationProperties();
    props.getIpIntel().getGroovy().setLocation(script);
    val service = new GroovyIPAddressIntelligenceService(props);
    val response = service.examine(new MockRequestContext(), "1.2.3.4");
    assertTrue(response.isBanned());
}
Also used : lombok.val(lombok.val) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Aggregations

AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)17 Test (org.junit.jupiter.api.Test)17 lombok.val (lombok.val)16 MockRequestContext (org.springframework.webflow.test.MockRequestContext)16 MockWebServer (org.apereo.cas.util.MockWebServer)9 ByteArrayResource (org.springframework.core.io.ByteArrayResource)9 GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)4 GeoLocationResponse (org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse)3 ClassPathResource (org.springframework.core.io.ClassPathResource)2 GeoLocationService (org.apereo.cas.authentication.adaptive.geo.GeoLocationService)1 IPAddressIntelligenceResponse (org.apereo.cas.authentication.adaptive.intel.IPAddressIntelligenceResponse)1 IPAddressIntelligenceService (org.apereo.cas.authentication.adaptive.intel.IPAddressIntelligenceService)1 HttpRequestUtils (org.apereo.cas.util.HttpRequestUtils)1 ClientInfoHolder (org.apereo.inspektr.common.web.ClientInfoHolder)1 Assertions (org.junit.jupiter.api.Assertions)1 Tag (org.junit.jupiter.api.Tag)1 Mockito (org.mockito.Mockito)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1