Skip to content

Commit 7f70450

Browse files
committed
Adjustment to testing setup
1 parent ce1947b commit 7f70450

File tree

4 files changed

+86
-43
lines changed

4 files changed

+86
-43
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,13 @@ public <T extends AccessCredential> CompletionStage<List<T>> query(final URI age
391391
final URI type;
392392
final Set<String> supportedTypes;
393393
if (AccessGrant.class.isAssignableFrom(clazz)) {
394-
type = ACCESS_GRANT;
394+
type = URI.create("SolidAccessGrant");
395395
supportedTypes = ACCESS_GRANT_TYPES;
396396
} else if (AccessRequest.class.isAssignableFrom(clazz)) {
397-
type = ACCESS_REQUEST;
397+
type = URI.create("SolidAccessRequest");
398398
supportedTypes = ACCESS_REQUEST_TYPES;
399399
} else if (AccessDenial.class.isAssignableFrom(clazz)) {
400-
type = ACCESS_DENIAL;
400+
type = URI.create("SolidAccessDenial");
401401
supportedTypes = ACCESS_DENIAL_TYPES;
402402
} else {
403403
throw new AccessGrantException("Unsupported type " + clazz + " in query request");

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

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ public class AccessGrantScenarios {
112112
private static String testRDFresourceName = "resource.ttl";
113113
private static URI testRDFresourceURI;
114114
private static String sharedTextFileName = "sharedFile.txt";
115+
private static String sharedResourceName = "sharedResource";
115116
private static URI sharedTextFileURI;
117+
private static URI sharedResource;
116118
private static Session session;
117119

118120
@BeforeAll
@@ -158,32 +160,45 @@ static void setup() throws IOException {
158160
sharedTextFileURI = URIBuilder.newBuilder(URI.create(testContainerURI.toString()))
159161
.path(sharedTextFileName)
160162
.build();
163+
sharedResource = URIBuilder.newBuilder(URI.create(testContainerURI.toString()))
164+
.path(sharedResourceName).build();
161165

162166
testRDFresourceURI = URIBuilder.newBuilder(testContainerURI)
163167
.path(testRDFresourceName)
164168
.build();
165169

170+
session = OpenIdSession.ofClientCredentials(
171+
URI.create(issuer), //Client credentials
172+
CLIENT_ID,
173+
CLIENT_SECRET,
174+
AUTH_METHOD);
175+
166176
//create test file in test container
167177
try (final InputStream is = new ByteArrayInputStream(StandardCharsets.UTF_8.encode("Test text").array())) {
168178
final SolidNonRDFSource testResource = new SolidNonRDFSource(sharedTextFileURI, Utils.PLAIN_TEXT, is, null);
169-
session = OpenIdSession.ofClientCredentials(
170-
URI.create(issuer), //Client credentials
171-
CLIENT_ID,
172-
CLIENT_SECRET,
173-
AUTH_METHOD);
174179
final SolidSyncClient authClient = client.session(session);
175180
assertDoesNotThrow(() -> authClient.create(testResource));
176181

177182
prepareACPofResource(authClient, sharedTextFileURI);
178183
}
179184

180-
accessGrantServer = new MockAccessGrantServer(State.WEBID.toString(), sharedTextFileURI.toString());
185+
accessGrantServer = new MockAccessGrantServer(State.WEBID, sharedTextFileURI, sharedResource);
181186
accessGrantServer.start();
182187

183188
VC_PROVIDER = config
184189
.getOptionalValue("inrupt.test.vc.provider", String.class)
185190
.orElse(accessGrantServer.getMockServerUrl());
186191

192+
final AccessGrantClient accessGrantClient = new AccessGrantClient(URI.create(VC_PROVIDER)).session(session);
193+
final Set<String> modes = new HashSet<>(Arrays.asList(GRANT_MODE_READ, GRANT_MODE_APPEND));
194+
final Instant expiration = Instant.parse(GRANT_EXPIRATION);
195+
196+
final AccessRequest request = accessGrantClient.requestAccess(URI.create(webidUrl),
197+
new HashSet<>(Arrays.asList(sharedResource)), modes, PURPOSES, expiration)
198+
.toCompletableFuture().join();
199+
final AccessGrant grant = accessGrantClient.grantAccess(request)
200+
.toCompletableFuture().join();
201+
187202
LOGGER.info("Integration Test Issuer: [{}]", issuer);
188203
LOGGER.info("Integration Test Pod Host: [{}]", podUrl);
189204
LOGGER.info("Integration Test Access Grant server: [{}]", VC_PROVIDER);
@@ -229,8 +244,7 @@ void accessGrantIssuanceLifecycleTest(final Session session) {
229244

230245
//2. call verify endpoint to verify grant
231246

232-
final URI uri = URIBuilder.newBuilder(URI.create(VC_PROVIDER)).path(grant.getIdentifier().toString()).build();
233-
final AccessGrant grantFromVcProvider = accessGrantClient.fetch(uri, AccessGrant.class)
247+
final AccessGrant grantFromVcProvider = accessGrantClient.fetch(grant.getIdentifier(), AccessGrant.class)
234248
.toCompletableFuture().join();
235249
assertEquals(grant.getPurposes(), grantFromVcProvider.getPurposes());
236250

@@ -259,7 +273,6 @@ void accessGrantIssuanceLifecycleTest(final Session session) {
259273
assertDoesNotThrow(accessGrantClient.revoke(grant).toCompletableFuture()::join);
260274

261275
//6. call verify endpoint to check the grant is not valid
262-
263276
}
264277

265278
@ParameterizedTest
@@ -279,8 +292,6 @@ void accessGrantWithRequestOverridesTest(final Session session) {
279292
.toCompletableFuture().join();
280293

281294
//2. call verify endpoint to verify grant
282-
283-
assertDoesNotThrow(accessGrantClient.delete(grant).toCompletableFuture()::join);
284295
}
285296

286297
@ParameterizedTest
@@ -300,8 +311,6 @@ void accessGrantNonRecursiveTest(final Session session) {
300311
.toCompletableFuture().join();
301312
//Steps
302313
//1. call verify endpoint to verify grant
303-
304-
assertDoesNotThrow(accessGrantClient.delete(grant).toCompletableFuture()::join);
305314
}
306315

307316
// Query access grant related tests
@@ -315,7 +324,7 @@ void accessGrantQueryByRequestorTest(final Session session) {
315324

316325
//query for all grants issued by the user
317326
final List<AccessRequest> grants = accessGrantClient.query(URI.create(webidUrl),
318-
sharedTextFileURI, PURPOSE1, GRANT_MODE_READ, AccessRequest.class)
327+
sharedResource, PURPOSE1, GRANT_MODE_READ, AccessRequest.class)
319328
.toCompletableFuture().join();
320329
// result is 4 because we retrieve the grants for each path
321330
// sharedTextFileURI =
@@ -324,7 +333,7 @@ void accessGrantQueryByRequestorTest(final Session session) {
324333

325334
//query for all grants issued by a random user
326335
final List<AccessRequest> randomGrants = accessGrantClient.query(URI.create("https://someuser.test"),
327-
sharedTextFileURI, PURPOSE1, GRANT_MODE_READ, AccessRequest.class)
336+
sharedResource, PURPOSE1, GRANT_MODE_READ, AccessRequest.class)
328337
.toCompletableFuture().join();
329338
assertEquals(0, randomGrants.size());
330339
}
@@ -339,7 +348,7 @@ void accessGrantQueryByResourceTest(final Session session) {
339348

340349
//query for all grants of a dedicated resource
341350
final List<AccessRequest> requests = accessGrantClient.query(URI.create(webidUrl),
342-
sharedTextFileURI, PURPOSE1, GRANT_MODE_READ, AccessRequest.class)
351+
sharedResource, PURPOSE1, GRANT_MODE_READ, AccessRequest.class)
343352
.toCompletableFuture().join();
344353
assertEquals(1, requests.size());
345354

@@ -360,14 +369,13 @@ void accessGrantQueryByPurposeTest(final Session session) {
360369

361370
//query for all grants with a dedicated purpose
362371
final List<AccessRequest> requests = accessGrantClient.query(URI.create(webidUrl),
363-
sharedTextFileURI, PURPOSE1, GRANT_MODE_READ, AccessRequest.class)
372+
sharedResource, PURPOSE1, GRANT_MODE_READ, AccessRequest.class)
364373
.toCompletableFuture().join();
365374
assertEquals(1, requests.size());
366375

367-
//query for all grants of an unsupported purpose
368-
final URI purpose = URI.create("https://example.com/12");
369-
final List<AccessRequest> randomGrants = accessGrantClient.query(URI.create(webidUrl),
370-
sharedTextFileURI, purpose, GRANT_MODE_READ, AccessRequest.class)
376+
//query for all grants of dedicated purpose combinations
377+
final List<AccessGrant> randomGrants = accessGrantClient.query(URI.create(webidUrl),
378+
sharedResource, PURPOSE1, GRANT_MODE_WRITE, AccessGrant.class)
371379
.toCompletableFuture().join();
372380
assertEquals(0, randomGrants.size()); //our grant is actually a Read
373381
}
@@ -448,7 +456,6 @@ void accessGrantSetRdfTest(final Session session) {
448456
authClient.delete(testRDFresourceURI);
449457

450458
assertDoesNotThrow(accessGrantClient.revoke(grant).toCompletableFuture()::join);
451-
assertDoesNotThrow(accessGrantClient.delete(grant).toCompletableFuture()::join);
452459
}
453460
}
454461

@@ -527,7 +534,6 @@ void accessGrantGetNonRdfTest(final Session session) throws IOException {
527534

528535
authClient.delete(newTestFileURI);
529536
assertDoesNotThrow(accessGrantClient.revoke(grant).toCompletableFuture()::join);
530-
assertDoesNotThrow(accessGrantClient.delete(grant).toCompletableFuture()::join);
531537
}
532538

533539
@ParameterizedTest
@@ -581,7 +587,6 @@ void accessGrantSetNonRdfTest(final Session session) throws IOException {
581587

582588
authClient.delete(newTestFileURI);
583589
assertDoesNotThrow(accessGrantClient.revoke(grant).toCompletableFuture()::join);
584-
assertDoesNotThrow(accessGrantClient.delete(grant).toCompletableFuture()::join);
585590
}
586591

587592
@ParameterizedTest
@@ -620,7 +625,7 @@ void accessGrantCreateNonRdfTest(final Session session) throws IOException {
620625
private static void prepareACPofResource(final SolidSyncClient authClient, final URI resourceURI) {
621626

622627
// find the acl Link in the header of the resource
623-
try (final SolidRDFSource resource = authClient.read(resourceURI, SolidRDFSource.class)) {
628+
try (final SolidNonRDFSource resource = authClient.read(resourceURI, SolidNonRDFSource.class)) {
624629
resource.getMetadata().getAcl().ifPresent(acl -> {
625630
try (final SolidRDFSource acr = authClient.read(acl, SolidRDFSource.class)) {
626631
AccessGrantUtils.accessControlPolicyTriples(acl, ACL.Read, ACL.Write)
@@ -641,8 +646,8 @@ private static Stream<Arguments> provideSessions() throws SolidClientException {
641646
final var token = credential.map(Credential::getToken)
642647
.orElseThrow(() -> new OpenIdException("We could not get a token"));
643648
return Stream.of(
644-
Arguments.of(OpenIdSession.ofIdToken(token), //OpenId token
649+
Arguments.of(OpenIdSession.ofIdToken(token)), //OpenId token
645650
Arguments.of(session)
646-
));
651+
);
647652
}
648653
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void fetchPrivateResourceUnauthenticatedTest(final Session session) {
203203
@MethodSource("provideSessions")
204204
@DisplayName(":authenticatedPublicNode Authenticated fetch of public resource succeeds")
205205
void fetchPublicResourceAuthenticatedTest(final Session session) {
206-
LOGGER.info("Integration Test - AuAuthenticatedth fetch of public resource");
206+
LOGGER.info("Integration Test - Authenticated fetch of public resource");
207207
//create public resource
208208
final SolidSyncClient client = SolidSyncClient.getClient();
209209
try (final SolidRDFSource testResource = new SolidRDFSource(publicResourceURL, null, null)) {

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

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@
2929
import java.io.IOException;
3030
import java.io.InputStream;
3131
import java.io.UncheckedIOException;
32+
import java.net.URI;
3233

3334
import org.apache.commons.io.IOUtils;
3435

3536
class MockAccessGrantServer {
3637

37-
private final WireMockServer wireMockServer;
38-
private String webId;
39-
private String sharedFile;
40-
private final String DERIVE = "/derive";
38+
private static final String DERIVE = "/derive";
4139

42-
public MockAccessGrantServer(final String webId, final String sharedFile) {
43-
this.webId = webId;
44-
this.sharedFile = sharedFile;
40+
private final WireMockServer wireMockServer;
41+
private final String webId;
42+
private final String sharedFile;
43+
private final String sharedResource;
44+
45+
public MockAccessGrantServer(final URI webId, final URI sharedFile, final URI sharedResource) {
46+
this.webId = webId.toString();
47+
this.sharedFile = sharedFile.toString();
48+
this.sharedResource = sharedResource.toString();
4549
wireMockServer = new WireMockServer(WireMockConfiguration.options().dynamicPort());
4650
}
4751

@@ -52,14 +56,14 @@ private void setupMocks() {
5256
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
5357
.withBody(getResource("/vc-configuration.json", wireMockServer.baseUrl()))));
5458

55-
wireMockServer.stubFor(get(urlPathMatching(".+:(\\d*)/vc-grant"))
59+
wireMockServer.stubFor(get(urlPathEqualTo("/vc-grant"))
5660
.willReturn(aResponse()
5761
.withStatus(Utils.SUCCESS)
5862
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
5963
.withBody(getResource("/vc-grant.json", wireMockServer.baseUrl(),
6064
this.webId, this.sharedFile))));
6165

62-
wireMockServer.stubFor(get(urlPathMatching(".+:(\\d*)/vc-request"))
66+
wireMockServer.stubFor(get(urlPathEqualTo("/vc-request"))
6367
.willReturn(aResponse()
6468
.withStatus(Utils.SUCCESS)
6569
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
@@ -71,6 +75,27 @@ private void setupMocks() {
7175
.withStatus(204)));
7276

7377
wireMockServer.stubFor(post(urlEqualTo("/issue"))
78+
.atPriority(2)
79+
.withRequestBody(containing("hasConsent"))
80+
.withRequestBody(containing(this.sharedResource))
81+
.willReturn(aResponse()
82+
.withStatus(Utils.SUCCESS)
83+
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
84+
.withBody(getResource("/vc-request.json", wireMockServer.baseUrl(),
85+
this.webId, this.sharedResource))));
86+
87+
wireMockServer.stubFor(post(urlEqualTo("/issue"))
88+
.atPriority(2)
89+
.withRequestBody(containing("providedConsent"))
90+
.withRequestBody(containing(this.sharedResource))
91+
.willReturn(aResponse()
92+
.withStatus(Utils.SUCCESS)
93+
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
94+
.withBody(getResource("/vc-grant.json", wireMockServer.baseUrl(),
95+
this.webId, this.sharedResource))));
96+
97+
wireMockServer.stubFor(post(urlEqualTo("/issue"))
98+
.atPriority(1)
7499
.withRequestBody(containing("hasConsent"))
75100
.willReturn(aResponse()
76101
.withStatus(Utils.SUCCESS)
@@ -79,6 +104,7 @@ private void setupMocks() {
79104
this.webId, this.sharedFile))));
80105

81106
wireMockServer.stubFor(post(urlEqualTo("/issue"))
107+
.atPriority(1)
82108
.withRequestBody(containing("providedConsent"))
83109
.willReturn(aResponse()
84110
.withStatus(Utils.SUCCESS)
@@ -96,6 +122,17 @@ private void setupMocks() {
96122
.withRequestBody(containing("\"Read\""))
97123
.withRequestBody(containing("\"https://purpose.example/212efdf4-e1a4-4dcd-9d3b-d6eb92e0205f\""))
98124
.withRequestBody(containing("\"" + this.webId + "\""))
125+
.withRequestBody(containing("\"" + this.sharedResource + "\""))
126+
.willReturn(aResponse()
127+
.withStatus(Utils.SUCCESS)
128+
.withHeader(Utils.CONTENT_TYPE, Utils.APPLICATION_JSON)
129+
.withBody(getResource("/query_response.json", wireMockServer.baseUrl(),
130+
this.webId, this.sharedResource))));
131+
132+
wireMockServer.stubFor(post(urlEqualTo(DERIVE))
133+
.atPriority(1)
134+
.withRequestBody(containing("\"Read\""))
135+
.withRequestBody(containing("\"" + this.webId + "\""))
99136
.withRequestBody(containing("\"" + this.sharedFile + "\""))
100137
.willReturn(aResponse()
101138
.withStatus(Utils.SUCCESS)
@@ -113,19 +150,20 @@ private void setupMocks() {
113150

114151
}
115152

116-
private String getResource(final String path) {
153+
private static String getResource(final String path) {
117154
try (final InputStream res = MockAccessGrantServer.class.getResourceAsStream(path)) {
118155
return new String(IOUtils.toByteArray(res), UTF_8);
119156
} catch (final IOException ex) {
120157
throw new UncheckedIOException("Could not read class resource", ex);
121158
}
122159
}
123160

124-
private String getResource(final String path, final String baseUrl) {
161+
private static String getResource(final String path, final String baseUrl) {
125162
return getResource(path).replace("{{baseUrl}}", baseUrl);
126163
}
127164

128-
private String getResource(final String path, final String baseUrl, final String webId, final String sharedFile) {
165+
private static String getResource(final String path, final String baseUrl, final String webId,
166+
final String sharedFile) {
129167
return getResource(path).replace("{{baseUrl}}", baseUrl)
130168
.replace("{{webId}}", webId)
131169
.replace("{{sharedFile}}", sharedFile);

0 commit comments

Comments
 (0)