Skip to content

Commit b4509db

Browse files
committed
Change index imports and test new endpoint case
1 parent 49b17dd commit b4509db

7 files changed

Lines changed: 39 additions & 12 deletions

File tree

packages/uma/config/rules/test/test.ttl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99

1010
ex:usagePolicy1 a odrl:Agreement .
1111
ex:usagePolicy1 odrl:permission ex:permission1 .
12+
ex:usagePolicy1 odrl:permission ex:permission1b .
1213
ex:permission1 a odrl:Permission .
1314
ex:permission1 odrl:action odrl:modify .
1415
ex:permission1 odrl:target <http://localhost:3000/alice/other/resource.txt> .
1516
ex:permission1 odrl:assignee <https://woslabbi.pod.knows.idlab.ugent.be/profile/card#me> .
16-
ex:permission1 odrl:assigner <https://pod.woutslabbinck.com/profile/card#me> .
17+
ex:permission1 odrl:assigner <https://pod.a.com/profile/card#me> .
18+
ex:permission1b a odrl:Permission .
19+
ex:permission1b odrl:action odrl:modify .
20+
ex:permission1b odrl:target <http://localhost:3000/alice/other/resource.txt> .
21+
ex:permission1b odrl:assignee <https://woslabbi.pod.knows.idlab.ugent.be/profile/card#me> .
22+
ex:permission1b odrl:assigner <https://pod.b.com/profile/card#me> .
1723

1824
ex:usagePolicy1a a odrl:Agreement .
1925
ex:usagePolicy1a odrl:permission ex:permission1a .

packages/uma/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ export * from './util/ConvertUtil';
7474
export * from './util/HttpMessageSignatures';
7575
export * from './util/Result';
7676
export * from './util/ReType';
77+
export * from './util/routeSpecific/policies/GetPolicies';
78+
export * from './util/routeSpecific/policies/policyUtil';

packages/uma/src/routes/Policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BadRequestHttpError, getLoggerFor, MethodNotAllowedHttpError } from "@solid/community-server";
22
import { UCRulesStorage } from "@solidlab/ucp";
33
import { HttpHandlerContext, HttpHandlerResponse, HttpHandler, HttpHandlerRequest } from "../util/http/models/HttpHandler";
4-
import { getPolicies as getPolicies } from "../util/routeSpecific/policies/";
4+
import { getPolicies as getPolicies } from "../util/routeSpecific/policies/GetPolicies";
55

66
/**
77
* Endpoint to handle policies, this implementation gives all policies that have the

packages/uma/src/util/routeSpecific/policies/GetPolicies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpHandlerRequest, HttpHandlerResponse } from "../../http/models/HttpHandler";
22
import { Quad, Store, Writer } from "n3";
3-
import { odrlAssigner, relations, namedNode } from "./helpers";
3+
import { odrlAssigner, relations, namedNode } from "./policyUtil";
44
import { MethodNotAllowedHttpError } from "@solid/community-server";
55

66
/**

packages/uma/src/util/routeSpecific/policies/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/uma/src/util/routeSpecific/policies/helpers.ts renamed to packages/uma/src/util/routeSpecific/policies/policyUtil.ts

File renamed without changes.

scripts/test-uma-ODRL-policy.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,45 @@
44
* The purpose of this file is to test the /policies endpoint.
55
*/
66

7+
import path from "path";
8+
import { DirectoryUCRulesStorage } from "../packages/ucp/src/storage/DirectoryUCRulesStorage"
9+
import { PolicyRequestHandler } from "../packages/uma/src/routes/Policy"
10+
711
const endpoint = 'http://localhost:4000/uma/policies'
812
const client1 = 'https://pod.woutslabbinck.com/profile/card#me';
913
const client2 = 'https://pod.example.com/profile/card#me';
1014

15+
// Pathname for the test-policy directory, will probably be changed with the new test structure
16+
const policyStorePath = path.join(__dirname, '..', 'packages', 'uma', 'config', 'rules', 'test');
1117

12-
async function main() {
13-
console.log(`Primitive unit test to check policy access based on the client\n`);
18+
async function testGetAllPolicies() {
19+
console.log("\n\nTest GET all policies endpoint",);
1420

15-
let response = await fetch(endpoint, { headers: { 'Authorization': client1 } })
21+
let response = await fetch(endpoint, { headers: { 'Authorization': client1 } });
1622

17-
console.log("expecting all five policies and their relations: \n", await response.text())
23+
console.log("expecting all five policies and their relations: \n", await response.text());
1824

19-
response = await fetch(endpoint, { headers: { 'Authorization': client2 } })
25+
response = await fetch(endpoint, { headers: { 'Authorization': client2 } });
2026

21-
console.log("expecting zero policies: ", await response.text())
27+
console.log("expecting zero policies: ", await response.text());
2228

2329
response = await fetch(endpoint, {});
2430

25-
console.log(`expecting 4xx error code (no authorization header provided): ${response.status}`)
31+
console.log(`expecting 4xx error code (no authorization header provided): ${response.status}`);
32+
33+
// Manual test for specific test cases
34+
// This test uses the existing test.ttl policy directory as the store, could be any other store
35+
const store = new DirectoryUCRulesStorage(policyStorePath);
36+
const handler = new PolicyRequestHandler(store);
37+
38+
let res = await handler.handle({ request: { url: new URL("http://localhost:4000/uma/policies"), method: 'GET', headers: { 'authorization': "https://pod.a.com/profile/card#me" } } });
39+
console.log("expecting only policy 1: ", res.body);
40+
}
41+
42+
async function main() {
43+
console.log(`Primitive unit test to check policy access based on the client\n`);
44+
45+
await testGetAllPolicies();
46+
2647
}
2748
main()

0 commit comments

Comments
 (0)