Search in sources :

Example 1 with OidcRestfulWebFingerUserInfoRepository

use of org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository 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"));
    }
}
Also used : lombok.val(lombok.val) RestEndpointProperties(org.apereo.cas.configuration.model.RestEndpointProperties) OidcRestfulWebFingerUserInfoRepository(org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 2 with OidcRestfulWebFingerUserInfoRepository

use of org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository 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());
    }
}
Also used : lombok.val(lombok.val) RestEndpointProperties(org.apereo.cas.configuration.model.RestEndpointProperties) OidcRestfulWebFingerUserInfoRepository(org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 3 with OidcRestfulWebFingerUserInfoRepository

use of org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository in project cas by apereo.

the class OidcRestfulWebFingerUserInfoRepositoryTests method verifyFindByUsername.

@Test
public void verifyFindByUsername() throws Exception {
    var data = MAPPER.writeValueAsString(CollectionUtils.wrap("username", "casuser"));
    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.findByUsername("casuser");
        assertNotNull(results);
        assertTrue(results.containsKey("username"));
        assertEquals("casuser", results.get("username"));
    }
}
Also used : lombok.val(lombok.val) RestEndpointProperties(org.apereo.cas.configuration.model.RestEndpointProperties) OidcRestfulWebFingerUserInfoRepository(org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)3 RestEndpointProperties (org.apereo.cas.configuration.model.RestEndpointProperties)3 OidcRestfulWebFingerUserInfoRepository (org.apereo.cas.oidc.discovery.webfinger.userinfo.OidcRestfulWebFingerUserInfoRepository)3 MockWebServer (org.apereo.cas.util.MockWebServer)3 Test (org.junit.jupiter.api.Test)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3