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);
}
}
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);
}
}
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());
}
}
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());
}
}
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);
}
}
Aggregations