-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathacl-doc-application.test.ts
170 lines (149 loc) · 5.58 KB
/
acl-doc-application.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { SolidLogic } from 'solid-logic';
import { generateTestFolder, getSolidLogicInstance, WEBID_ALICE } from '../helpers/env';
import { responseCodeGroup } from '../helpers/util';
function getAclBody(aliceWebId: string, bobWebId: string, target: string, bobAccessTo: string[], bobDefault: string[]) {
let turtle = `@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n\
\n\
<#alice> a acl:Authorization;\n\
acl:agent <${aliceWebId}>;\n\
acl:accessTo <${target}>;\n
acl:default <${target}>;\n
acl:mode acl:Read, acl:Write, acl:Control.\n\
`
if (bobAccessTo.length) {
turtle += `\
<#bobAccessTo> a acl:Authorization;\n\
acl:agent <${bobWebId}>;\n\
acl:accessTo <${target}>;\n
acl:mode ${bobAccessTo.join(', ')}.\n\
`
}
if (bobDefault.length) {
turtle += `\
<#bobAccessTo> a acl:Authorization;\n\
acl:agent <${bobWebId}>;\n\
acl:default <${target}>;\n
acl:mode ${bobDefault.join(' ')}.\n\
`
}
return turtle;
}
describe('ACL doc application', () => {
let solidLogicAlice: SolidLogic;
let solidLogicBob: SolidLogic;
beforeAll(async () => {
solidLogicAlice = await getSolidLogicInstance('ALICE')
solidLogicBob = await getSolidLogicInstance('BOB')
});
describe('No access on container', () => {
const { testFolderUrl } = generateTestFolder('ALICE');
const containerUrl = `${testFolderUrl}denied/`;
beforeAll(async () => {
// This will do mkdir-p:
await solidLogicAlice.fetch(`${testFolderUrl}denied/noAclDoc/noAclDoc.txt`, {
method: 'PUT',
body: 'hello'
});
const aclDocUrl = await solidLogicAlice.findAclDocUrl(`${testFolderUrl}denied/`);
await solidLogicAlice.fetch(aclDocUrl, {
method: 'PUT',
body: getAclBody(solidLogicAlice.me, solidLogicBob.me, containerUrl, [], []),
headers: {
'Content-Type': 'text/turtle'
}
});
// FIXME: NSS ACL cache,
// wait for ACL cache to clear:
await new Promise(resolve => setTimeout(resolve, 20));
});
afterAll(() => {
return solidLogicAlice.recursiveDelete(testFolderUrl);
});
it('does not allow GET denied/', async () => {
const result = await solidLogicBob.fetch(`${testFolderUrl}denied/`);
expect(result.status).toEqual(403);
});
it('does not allow GET denied/noAclDoc/', async () => {
const result = await solidLogicBob.fetch(`${testFolderUrl}denied/noAclDoc/`);
expect(result.status).toEqual(403);
});
it('does not allow GET denied/noAclDoc/noAclDoc.txt', async () => {
const result = await solidLogicBob.fetch(`${testFolderUrl}denied/noAclDoc/noAclDoc.txt`);
expect(result.status).toEqual(403);
});
});
describe('ACL doc with acl:accessTo on container', () => {
const { testFolderUrl } = generateTestFolder('ALICE');
const containerUrl = `${testFolderUrl}accessTo/`;
beforeAll(async () => {
// This will do mkdir-p:
await solidLogicAlice.fetch(`${containerUrl}noAclDoc/noAclDoc.txt`, {
method: 'PUT',
body: 'hello'
});
const aclDocUrl = await solidLogicAlice.findAclDocUrl(containerUrl);
await solidLogicAlice.fetch(aclDocUrl, {
method: 'PUT',
body: getAclBody(solidLogicAlice.me, solidLogicBob.me, containerUrl, ['acl:Read'], []),
headers: {
'Content-Type': 'text/turtle'
}
});
// FIXME: NSS ACL cache,
// wait for ACL cache to clear:
await new Promise(resolve => setTimeout(resolve, 2000));
});
afterAll(() => {
return solidLogicAlice.recursiveDelete(testFolderUrl);
});
it('allows GET accessTo/', async () => {
const result = await solidLogicBob.fetch(containerUrl);
expect(responseCodeGroup(result.status)).toEqual("2xx");
});
it('does not allow GET accessTo/noAclDoc/', async () => {
const result = await solidLogicBob.fetch(`${containerUrl}noAclDoc/`);
expect(result.status).toEqual(403);
});
it('does not allow GET accessTo/noAclDoc/noAclDoc.txt', async () => {
const result = await solidLogicBob.fetch(`${containerUrl}noAclDoc/noAclDoc.txt`);
expect(result.status).toEqual(403);
});
});
describe('ACL doc with acl:default on container', () => {
const { testFolderUrl } = generateTestFolder('ALICE');
const containerUrl = `${testFolderUrl}default/`;
beforeAll(async () => {
// This will do mkdir-p:
await solidLogicAlice.fetch(`${containerUrl}noAclDoc/noAclDoc.txt`, {
method: 'PUT',
body: 'hello'
});
const aclDocUrl = await solidLogicAlice.findAclDocUrl(containerUrl);
await solidLogicAlice.fetch(aclDocUrl, {
method: 'PUT',
body: getAclBody(solidLogicAlice.me, solidLogicBob.me, containerUrl, [], ['acl:Read']),
headers: {
'Content-Type': 'text/turtle'
}
});
// FIXME: NSS ACL cache,
// wait for ACL cache to clear:
await new Promise(resolve => setTimeout(resolve, 2000));
});
afterAll(() => {
return solidLogicAlice.recursiveDelete(testFolderUrl);
});
it('does not allow GET accessTo/', async () => {
const result = await solidLogicBob.fetch(containerUrl);
expect(result.status).toEqual(403);
});
it('allows GET accessTo/noAclDoc/', async () => {
const result = await solidLogicBob.fetch(`${containerUrl}noAclDoc/`);
expect(responseCodeGroup(result.status)).toEqual("2xx");
});
it('allows GET accessTo/noAclDoc/noAclDoc.txt', async () => {
const result = await solidLogicBob.fetch(`${containerUrl}noAclDoc/noAclDoc.txt`);
expect(responseCodeGroup(result.status)).toEqual("2xx");
});
});
});