@@ -41,11 +41,7 @@ test('aclCheck checkAccess() test - Append access implied by Write acecss', t =>
41
41
const origin = null
42
42
43
43
const result = aclLogic . checkAccess ( store , resource , directory , aclDoc , agent , modesRequired , origin , trustedOrigins )
44
- if ( result ) {
45
- t . ok ( result , 'Alice should have Append access implied by Write access' )
46
- } else {
47
- t . fail ( 'Alice should have Append access implied by Write access' )
48
- }
44
+ t . ok ( result , 'Alice should have Append access implied by Write access' )
49
45
t . end ( )
50
46
} )
51
47
@@ -65,25 +61,13 @@ test('acl-check checkAccess() test - accessTo', function (t) {
65
61
$rdf . parse ( ACLtext , store , containerAclUrl , 'text/turtle' )
66
62
67
63
var result = aclLogic . checkAccess ( store , container , null , containerAcl , alice , [ ACL ( 'Read' ) ] )
68
- if ( result ) {
69
- t . ok ( result , 'Alice should have Read acces' )
70
- } else {
71
- t . fail ( 'Alice s....' )
72
- }
64
+ t . ok ( result , 'Alice should have Read acces' )
73
65
74
66
result = aclLogic . checkAccess ( store , container , null , containerAcl , alice , [ ACL ( 'Write' ) ] )
75
- if ( result ) {
76
- t . ok ( result , 'Alice should have Write acces' )
77
- } else {
78
- t . fail ( 'Alice s....' )
79
- }
67
+ t . ok ( result , 'Alice should have Write acces' )
80
68
81
- result = aclLogic . checkAccess ( store , container , null , containerAcl , bob , [ ACL ( 'Write' ) ] )
82
- if ( ! result ) {
83
- t . ok ( result , 'Bob should not have Write acces' )
84
- } else {
85
- t . fail ( 'Alice s....' )
86
- }
69
+ result = ! aclLogic . checkAccess ( store , container , null , containerAcl , bob , [ ACL ( 'Write' ) ] )
70
+ t . ok ( result , 'Bob Should not have access' )
87
71
88
72
t . end ( )
89
73
} )
@@ -111,30 +95,18 @@ test('acl-check checkAccess() test - default/inherited', function (t) {
111
95
$rdf . parse ( containerAclText , store , containerAcl . uri , 'text/turtle' )
112
96
113
97
result = aclLogic . checkAccess ( store , file1 , container , containerAcl , alice , [ ACL ( 'Read' ) ] )
114
- if ( result ) {
115
- t . ok ( result , 'Alice should have Read acces inherited' )
116
- } else {
117
- t . fail ( 'Alice s....' )
118
- }
98
+ t . ok ( result , 'Alice should have Read acces inherited' )
119
99
120
100
result = aclLogic . checkAccess ( store , file2 , container , containerAcl , alice , [ ACL ( 'Read' ) ] )
121
- if ( result ) {
122
- t . ok ( result , 'Alice should have Read acces inherited 2' )
123
- } else {
124
- t . fail ( 'Alice s....' )
125
- }
101
+ t . ok ( result , 'Alice should have Read acces inherited 2' )
126
102
127
- result = aclLogic . checkAccess ( store , file2 , container , containerAcl , alice , [ ACL ( 'Read' ) ] )
128
- if ( result ) {
129
- t . ok ( result , 'Mallory should NOT have Read acces inherited' )
130
- } else {
131
- t . fail ( 'Alice s....' )
132
- }
103
+ result = ! aclLogic . checkAccess ( store , file2 , container , containerAcl , alice , [ ACL ( 'Write' ) ] )
104
+ t . ok ( result , 'Alice should NOT have Write acces inherited' )
133
105
134
106
t . end ( )
135
107
} )
136
108
137
- // Public access VESRIONS OF THESE
109
+ ///////////////////////////////////////// Public access VESRIONS OF THESE
138
110
// Append access implied by Write acecss -PUBLIC
139
111
test ( 'aclCheck checkAccess() test - Append access implied by Public Write acecss' , t => {
140
112
let resource = $rdf . sym ( 'https://alice.example.com/docs/file1' )
@@ -144,24 +116,17 @@ test('aclCheck checkAccess() test - Append access implied by Public Write acecss
144
116
const store = $rdf . graph ( ) // Quad store
145
117
const ACLtext = prefixes +
146
118
` <#auth> a acl:Authorization;
147
- acl:mode acl:Read ;
119
+ acl:mode acl:Write ;
148
120
acl:agentClass foaf:Agent;
149
121
acl:accessTo <${ resource . uri } > .
150
122
`
151
123
$rdf . parse ( ACLtext , store , aclUrl , 'text/turtle' )
152
124
153
- const agent = alice
154
- const directory = null
155
125
const modesRequired = [ ACL ( 'Append' ) ]
156
- const trustedOrigins = null
157
- const origin = null
158
126
159
- const result = aclLogic . checkAccess ( store , resource , directory , aclDoc , agent , modesRequired , origin , trustedOrigins )
160
- if ( result ) {
161
- t . ok ( result , 'Alice should have Append access implied by Write access - Public' )
162
- } else {
163
- t . fail ( 'Alice should have Append access implied by Write access - Public' )
164
- }
127
+ let result = aclLogic . checkAccess ( store , resource , null , aclDoc , alice , modesRequired )
128
+ t . ok ( result , 'Alice should have Append access implied by Write access - Public' )
129
+
165
130
t . end ( )
166
131
} )
167
132
@@ -181,39 +146,19 @@ test('acl-check checkAccess() test - accessTo', function (t) {
181
146
$rdf . parse ( ACLtext , store , containerAclUrl , 'text/turtle' )
182
147
183
148
var result = aclLogic . checkAccess ( store , container , null , containerAcl , alice , [ ACL ( 'Read' ) ] )
184
- if ( result ) {
185
- t . ok ( result , 'Alice should have Read acces - Public' )
186
- } else {
187
- t . fail ( 'Alice s....' )
188
- }
149
+ t . ok ( result , 'Alice should have Read acces - Public' )
189
150
190
151
result = aclLogic . checkAccess ( store , container , null , containerAcl , alice , [ ACL ( 'Write' ) ] )
191
- if ( result ) {
192
- t . ok ( result , 'Alice should have Write acces' )
193
- } else {
194
- t . fail ( 'Alice s....' )
195
- }
152
+ t . ok ( result , 'Alice should have Write acces' )
196
153
197
154
var result = aclLogic . checkAccess ( store , container , null , containerAcl , null , [ ACL ( 'Read' ) ] )
198
- if ( result ) {
199
- t . ok ( result , 'Anonymous should have Read acces to public thing - Public' )
200
- } else {
201
- t . fail ( 'Alice s....' )
202
- }
155
+ t . ok ( result , 'Anonymous should have Read acces to public thing - Public' )
203
156
204
157
result = aclLogic . checkAccess ( store , container , null , containerAcl , null , [ ACL ( 'Write' ) ] )
205
- if ( result ) {
206
- t . ok ( result , 'Anonymous should have Write acces - Public' )
207
- } else {
208
- t . fail ( 'Alice s....' )
209
- }
158
+ t . ok ( result , 'Anonymous should have Write acces - Public' )
210
159
211
160
result = aclLogic . checkAccess ( store , container , null , containerAcl , bob , [ ACL ( 'Write' ) ] )
212
- if ( result ) {
213
- t . ok ( result , 'Bob should have Write acces to public write - Public' )
214
- } else {
215
- t . fail ( 'Alice s....' )
216
- }
161
+ t . ok ( result , 'Bob should have Write acces to public write - Public' )
217
162
218
163
t . end ( )
219
164
} )
@@ -241,25 +186,104 @@ test('acl-check checkAccess() test - default/inherited', function (t) {
241
186
$rdf . parse ( containerAclText , store , containerAcl . uri , 'text/turtle' )
242
187
243
188
result = aclLogic . checkAccess ( store , file1 , container , containerAcl , alice , [ ACL ( 'Read' ) ] )
244
- if ( result ) {
245
- t . ok ( result , 'Alice should have Read acces inherited - Public' )
246
- } else {
247
- t . fail ( 'Alice s....' )
248
- }
189
+ t . ok ( result , 'Alice should have Read acces inherited - Public' )
249
190
250
191
result = aclLogic . checkAccess ( store , file2 , container , containerAcl , alice , [ ACL ( 'Read' ) ] )
251
- if ( result ) {
252
- t . ok ( result , 'Alice should have Read acces inherited 2 - Public' )
253
- } else {
254
- t . fail ( 'Alice s....' )
255
- }
192
+ t . ok ( result , 'Alice should have Read acces inherited 2 - Public' )
193
+
194
+ result = ! aclLogic . checkAccess ( store , file2 , container , containerAcl , alice , [ ACL ( 'Write' ) ] )
195
+ t . ok ( result , 'Alice should NOT have write acces inherited - Public' )
196
+
197
+ t . end ( )
198
+ } )
199
+
200
+ //////////////////////////// Non-anonymoud versions
201
+ // Append access implied by Write acecss -PUBLIC
202
+ test ( 'aclCheck checkAccess() test - Append access implied by Public Write acecss' , t => {
203
+ let resource = $rdf . sym ( 'https://alice.example.com/docs/file1' )
204
+ let aclUrl = 'https://alice.example.com/docs/.acl'
205
+ let aclDoc = $rdf . sym ( aclUrl )
206
+
207
+ const store = $rdf . graph ( ) // Quad store
208
+ const ACLtext = prefixes +
209
+ ` <#auth> a acl:Authorization;
210
+ acl:mode acl:Write;
211
+ acl:agentClass acl:AuthenticatedAgent;
212
+ acl:accessTo <${ resource . uri } > .
213
+ `
214
+ $rdf . parse ( ACLtext , store , aclUrl , 'text/turtle' )
215
+
216
+ const modesRequired = [ ACL ( 'Append' ) ]
217
+
218
+ let result = aclLogic . checkAccess ( store , resource , null , aclDoc , alice , modesRequired )
219
+ t . ok ( result , 'Alice should have Append access implied by Write access - AuthenticatedAgent' )
220
+
221
+ t . end ( )
222
+ } )
223
+
224
+ // Straight ACL access test
225
+ test ( 'acl-check checkAccess() test - accessTo' , function ( t ) {
226
+ let container = $rdf . sym ( 'https://alice.example.com/docs/' )
227
+ let containerAclUrl = 'https://alice.example.com/docs/.acl'
228
+ let containerAcl = $rdf . sym ( containerAclUrl )
229
+
230
+ const store = $rdf . graph ( ) // Quad store
231
+ const ACLtext = prefixes +
232
+ ` <#auth> a acl:Authorization;
233
+ acl:mode acl:Read, acl:Write;
234
+ acl:agentClass acl:AuthenticatedAgent;
235
+ acl:accessTo <${ container . uri } > .
236
+ `
237
+ $rdf . parse ( ACLtext , store , containerAclUrl , 'text/turtle' )
238
+
239
+ var result = aclLogic . checkAccess ( store , container , null , containerAcl , alice , [ ACL ( 'Read' ) ] )
240
+ t . ok ( result , 'Alice should have Read acces - AuthenticatedAgent' )
241
+
242
+ result = aclLogic . checkAccess ( store , container , null , containerAcl , alice , [ ACL ( 'Write' ) ] )
243
+ t . ok ( result , 'Alice should have Write acces' )
244
+
245
+ var result = ! aclLogic . checkAccess ( store , container , null , containerAcl , null , [ ACL ( 'Read' ) ] )
246
+ t . ok ( result , 'Anonymous should NOT have Read acces to public thing - AuthenticatedAgent' )
247
+
248
+ result = ! aclLogic . checkAccess ( store , container , null , containerAcl , null , [ ACL ( 'Write' ) ] )
249
+ t . ok ( result , 'Anonymous should NOT have Write acces - AuthenticatedAgent' )
250
+
251
+ result = aclLogic . checkAccess ( store , container , null , containerAcl , bob , [ ACL ( 'Write' ) ] )
252
+ t . ok ( result , 'Bob should have Write acces to public write - AuthenticatedAgent' )
253
+
254
+ t . end ( )
255
+ } )
256
+
257
+ // Inheriting permissions from directory defaults
258
+ test ( 'acl-check checkAccess() test - default/inherited' , function ( t ) {
259
+ let container = $rdf . sym ( 'https://alice.example.com/docs/' )
260
+ let containerAcl = $rdf . sym ( 'https://alice.example.com/docs/.acl' )
261
+ let file1 = $rdf . sym ( 'https://alice.example.com/docs/file1' )
262
+ let file2 = $rdf . sym ( 'https://alice.example.com/docs/stuff/file2' )
263
+ var result
264
+ const store = $rdf . graph ( )
265
+ let ACLtext = prefixes + ` <#auth> a acl:Authorization;
266
+ acl:mode acl:Read;
267
+ acl:agent bob:me;
268
+ acl:accessTo <${ file1 . uri } > .
269
+ `
270
+ $rdf . parse ( ACLtext , store , containerAcl . uri , 'text/turtle' )
271
+
272
+ let containerAclText = prefixes + ` <#auth> a acl:Authorization;
273
+ acl:mode acl:Read;
274
+ acl:agentClass acl:AuthenticatedAgent;
275
+ acl:default <${ container . uri } > .
276
+ `
277
+ $rdf . parse ( containerAclText , store , containerAcl . uri , 'text/turtle' )
278
+
279
+ result = aclLogic . checkAccess ( store , file1 , container , containerAcl , alice , [ ACL ( 'Read' ) ] )
280
+ t . ok ( result , 'Alice should have Read acces inherited - AuthenticatedAgent' )
256
281
257
282
result = aclLogic . checkAccess ( store , file2 , container , containerAcl , alice , [ ACL ( 'Read' ) ] )
258
- if ( result ) {
259
- t . ok ( result , 'Mallory should NOT have Read acces inherited - Public' )
260
- } else {
261
- t . fail ( 'Alice s....' )
262
- }
283
+ t . ok ( result , 'Alice should have Read acces inherited 2 - AuthenticatedAgent' )
284
+
285
+ result = ! aclLogic . checkAccess ( store , file2 , container , containerAcl , alice , [ ACL ( 'Write' ) ] )
286
+ t . ok ( result , 'Alice should NOT have write acces inherited - AuthenticatedAgent' )
263
287
264
288
t . end ( )
265
289
} )
0 commit comments