use of org.apereo.cas.configuration.model.support.aup.AcceptableUsagePolicyProperties in project cas by apereo.
the class RestAcceptableUsagePolicyRepositoryTests method verify.
@Test
public void verify() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication("casuser"), context);
val ticketRegistrySupport = mock(TicketRegistrySupport.class);
val props = new AcceptableUsagePolicyProperties();
props.getRest().setUrl("http://localhost:9298");
props.getCore().setAupAttributeName("givenName");
val r = new RestAcceptableUsagePolicyRepository(ticketRegistrySupport, props);
val data = StringUtils.EMPTY;
try (val webServer = new MockWebServer(9298, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
assertFalse(r.isUsagePolicyAcceptedBy(CoreAuthenticationTestUtils.getPrincipal()));
assertTrue(r.submit(context));
}
}
use of org.apereo.cas.configuration.model.support.aup.AcceptableUsagePolicyProperties in project cas by apereo.
the class RestAcceptableUsagePolicyRepositoryTests method verifyFetch.
@Test
public void verifyFetch() throws Exception {
val ticketRegistrySupport = mock(TicketRegistrySupport.class);
val props = new AcceptableUsagePolicyProperties();
props.getRest().setUrl("http://localhost:9198");
props.getCore().setAupAttributeName("givenName");
val r = new RestAcceptableUsagePolicyRepository(ticketRegistrySupport, props);
val input = AcceptableUsagePolicyTerms.builder().code("example").defaultText("hello world").build();
val data = MAPPER.writeValueAsString(input);
try (val webServer = new MockWebServer(9198, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val context = new MockRequestContext();
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication("casuser"), context);
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
val terms = r.fetchPolicy(context);
assertTrue(terms.isPresent());
assertEquals(terms.get(), input);
}
}
use of org.apereo.cas.configuration.model.support.aup.AcceptableUsagePolicyProperties in project cas by apereo.
the class RestAcceptableUsagePolicyRepositoryTests method verifyFails.
@Test
public void verifyFails() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication("casuser"), context);
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
val ticketRegistrySupport = mock(TicketRegistrySupport.class);
val props = new AcceptableUsagePolicyProperties();
props.getRest().setUrl("http://localhost:9299");
props.getCore().setAupAttributeName("givenName");
val r = new RestAcceptableUsagePolicyRepository(ticketRegistrySupport, props);
val data = StringUtils.EMPTY;
try (val webServer = new MockWebServer(9299, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), HttpStatus.SERVICE_UNAVAILABLE)) {
webServer.start();
assertFalse(r.fetchPolicy(context).isPresent());
assertFalse(r.submit(context));
}
}
Aggregations