diff --git a/packages/uma/src/util/routeSpecific/post.ts b/packages/uma/src/util/routeSpecific/post.ts index 57fad80..762bdc2 100644 --- a/packages/uma/src/util/routeSpecific/post.ts +++ b/packages/uma/src/util/routeSpecific/post.ts @@ -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 ; @@ -74,7 +75,6 @@ const buildPolicyCreationQuery = (resourceOwner: string) => ` ?r a odrl:Permission ; odrl:action ?action ; odrl:target ?target ; - odrl:assignee ?assignee ; odrl:assigner <${resourceOwner}> . } `; @@ -92,9 +92,9 @@ const buildPolicyCreationQuery = (resourceOwner: string) => ` export const postPolicy = async (store: Store, resourceOwner: string): Promise => { 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; } @@ -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"]); -} \ No newline at end of file +} diff --git a/test/integration/Base.test.ts b/test/integration/Base.test.ts index 3ecf888..e26a348 100644 --- a/test/integration/Base.test.ts +++ b/test/integration/Base.test.ts @@ -196,13 +196,50 @@ describe('A server setup', (): void => { @prefix ex: . @prefix odrl: . - 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 ; + 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 => { + const owner = 'https://pod.woutslabbinck.com/profile/card#me'; + const url = `http://localhost:${umaPort}/uma/policies`; + + const policy = ` + @prefix ex: . + @prefix odrl: . + + 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 ; odrl:assigner <${owner}> . `; @@ -211,6 +248,7 @@ 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, { @@ -218,6 +256,7 @@ describe('A server setup', (): void => { headers: { 'content-type': 'text/plain' }, body: 'Some new text!', }); + console.log(await putResponse.text()); expect(putResponse.status).toBe(205); const getResponse = await fetch(collectionResource);