-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt at payment-required test
- Loading branch information
1 parent
84ee0d3
commit f753ec2
Showing
5 changed files
with
111 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { SolidLogic } from 'solid-logic'; | ||
import { generateTestFolder, getSolidLogicInstance, WEBID_ALICE, WEBID_BOB } from '../helpers/env'; | ||
import { responseCodeGroup } from '../helpers/util'; | ||
|
||
function makeBody(accessToModes: string, defaultModes: string, target: string) { | ||
let str = [ | ||
'@prefix acl: <http://www.w3.org/ns/auth/acl#>.', | ||
'', | ||
`<#alice> a acl:Authorization;\n acl:agent <${WEBID_ALICE}>;`, | ||
` acl:accessTo <${target}>;`, | ||
` acl:default <${target}>;`, | ||
' acl:mode acl:Read, acl:Write, acl:Control.', | ||
'' | ||
].join('\n') | ||
if (accessToModes) { | ||
str += [ | ||
'<#bobAccessTo> a acl:Authorization;', | ||
' acl:agentClass acl:PayingAgent;', | ||
` acl:accessTo <${target}>;`, | ||
` acl:mode ${accessToModes}.`, | ||
'' | ||
].join('\n') | ||
} | ||
if (defaultModes) { | ||
str += [ | ||
'<#bobDefault> a acl:Authorization;', | ||
' acl:agentClass acl:PayingAgent;', | ||
` acl:default <${target}>;`, | ||
` acl:mode ${defaultModes}.`, | ||
'' | ||
].join('\n') | ||
} | ||
return str | ||
} | ||
|
||
describe('Read-Paying', () => { | ||
let solidLogicAlice: SolidLogic; | ||
let solidLogicBob: SolidLogic; | ||
beforeAll(async () => { | ||
solidLogicAlice = await getSolidLogicInstance('ALICE') | ||
solidLogicBob = await getSolidLogicInstance('BOB') | ||
}); | ||
|
||
const { testFolderUrl } = generateTestFolder('ALICE'); | ||
beforeEach(async () => { | ||
// FIXME: NSS ACL cache, | ||
// wait for ACL cache to clear: | ||
await new Promise(resolve => setTimeout(resolve, 20)); | ||
}); | ||
|
||
afterEach(() => { | ||
// return solidLogicAlice.recursiveDelete(testFolderUrl); | ||
}); | ||
it('Gives a 402 with accessTo Read access on non-container resource', async () => { | ||
const resourceUrl = `${testFolderUrl}1/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 aclDocUrl = await solidLogicAlice.findAclDocUrl(resourceUrl); | ||
await solidLogicAlice.fetch(aclDocUrl, { | ||
method: 'PUT', | ||
body: makeBody('acl:Read', null, resourceUrl), | ||
headers: { | ||
'Content-Type': 'text/turtle', | ||
// 'If-None-Match': '*' - work around a bug in some servers that don't support If-None-Match on ACL doc URLs | ||
} | ||
}); | ||
const result = await solidLogicBob.fetch(resourceUrl) | ||
expect(result.status).toEqual("402"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters