Skip to content

Commit

Permalink
PATCH needs Read+Write for overwrite (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
bourgeoa authored Jan 26, 2021
1 parent 5500b10 commit d26e566
Showing 1 changed file with 70 additions and 6 deletions.
76 changes: 70 additions & 6 deletions test/surface/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ describe('Update', () => {
});

const { testFolderUrl } = generateTestFolder('ALICE');
beforeEach(async () => {
/* beforeEach(async () => {
// FIXME: NSS ACL cache,
// wait for ACL cache to clear:
await new Promise(resolve => setTimeout(resolve, 20));
});
}); */

afterEach(() => {
return solidLogicAlice.recursiveDelete(testFolderUrl);
Expand Down Expand Up @@ -508,8 +508,9 @@ describe('Update', () => {
});
});

// Read+Write needed following https://github.com/solid/specification/issues/220
describe('Using PATCH to overwrite', () => {
it('Is allowed with accessTo Write access on resource', async () => {
it('Is allowed with accessTo Read+Write access on resource', async () => {
const resourceUrl = `${testFolderUrl}accessToAppend/test.txt`;
// This will do mkdir-p:
const creationResult = await solidLogicAlice.fetch(resourceUrl, {
Expand All @@ -525,7 +526,7 @@ describe('Update', () => {
const aclDocUrl = await solidLogicAlice.findAclDocUrl(resourceUrl);
await solidLogicAlice.fetch(aclDocUrl, {
method: 'PUT',
body: makeBody('acl:Write', null, resourceUrl),
body: makeBody('acl:Read, acl:Write', null, resourceUrl),
headers: {
'Content-Type': 'text/turtle',
'If-None-Match': '*'
Expand Down Expand Up @@ -571,7 +572,38 @@ describe('Update', () => {
});
expect(result.status).toEqual(403);
});
it('Is allowed with default Write access on parent', async () => {
it('Is disallowed with accessTo Write+Control access on resource', async () => {
const resourceUrl = `${testFolderUrl}accessToAppend/test.txt`;
// This will do mkdir-p:
const creationResult = await solidLogicAlice.fetch(resourceUrl, {
method: 'PUT',
body: '<#hello> <#linked> <#world> .',
headers: {
'Content-Type': 'text/turtle',
'If-None-Match': '*'
}
});
const etagInQuotes = creationResult.headers.get('etag');
// console.log({ etag: etagInQuotes });
const aclDocUrl = await solidLogicAlice.findAclDocUrl(resourceUrl);
await solidLogicAlice.fetch(aclDocUrl, {
method: 'PUT',
body: makeBody('acl:Write, acl:Control', null, resourceUrl),
headers: {
'Content-Type': 'text/turtle',
'If-None-Match': '*'
}
});
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'DELETE { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
});
expect(result.status).toEqual(403);
});
it('Is allowed with default Read+Write access on parent', async () => {
const containerUrl = `${testFolderUrl}accessToAppend/`;
const resourceUrl = `${containerUrl}test.txt`;
// This will do mkdir-p:
Expand All @@ -588,7 +620,7 @@ describe('Update', () => {
const aclDocUrl = await solidLogicAlice.findAclDocUrl(containerUrl);
await solidLogicAlice.fetch(aclDocUrl, {
method: 'PUT',
body: makeBody(null, 'acl:Write', containerUrl),
body: makeBody(null, 'acl:Read, acl:Write', containerUrl),
headers: {
'Content-Type': 'text/turtle',
'If-None-Match': '*'
Expand Down Expand Up @@ -635,6 +667,38 @@ describe('Update', () => {
});
expect(result.status).toEqual(403);
});
it('Is disallowed with default Write+Control access on parent', async () => {
const containerUrl = `${testFolderUrl}accessToAppend/`;
const resourceUrl = `${containerUrl}test.txt`;
// This will do mkdir-p:
const creationResult = await solidLogicAlice.fetch(resourceUrl, {
method: 'PUT',
body: '<#hello> <#linked> <#world> .',
headers: {
'Content-Type': 'text/turtle',
'If-None-Match': '*'
}
});
const etagInQuotes = creationResult.headers.get('etag');
// console.log({ etag: etagInQuotes });
const aclDocUrl = await solidLogicAlice.findAclDocUrl(containerUrl);
await solidLogicAlice.fetch(aclDocUrl, {
method: 'PUT',
body: makeBody(null, 'acl:Write, acl:Control', containerUrl),
headers: {
'Content-Type': 'text/turtle',
'If-None-Match': '*'
}
});
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'DELETE { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
});
expect(result.status).toEqual(403);
});

});
});

0 comments on commit d26e566

Please sign in to comment.