Skip to content

Commit f753ec2

Browse files
First attempt at payment-required test
1 parent 84ee0d3 commit f753ec2

File tree

5 files changed

+111
-36
lines changed

5 files changed

+111
-36
lines changed

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

run-against-nss.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ echo Automated way to get an OIDC issuer cookie for Alice:
2222
export CURL_RESULT_ALICE=`curl -ki $OIDC_ISSUER_ALICE/login/password -d"username=$USERNAME_ALICE&password=$PASSWORD_ALICE" | grep Set-Cookie`
2323
export COOKIE_ALICE=`expr "$CURL_RESULT_ALICE" : '^Set-Cookie:\ \(.*\).'`
2424

25-
# echo Automated way to get an OIDC issuer cookie for Bob:
26-
# export CURL_RESULT_BOB=`curl -ki $OIDC_ISSUER_BOB/login/password -d"username=$USERNAME_BOB&password=$PASSWORD_BOB" | grep Set-Cookie`
27-
# export COOKIE_BOB=`expr "$CURL_RESULT_BOB" : '^Set-Cookie:\ \(.*\).'`
25+
echo Automated way to get an OIDC issuer cookie for Bob:
26+
export CURL_RESULT_BOB=`curl -ki $OIDC_ISSUER_BOB/login/password -d"username=$USERNAME_BOB&password=$PASSWORD_BOB" | grep Set-Cookie`
27+
export COOKIE_BOB=`expr "$CURL_RESULT_BOB" : '^Set-Cookie:\ \(.*\).'`
2828

2929
echo Running with these values for Alice:
3030
echo Cookie: $COOKIE_ALICE

test/helpers/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function generateTestFolder(who: string) {
2727
console.warn(`Adding slash to the end of ${who}'s storage root ->"${storageRoot}"+"/"`);
2828
storageRoot += '/';
2929
}
30-
const testFolder = `web-access-control-tests-${new Date().getTime()}`;
30+
const testFolder = `monetization-tests-${new Date().getTime()}`;
3131
return {
3232
testFolder,
3333
testFolderUrl: `${storageRoot}${testFolder}/`
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { SolidLogic } from 'solid-logic';
2+
import { generateTestFolder, getSolidLogicInstance, WEBID_ALICE, WEBID_BOB } from '../helpers/env';
3+
import { responseCodeGroup } from '../helpers/util';
4+
5+
function makeBody(accessToModes: string, defaultModes: string, target: string) {
6+
let str = [
7+
'@prefix acl: <http://www.w3.org/ns/auth/acl#>.',
8+
'',
9+
`<#alice> a acl:Authorization;\n acl:agent <${WEBID_ALICE}>;`,
10+
` acl:accessTo <${target}>;`,
11+
` acl:default <${target}>;`,
12+
' acl:mode acl:Read, acl:Write, acl:Control.',
13+
''
14+
].join('\n')
15+
if (accessToModes) {
16+
str += [
17+
'<#bobAccessTo> a acl:Authorization;',
18+
' acl:agentClass acl:PayingAgent;',
19+
` acl:accessTo <${target}>;`,
20+
` acl:mode ${accessToModes}.`,
21+
''
22+
].join('\n')
23+
}
24+
if (defaultModes) {
25+
str += [
26+
'<#bobDefault> a acl:Authorization;',
27+
' acl:agentClass acl:PayingAgent;',
28+
` acl:default <${target}>;`,
29+
` acl:mode ${defaultModes}.`,
30+
''
31+
].join('\n')
32+
}
33+
return str
34+
}
35+
36+
describe('Read-Paying', () => {
37+
let solidLogicAlice: SolidLogic;
38+
let solidLogicBob: SolidLogic;
39+
beforeAll(async () => {
40+
solidLogicAlice = await getSolidLogicInstance('ALICE')
41+
solidLogicBob = await getSolidLogicInstance('BOB')
42+
});
43+
44+
const { testFolderUrl } = generateTestFolder('ALICE');
45+
beforeEach(async () => {
46+
// FIXME: NSS ACL cache,
47+
// wait for ACL cache to clear:
48+
await new Promise(resolve => setTimeout(resolve, 20));
49+
});
50+
51+
afterEach(() => {
52+
// return solidLogicAlice.recursiveDelete(testFolderUrl);
53+
});
54+
it('Gives a 402 with accessTo Read access on non-container resource', async () => {
55+
const resourceUrl = `${testFolderUrl}1/test.txt`;
56+
// This will do mkdir-p:
57+
const creationResult = await solidLogicAlice.fetch(resourceUrl, {
58+
method: 'PUT',
59+
body: '<#hello> <#linked> <#world> .',
60+
headers: {
61+
'Content-Type': 'text/turtle',
62+
'If-None-Match': '*'
63+
}
64+
});
65+
const aclDocUrl = await solidLogicAlice.findAclDocUrl(resourceUrl);
66+
await solidLogicAlice.fetch(aclDocUrl, {
67+
method: 'PUT',
68+
body: makeBody('acl:Read', null, resourceUrl),
69+
headers: {
70+
'Content-Type': 'text/turtle',
71+
// 'If-None-Match': '*' - work around a bug in some servers that don't support If-None-Match on ACL doc URLs
72+
}
73+
});
74+
const result = await solidLogicBob.fetch(resourceUrl)
75+
expect(result.status).toEqual("402");
76+
});
77+
});

test/surface/vanity-payment-pointer.test.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,32 @@ import { getSolidLogicInstance, WEBID_ALICE } from '../helpers/env';
33
import { responseCodeGroup } from '../helpers/util';
44
import fetch from 'node-fetch';
55

6+
async function setPaymentPointer(solidLogic, paymentPointer) {
7+
const body = '@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n' +
8+
'@prefix pp: <http://paymentpointers.org/ns#>.\n' +
9+
`<#me> pp:PaymentPointer "${paymentPointer}";\n` +
10+
' acl:trustedApp [\n'+
11+
' acl:mode acl:Append, acl:Control, acl:Read, acl:Write;\n'+
12+
' acl:origin <https://tester>\n'+
13+
' ].';
14+
const result = await solidLogic.fetch(solidLogic.me, {
15+
method: 'PUT',
16+
body,
17+
headers: {
18+
'Content-Type': 'text/turtle'
19+
}
20+
});
21+
expect(responseCodeGroup(result.status)).toEqual('2xx');
22+
}
23+
624
describe('Vanity Payment Pointer', () => {
725
let solidLogicAlice: SolidLogic;
826
beforeAll(async () => {
927
solidLogicAlice = await getSolidLogicInstance('ALICE')
1028
});
1129

1230
describe('Alice has a pp:PaymentPointer triple in her profile, no slash', () => {
13-
beforeAll(async () => {
14-
const result = await solidLogicAlice.fetch(solidLogicAlice.me, {
15-
method: 'PUT',
16-
body: '<#me> <http://paymentpointers.org/ns#PaymentPointer> "$example.com" .',
17-
headers: {
18-
'Content-Type': 'text/turtle'
19-
}
20-
});
21-
expect(responseCodeGroup(result.status)).toEqual('2xx');
22-
});
23-
31+
beforeAll(() => setPaymentPointer(solidLogicAlice, '$example.com'));
2432
it('makes /.well-known/pay redirects to it', async () => {
2533
const podRoot = new URL(solidLogicAlice.me).origin;
2634
const result = await fetch(`${podRoot}/.well-known/pay`, { redirect: 'manual' });
@@ -29,17 +37,7 @@ describe('Vanity Payment Pointer', () => {
2937
});
3038
});
3139
describe('Alice has a pp:PaymentPointer triple in her profile, with slash', () => {
32-
beforeAll(async () => {
33-
const result = await solidLogicAlice.fetch(solidLogicAlice.me, {
34-
method: 'PUT',
35-
body: '<#me> <http://paymentpointers.org/ns#PaymentPointer> "$example.com/foo/bar" .',
36-
headers: {
37-
'Content-Type': 'text/turtle'
38-
}
39-
});
40-
expect(responseCodeGroup(result.status)).toEqual('2xx');
41-
});
42-
40+
beforeAll(() => setPaymentPointer(solidLogicAlice, '$example.com/foo/bar'));
4341
it('makes /.well-known/pay redirects to it', async () => {
4442
const podRoot = new URL(solidLogicAlice.me).origin;
4543
const result = await fetch(`${podRoot}/.well-known/pay`, { redirect: 'manual' });

0 commit comments

Comments
 (0)