use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.
the class RestfulPrincipalFactoryTests method verifyBadResponse.
@Test
public void verifyBadResponse() {
try (val webServer = new MockWebServer(9157, new ByteArrayResource("abcde123456".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new RestEndpointProperties();
props.setUrl("http://localhost:9157");
val factory = PrincipalFactoryUtils.newRestfulPrincipalFactory(props);
assertThrows(IllegalArgumentException.class, () -> factory.createPrincipal("casuser", CollectionUtils.wrap("name", List.of("CAS"))));
}
}
use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.
the class RestfulPrincipalFactoryTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val entity = MAPPER.writeValueAsString(CoreAuthenticationTestUtils.getPrincipal("casuser"));
try (val webServer = new MockWebServer(9155, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new RestEndpointProperties();
props.setUrl("http://localhost:9155");
val factory = PrincipalFactoryUtils.newRestfulPrincipalFactory(props);
val p = factory.createPrincipal("casuser", CollectionUtils.wrap("name", List.of("CAS")));
assertEquals("casuser", p.getId());
assertEquals(5, p.getAttributes().size());
}
}
use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.
the class OidcRestfulWebFingerUserInfoRepositoryTests method verifyFindByEmail.
@Test
public void verifyFindByEmail() throws Exception {
var data = MAPPER.writeValueAsString(CollectionUtils.wrap("email", "cas@example.org"));
try (val webServer = new MockWebServer(9312, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
this.webServer = webServer;
this.webServer.start();
assertTrue(this.webServer.isRunning());
val props = new RestEndpointProperties();
props.setUrl("http://localhost:9312");
val repo = new OidcRestfulWebFingerUserInfoRepository(props);
val results = repo.findByEmailAddress("cas@example.org");
assertNotNull(results);
assertTrue(results.containsKey("email"));
assertEquals("cas@example.org", results.get("email"));
}
}
use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.
the class RestfulDelegatedClientUserProfileProvisionerTests method verifyAllowedOperation.
@Test
public void verifyAllowedOperation() {
val commonProfile = new CommonProfile();
commonProfile.setClientName("CasClient");
commonProfile.setId("testuser");
val client = new CasClient(new CasConfiguration("http://cas.example.org"));
try (val webServer = new MockWebServer(9192, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new RestEndpointProperties();
props.setUrl("http://localhost:9192");
val service = new RestfulDelegatedClientUserProfileProvisioner(props);
service.execute(CoreAuthenticationTestUtils.getPrincipal(), commonProfile, client, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
}
}
use of org.apereo.cas.configuration.model.RestEndpointProperties in project cas by apereo.
the class OidcRestfulWebFingerUserInfoRepositoryTests method verifyBadPayload.
@Test
public void verifyBadPayload() throws Exception {
try (val webServer = new MockWebServer(9312, new ByteArrayResource("-@@-".getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
this.webServer = webServer;
this.webServer.start();
assertTrue(this.webServer.isRunning());
val props = new RestEndpointProperties();
props.setUrl("http://localhost:9312");
val repo = new OidcRestfulWebFingerUserInfoRepository(props);
val results = repo.findByEmailAddress("cas@example.org");
assertTrue(results.isEmpty());
}
}
Aggregations