use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulYubiKeyAccountRegistryTests method verifyAccounts.
@Test
public void verifyAccounts() throws Exception {
val pubKey = getYubiKeyAccountRegistry().getAccountValidator().getTokenPublicId(AbstractYubiKeyAccountRegistryTests.OTP);
val registeredDevice = YubiKeyRegisteredDevice.builder().id(System.currentTimeMillis()).name("first-device").publicId(getYubikeyAccountCipherExecutor().encode(pubKey).toString()).registrationDate(ZonedDateTime.now(Clock.systemUTC())).build();
val account = YubiKeyAccount.builder().devices(CollectionUtils.wrapList(registeredDevice)).username("casuser").build();
try (val webServer = new MockWebServer(6591, new ByteArrayResource(MAPPER.writeValueAsString(CollectionUtils.wrapList(account)).getBytes(StandardCharsets.UTF_8), "Output"), OK)) {
webServer.start();
assertFalse(getYubiKeyAccountRegistry().getAccounts().isEmpty());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulYubiKeyAccountRegistryTests method verifyFailsAccount.
@Test
public void verifyFailsAccount() {
try (val webServer = new MockWebServer(6591, new ByteArrayResource("...".getBytes(StandardCharsets.UTF_8), "Output"), OK)) {
webServer.start();
assertTrue(getYubiKeyAccountRegistry().getAccounts().isEmpty());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class ReturnRestfulAttributeReleasePolicyTests method verifyBadPolicy.
@Test
public void verifyBadPolicy() {
try (val webServer = new MockWebServer(9298, new ByteArrayResource("---".getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val policy = new ReturnRestfulAttributeReleasePolicy("http://localhost:9298");
val releasePolicyContext = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(CoreAuthenticationTestUtils.getRegisteredService()).service(CoreAuthenticationTestUtils.getService()).principal(CoreAuthenticationTestUtils.getPrincipal()).build();
val attributes = policy.getAttributes(releasePolicyContext);
assertTrue(attributes.isEmpty());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class ReturnRestfulAttributeReleasePolicyTests method verifyPolicy.
@Test
public void verifyPolicy() throws IOException {
val data = MAPPER.writeValueAsString(CollectionUtils.wrap("givenName", "CASUSER", "familyName", "CAS"));
try (val webServer = new MockWebServer(9299, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val policyWritten = new ReturnRestfulAttributeReleasePolicy("http://localhost:9299");
val releasePolicyContext = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(CoreAuthenticationTestUtils.getRegisteredService()).service(CoreAuthenticationTestUtils.getService()).principal(CoreAuthenticationTestUtils.getPrincipal()).build();
val attributes = policyWritten.getAttributes(releasePolicyContext);
assertFalse(attributes.isEmpty());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulUrlTemplateResolverTests method verifyUnknownErrorAction.
@Test
public void verifyUnknownErrorAction() {
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"), HttpStatus.NO_CONTENT)) {
webServer.start();
val props = new CasConfigurationProperties();
props.getView().getRest().setUrl("http://localhost:9302");
val r = new RestfulUrlTemplateResolver(props, new FixedThemeResolver());
val res = r.resolveTemplate(mock(IEngineConfiguration.class), "cas", "template", new LinkedHashMap<>());
assertNotNull(res);
}
}
Aggregations