Skip to content

Commit fde54c7

Browse files
authored
Merge branch 'main' into JCL-417-ldp-contains
2 parents 7f9113f + cf17f3c commit fde54c7

File tree

6 files changed

+90
-27
lines changed

6 files changed

+90
-27
lines changed

access-grant/src/main/java/com/inrupt/client/accessgrant/AccessGrantClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ public AccessGrantClient session(final Session session) {
177177
/**
178178
* Issue an access request.
179179
*
180-
* @param recipient the agent to whom the access request is made;
181-
* i.e., the agent controlling access to the resources
180+
* @param recipient the agent controlling access to the resources
182181
* @param resources the resources to which this credential applies
183182
* @param modes the access modes for this credential
184183
* @param purposes the purposes of this credential

integration/base/src/main/java/com/inrupt/client/integration/base/AccessGrantScenarios.java

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
*/
2121
package com.inrupt.client.integration.base;
2222

23-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
24-
import static org.junit.jupiter.api.Assertions.assertEquals;
25-
import static org.junit.jupiter.api.Assertions.assertThrows;
26-
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
import static org.junit.jupiter.api.Assertions.*;
2724
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2825

2926
import com.inrupt.client.Headers;
@@ -193,6 +190,7 @@ static void setup() throws IOException {
193190
.toString());
194191

195192
accessGrantServer = new MockAccessGrantServer(
193+
URI.create(webidUrl),
196194
URI.create(requesterWebidUrl),
197195
sharedTextFileURI,
198196
authServer.getMockServerUrl()
@@ -368,6 +366,68 @@ void accessGrantQueryByRequesterTest(final Session resourceOwnerSession, final S
368366
assertDoesNotThrow(resourceOwnerAccessGrantClient.revoke(grant).toCompletableFuture()::join);
369367
}
370368

369+
@ParameterizedTest
370+
@MethodSource("provideSessions")
371+
@DisplayName("Given a grant id, approve it")
372+
void accessGrantGrantAccessByIdTest(final Session resourceOwnerSession, final Session requesterSession) {
373+
LOGGER.info("Integration Test - Grant access by id");
374+
375+
//setup test
376+
final AccessGrantClient requesterAccessGrantClient = new AccessGrantClient(
377+
URI.create(ACCESS_GRANT_PROVIDER)
378+
).session(requesterSession);
379+
380+
final Set<String> modes = new HashSet<>(Arrays.asList(GRANT_MODE_READ));
381+
final Instant expiration = Instant.parse(GRANT_EXPIRATION);
382+
final AccessRequest request = requesterAccessGrantClient.requestAccess(URI.create(webidUrl),
383+
new HashSet<>(Arrays.asList(sharedTextFileURI)), modes, PURPOSES, expiration)
384+
.toCompletableFuture().join();
385+
386+
final var grantId = request.getIdentifier();
387+
388+
//requester has access to see their own access requests
389+
final AccessRequest fetchedAccessRequest =
390+
requesterAccessGrantClient.fetch(
391+
grantId,
392+
AccessRequest.class).toCompletableFuture().join();
393+
394+
assertEquals(grantId, fetchedAccessRequest.getIdentifier());
395+
396+
//switching to owner
397+
final AccessGrantClient resourceOwnerAccessGrantClient = new AccessGrantClient(
398+
URI.create(ACCESS_GRANT_PROVIDER)
399+
).session(resourceOwnerSession);
400+
401+
//the owner SHOULD see an access request from requester
402+
//because it is a request concerning the owner's resource
403+
final AccessRequest fetchedAccessRequest1 = resourceOwnerAccessGrantClient.fetch(
404+
grantId,
405+
AccessRequest.class).toCompletableFuture().join();
406+
assertEquals(grantId, fetchedAccessRequest1.getIdentifier());
407+
408+
//owner grants the request
409+
final AccessGrant grant = resourceOwnerAccessGrantClient.grantAccess(request)
410+
.toCompletableFuture().join();
411+
412+
//owner can see the access grants just granted
413+
final AccessGrant accessGrant =
414+
resourceOwnerAccessGrantClient.fetch(
415+
grant.getIdentifier(),
416+
AccessGrant.class).toCompletableFuture().join();
417+
418+
//check that the approved grant is the same we find when querying for all grants
419+
final AccessCredentialQuery<AccessGrant> query = AccessCredentialQuery.newBuilder()
420+
.recipient(URI.create(requesterWebidUrl)).resource(sharedTextFileURI)
421+
.mode(GRANT_MODE_READ).build(AccessGrant.class);
422+
final List<AccessGrant> grants = resourceOwnerAccessGrantClient.query(query).toCompletableFuture().join();
423+
assertEquals(1, grants.size());
424+
assertEquals(grant.getIdentifier(), grants.get(0).getIdentifier());
425+
assertEquals(accessGrant.getIdentifier(), grants.get(0).getIdentifier());
426+
427+
//cleanup
428+
assertDoesNotThrow(resourceOwnerAccessGrantClient.revoke(grant).toCompletableFuture()::join);
429+
}
430+
371431
@ParameterizedTest
372432
@MethodSource("provideSessions")
373433
@DisplayName("https://w3id.org/inrupt/qa/manifest/solid-client-java/accessGrantQueryByPurpose " +

integration/base/src/main/java/com/inrupt/client/integration/base/MockAccessGrantServer.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,20 @@ class MockAccessGrantServer {
5757
private static final String SCENARIO_STATE_REVOKED = "Revoked";
5858

5959
private final WireMockServer wireMockServer;
60-
private final String webId;
60+
private final String ownerWebId;
61+
private final String requesterWebId;
6162
private final String sharedResource;
6263

6364
private final String authorisationServerUrl;
6465

6566
public MockAccessGrantServer(
66-
final URI webId,
67+
final URI ownerWebId,
68+
final URI requesterWebId,
6769
final URI sharedResource,
6870
final String authorisationServerUrl
6971
) {
70-
this.webId = webId.toString();
72+
this.ownerWebId = ownerWebId.toString();
73+
this.requesterWebId = requesterWebId.toString();
7174
this.sharedResource = sharedResource.toString();
7275
this.authorisationServerUrl = authorisationServerUrl;
7376
wireMockServer = new WireMockServer(WireMockConfiguration.options().dynamicPort());
@@ -87,15 +90,15 @@ private void setupMocks() {
8790
.withStatus(Utils.SUCCESS)
8891
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
8992
.withBody(getResource("/vc-grant.json", wireMockServer.baseUrl(),
90-
this.webId, this.sharedResource))));
93+
this.requesterWebId, this.ownerWebId, this.sharedResource))));
9194

9295
wireMockServer.stubFor(get(urlPathEqualTo("/vc-request"))
9396
.withHeader(USER_AGENT_HEADER, equalTo(USER_AGENT))
9497
.willReturn(aResponse()
9598
.withStatus(Utils.SUCCESS)
9699
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
97100
.withBody(getResource("/vc-request.json", wireMockServer.baseUrl(),
98-
this.webId, this.sharedResource))));
101+
this.requesterWebId, this.ownerWebId, this.sharedResource))));
99102

100103
wireMockServer.stubFor(delete(urlPathMatching("/vc-grant"))
101104
.withHeader(USER_AGENT_HEADER, equalTo(USER_AGENT))
@@ -120,7 +123,7 @@ private void setupMocks() {
120123
.withStatus(Utils.SUCCESS)
121124
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
122125
.withBody(getResource("/vc-request.json", wireMockServer.baseUrl(),
123-
this.webId, this.sharedResource))));
126+
this.requesterWebId, this.ownerWebId, this.sharedResource))));
124127

125128
wireMockServer.stubFor(post(urlEqualTo(ISSUE))
126129
.inScenario(SCENARIO_ACCESS_GRANT)
@@ -134,7 +137,7 @@ private void setupMocks() {
134137
.withStatus(Utils.SUCCESS)
135138
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
136139
.withBody(getResource("/vc-grant.json", wireMockServer.baseUrl(),
137-
this.webId, this.sharedResource))));
140+
this.requesterWebId, this.ownerWebId, this.sharedResource))));
138141

139142
wireMockServer.stubFor(post(urlEqualTo(ISSUE))
140143
.atPriority(1)
@@ -145,7 +148,7 @@ private void setupMocks() {
145148
.withStatus(Utils.SUCCESS)
146149
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
147150
.withBody(getResource("/vc-request.json", wireMockServer.baseUrl(),
148-
this.webId, this.sharedResource))));
151+
this.requesterWebId, this.ownerWebId, this.sharedResource))));
149152

150153
wireMockServer.stubFor(post(urlEqualTo(ISSUE))
151154
.inScenario(SCENARIO_ACCESS_GRANT)
@@ -158,7 +161,7 @@ private void setupMocks() {
158161
.withStatus(Utils.SUCCESS)
159162
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
160163
.withBody(getResource("/vc-grant.json", wireMockServer.baseUrl(),
161-
this.webId, this.sharedResource))));
164+
this.requesterWebId, this.ownerWebId, this.sharedResource))));
162165

163166
wireMockServer.stubFor(post(urlEqualTo(ISSUE))
164167
.atPriority(1)
@@ -169,7 +172,7 @@ private void setupMocks() {
169172
.withStatus(Utils.SUCCESS)
170173
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
171174
.withBody(getResource("/vc-request.json", wireMockServer.baseUrl(),
172-
this.webId, this.sharedResource))));
175+
this.requesterWebId, this.ownerWebId, this.sharedResource))));
173176

174177
// Require UMA authentication for the /verify endpoint
175178
wireMockServer.stubFor(post(urlEqualTo(VERIFY))
@@ -229,7 +232,7 @@ private void setupMocks() {
229232
.withStatus(Utils.SUCCESS)
230233
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
231234
.withBody(getResource("/query_response.json", wireMockServer.baseUrl(),
232-
this.webId, this.sharedResource))));
235+
this.requesterWebId, this.ownerWebId, this.sharedResource))));
233236

234237
wireMockServer.stubFor(post(urlEqualTo(DERIVE))
235238
.atPriority(1)
@@ -241,7 +244,7 @@ private void setupMocks() {
241244
.withStatus(Utils.SUCCESS)
242245
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
243246
.withBody(getResource("/query_response.json", wireMockServer.baseUrl(),
244-
this.webId, this.sharedResource))));
247+
this.requesterWebId, this.ownerWebId, this.sharedResource))));
245248

246249
wireMockServer.stubFor(post(urlEqualTo(DERIVE))
247250
.atPriority(2)
@@ -265,10 +268,11 @@ private static String getResource(final String path, final String baseUrl) {
265268
return getResource(path).replace("{{baseUrl}}", baseUrl);
266269
}
267270

268-
private static String getResource(final String path, final String baseUrl, final String webId,
269-
final String sharedFile) {
271+
private static String getResource(final String path, final String baseUrl, final String requesterWebId,
272+
final String ownerWebId, final String sharedFile) {
270273
return getResource(path).replace("{{baseUrl}}", baseUrl)
271-
.replace("{{webId}}", webId)
274+
.replace("{{requesterWebId}}", requesterWebId)
275+
.replace("{{ownerWebId}}", ownerWebId)
272276
.replace("{{sharedFile}}", sharedFile);
273277
}
274278

integration/base/src/main/resources/query_response.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"revocationListIndex":"2832",
1717
"type":"RevocationList2020Status"},
1818
"credentialSubject":{
19-
"id":"{{webId}}",
19+
"id":"{{ownerWebId}}",
2020
"providedConsent":{
2121
"mode":["Read","Append"],
2222
"hasStatus":"https://w3id.org/GConsent#ConsentStatusExplicitlyGiven",
23-
"isProvidedTo":"{{webId}}",
23+
"isProvidedTo":"{{requesterWebId}}",
2424
"forPurpose":["https://purpose.example/Purpose1"],
2525
"forPersonalData":["{{sharedFile}}"]}},
2626
"proof":{

integration/base/src/main/resources/vc-grant.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"revocationListIndex":"2832",
1616
"type":"RevocationList2020Status"},
1717
"credentialSubject":{
18-
"id":"{{webId}}",
18+
"id":"{{ownerWebId}}",
1919
"providedConsent":{
2020
"mode":["Read"],
2121
"hasStatus":"https://w3id.org/GConsent#ConsentStatusExplicitlyGiven",
22-
"isProvidedToPerson":"{{webId}}",
22+
"isProvidedToPerson":"{{requesterWebId}}",
2323
"forPurpose":[
2424
"https://purpose.example/212efdf4-e1a4-4dcd-9d3b-d6eb92e0205f",
2525
"https://purpose.example/de605b08-76c7-4f04-9cec-a438810b0c03"],

integration/base/src/main/resources/vc-request.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"revocationListIndex":"2832",
1616
"type":"RevocationList2020Status"},
1717
"credentialSubject":{
18-
"id":"{{webId}}",
18+
"id":"{{requesterWebId}}",
1919
"hasConsent":{
2020
"mode":["Read"],
2121
"hasStatus":"https://w3id.org/GConsent#ConsentStatusRequested",
22-
"isConsentForDataSubject":"{{webId}}",
22+
"isConsentForDataSubject":"{{ownerWebId}}",
2323
"forPurpose":[
2424
"https://purpose.example/212efdf4-e1a4-4dcd-9d3b-d6eb92e0205f",
2525
"https://purpose.example/de605b08-76c7-4f04-9cec-a438810b0c03"],

0 commit comments

Comments
 (0)