Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/uma/src/util/routeSpecific/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const buildPolicyCreationQuery = (resourceOwner: string) => `
?p a odrl:Agreement ;
odrl:permission ?r ;
odrl:uid ?p .
?r odrl:assignee ?assignee .
} UNION {
?p a odrl:Set ;
odrl:permission ?r ;
Expand All @@ -74,7 +75,6 @@ const buildPolicyCreationQuery = (resourceOwner: string) => `
?r a odrl:Permission ;
odrl:action ?action ;
odrl:target ?target ;
odrl:assignee ?assignee ;
odrl:assigner <${resourceOwner}> .
}
`;
Expand All @@ -92,9 +92,9 @@ const buildPolicyCreationQuery = (resourceOwner: string) => `
export const postPolicy = async (store: Store, resourceOwner: string): Promise<Store> => {
const isOwner = store.countQuads(null, 'http://www.w3.org/ns/odrl/2/assigner', resourceOwner, null) !== 0;
if (!isOwner) throw new ForbiddenHttpError();

const result = await executePost(store, buildPolicyCreationQuery(resourceOwner), ["p", "r"]);

return result;
}

Expand Down Expand Up @@ -144,4 +144,4 @@ export const postAccessRequest = async (store: Store, requestingParty: string):

store.addQuad(requestIds[0], namedNode("http://purl.org/dc/terms/issued"), literal(new Date().toISOString(), XSD.terms.dateTime))
return await executePost(store, buildAccessRequestCreationQuery(requestingParty), ["r"]);
}
}
43 changes: 41 additions & 2 deletions test/integration/Base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,50 @@ describe('A server setup', (): void => {
@prefix ex: <http://example.org/>.
@prefix odrl: <http://www.w3.org/ns/odrl/2/> .

ex:publicPolicy a odrl:Agreement ;
ex:publicAnonPolicy a odrl:Agreement ;
odrl:uid ex:publicAnonPolicy ;
odrl:permission ex:publicAnonPermission .
ex:publicAnonPermission a odrl:Permission ;
odrl:action odrl:read , odrl:modify ;
odrl:target <${collectionResource}> ;
odrl:assignee <urn:solidlab:uma:id:anonymous> ;
odrl:assigner <${owner}> .
`;

const policyResponse = await fetch(url, {
method: 'POST',
headers: { authorization: `WebID ${encodeURIComponent(owner)}`, 'content-type': 'text/turtle' },
body: policy,
});
console.log(await policyResponse.text());
expect(policyResponse.status).toBe(201);

const putResponse = await fetch(collectionResource, {
method: 'PUT',
headers: { 'content-type': 'text/plain' },
body: 'Some new text!',
});
expect(putResponse.status).toBe(205);

const getResponse = await fetch(collectionResource);
expect(getResponse.status).toBe(200);
await expect(getResponse.text()).resolves.toEqual('Some new text!');
});

it('the resource can be made publicly accessible by being a Set without assignee.', async(): Promise<void> => {
const owner = 'https://pod.woutslabbinck.com/profile/card#me';
const url = `http://localhost:${umaPort}/uma/policies`;

const policy = `
@prefix ex: <http://example.org/>.
@prefix odrl: <http://www.w3.org/ns/odrl/2/> .

ex:publicPolicy a odrl:Set ;
odrl:uid ex:publicPolicy ;
odrl:permission ex:publicPermission .
ex:publicPermission a odrl:Permission ;
odrl:action odrl:read , odrl:modify ;
odrl:target <${collectionResource}> ;
odrl:assignee <urn:solidlab:uma:id:anonymous> ;
odrl:assigner <${owner}> .
`;

Expand All @@ -193,13 +230,15 @@ describe('A server setup', (): void => {
headers: { authorization: `WebID ${encodeURIComponent(owner)}`, 'content-type': 'text/turtle' },
body: policy,
});
console.log(await policyResponse.text());
expect(policyResponse.status).toBe(201);

const putResponse = await fetch(collectionResource, {
method: 'PUT',
headers: { 'content-type': 'text/plain' },
body: 'Some new text!',
});
console.log(await putResponse.text());
expect(putResponse.status).toBe(205);

const getResponse = await fetch(collectionResource);
Expand Down