|
24 | 24 | import static org.junit.jupiter.api.Assertions.*; |
25 | 25 |
|
26 | 26 | import com.inrupt.client.Request; |
| 27 | +import com.inrupt.client.auth.Authenticator; |
| 28 | +import com.inrupt.client.auth.Challenge; |
27 | 29 | import com.inrupt.client.auth.Credential; |
28 | 30 | import com.inrupt.client.auth.Session; |
| 31 | +import com.inrupt.client.openid.OpenIdAuthenticationProvider; |
29 | 32 | import com.inrupt.client.openid.OpenIdSession; |
30 | 33 | import com.inrupt.client.util.URIBuilder; |
31 | 34 |
|
@@ -106,6 +109,32 @@ void testAccessGrantSession() throws IOException { |
106 | 109 | } |
107 | 110 | } |
108 | 111 |
|
| 112 | + @Test |
| 113 | + void testProtectedResource() throws IOException { |
| 114 | + final Map<String, Object> claims = new HashMap<>(); |
| 115 | + claims.put("webid", WEBID); |
| 116 | + claims.put("sub", SUB); |
| 117 | + claims.put("iss", ISS); |
| 118 | + claims.put("azp", AZP); |
| 119 | + |
| 120 | + final String token = AccessGrantTestUtils.generateIdToken(claims); |
| 121 | + |
| 122 | + try (final InputStream resource = AccessGrantTest.class.getResourceAsStream("/access_grant3.json")) { |
| 123 | + final AccessGrant grant = AccessGrant.ofAccessGrant(resource); |
| 124 | + final Session session = AccessGrantSession.ofAccessGrant(OpenIdSession.ofIdToken(token), grant); |
| 125 | + final Request req = Request.newBuilder(URI.create("https://storage.example/protected-resource")).build(); |
| 126 | + final Authenticator auth = new OpenIdAuthenticationProvider().getAuthenticator(Challenge.of("Bearer")); |
| 127 | + |
| 128 | + final Optional<Credential> credential = session.authenticate(auth, req, Collections.emptySet()) |
| 129 | + .toCompletableFuture().join(); |
| 130 | + |
| 131 | + assertTrue(credential.isPresent()); |
| 132 | + assertTrue(session.fromCache(req).isPresent()); |
| 133 | + session.reset(); |
| 134 | + assertFalse(session.fromCache(req).isPresent()); |
| 135 | + } |
| 136 | + } |
| 137 | + |
109 | 138 | @ParameterizedTest |
110 | 139 | @MethodSource |
111 | 140 | void ancestors(final URI parent, final URI resource, final boolean expected) { |
|
0 commit comments