-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathacl-tls-test.js
More file actions
960 lines (912 loc) · 35.9 KB
/
acl-tls-test.js
File metadata and controls
960 lines (912 loc) · 35.9 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
var assert = require('chai').assert
var fs = require('fs-extra')
var $rdf = require('rdflib')
var request = require('request')
var path = require('path')
var { cleanDir } = require('../utils')
/**
* Note: this test suite requires an internet connection, since it actually
* uses remote accounts https://user1.databox.me and https://user2.databox.me
*/
// Helper functions for the FS
var rm = require('../utils').rm
// var write = require('./utils').write
// var cp = require('./utils').cp
// var read = require('./utils').read
var ldnode = require('../../index')
var ns = require('solid-namespace')($rdf)
const port = 7777
const serverUri = `https://localhost:7777`
const rootPath = path.join(__dirname, '../resources/acl-tls')
const dbPath = path.join(rootPath, 'db')
const configPath = path.join(rootPath, 'config')
var aclExtension = '.acl'
var metaExtension = '.meta'
var testDir = 'acl-tls/testDir'
var testDirAclFile = testDir + '/' + aclExtension
var testDirMetaFile = testDir + '/' + metaExtension
var abcFile = testDir + '/abc.ttl'
var globFile = testDir + '/*'
var origin1 = 'http://example.org/'
var origin2 = 'http://example.com/'
var user1 = 'https://tim.localhost:7777/profile/card#me'
var user2 = 'https://nicola.localhost:7777/profile/card#me'
var address = 'https://tim.localhost:7777'
var userCredentials = {
user1: {
cert: fs.readFileSync(path.join(__dirname, '../keys/user1-cert.pem')),
key: fs.readFileSync(path.join(__dirname, '../keys/user1-key.pem'))
},
user2: {
cert: fs.readFileSync(path.join(__dirname, '../keys/user2-cert.pem')),
key: fs.readFileSync(path.join(__dirname, '../keys/user2-key.pem'))
}
}
// TODO Remove skip. TLS is currently broken, but is not a priority to fix since
// the current Solid spec does not require supporting webid-tls on the resource
// server. The current spec only requires the resource server to support webid-oidc,
// and it requires the IDP to support webid-tls as a log in method, so that users of
// a webid-tls client certificate can still use their certificate (and not a
// username/password pair or other login method) to "bridge" from webid-tls to
// webid-oidc.
describe.skip('ACL with WebID+TLS', function () {
var ldpHttpsServer
var serverConfig = {
root: rootPath,
serverUri,
dbPath,
port,
configPath,
sslKey: path.join(__dirname, '../keys/key.pem'),
sslCert: path.join(__dirname, '../keys/cert.pem'),
webid: true,
multiuser: true,
auth: 'tls',
rejectUnauthorized: false,
strictOrigin: true,
host: { serverUri }
}
var ldp = ldnode.createServer(serverConfig)
before(function (done) {
ldpHttpsServer = ldp.listen(port, () => {
setTimeout(() => {
done()
}, 0)
})
})
after(function () {
if (ldpHttpsServer) ldpHttpsServer.close()
cleanDir(rootPath)
})
function createOptions (path, user) {
var options = {
url: address + path,
headers: {
accept: 'text/turtle',
'content-type': 'text/plain'
}
}
if (user) {
options.agentOptions = userCredentials[user]
}
return options
}
describe('no ACL', function () {
it('should return 500 for any resource', function (done) {
rm('.acl')
var options = createOptions('/acl-tls/no-acl/', 'user1')
request(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 500)
done()
})
})
it('should have `User` set in the Response Header', function (done) {
rm('.acl')
var options = createOptions('/acl-tls/no-acl/', 'user1')
request(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.headers['user'], 'https://user1.databox.me/profile/card#me')
done()
})
})
it.skip('should return a 401 and WWW-Authenticate header without credentials', (done) => {
rm('.acl')
let options = {
url: address + '/acl-tls/no-acl/',
headers: { accept: 'text/turtle' }
}
request(options, (error, response, body) => {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
assert.equal(response.headers['www-authenticate'], 'WebID-TLS realm="https://localhost:8443"')
done()
})
})
})
describe('empty .acl', function () {
describe('with no default in parent path', function () {
it('should give no access', function (done) {
var options = createOptions('/acl-tls/empty-acl/test-folder', 'user1')
options.body = ''
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('should not let edit the .acl', function (done) {
var options = createOptions('/acl-tls/empty-acl/.acl', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = ''
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('should not let read the .acl', function (done) {
var options = createOptions('/acl-tls/empty-acl/.acl', 'user1')
options.headers = {
accept: 'text/turtle'
}
request.get(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
})
describe('with default in parent path', function () {
before(function () {
rm('/acl-tls/write-acl/empty-acl/another-empty-folder/test-file.acl')
rm('/acl-tls/write-acl/empty-acl/test-folder/test-file')
rm('/acl-tls/write-acl/empty-acl/test-file')
rm('/acl-tls/write-acl/test-file')
rm('/acl-tls/write-acl/test-file.acl')
})
it('should fail to create a container', function (done) {
var options = createOptions('/acl-tls/write-acl/empty-acl/test-folder/', 'user1')
options.body = ''
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403) // TODO: SHOULD THIS RETURN A 409?
done()
})
})
it('should not allow creation of new files', function (done) {
var options = createOptions('/acl-tls/write-acl/empty-acl/test-file', 'user1')
options.body = ''
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('should not allow creation of new files in deeper paths', function (done) {
var options = createOptions('/acl-tls/write-acl/empty-acl/test-folder/test-file', 'user1')
options.body = ''
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('Should not create empty acl file', function (done) {
var options = createOptions('/acl-tls/write-acl/empty-acl/another-empty-folder/test-file.acl', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = ''
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('should not return text/turtle for the acl file', function (done) {
var options = createOptions('/acl-tls/write-acl/.acl', 'user1')
options.headers = {
accept: 'text/turtle'
}
request.get(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
// assert.match(response.headers['content-type'], /text\/turtle/)
done()
})
})
it('should create test file', function (done) {
var options = createOptions('/acl-tls/write-acl/test-file', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<a> <b> <c> .'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
})
})
it("should create test file's acl file", function (done) {
var options = createOptions('/acl-tls/write-acl/test-file.acl', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = ''
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
})
})
it("should not access test file's acl file", function (done) {
var options = createOptions('/acl-tls/write-acl/test-file.acl', 'user1')
options.headers = {
accept: 'text/turtle'
}
request.get(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
// assert.match(response.headers['content-type'], /text\/turtle/)
done()
})
})
after(function () {
rm('/acl-tls/write-acl/empty-acl/another-empty-folder/test-file.acl')
rm('/acl-tls/write-acl/empty-acl/test-folder/test-file')
rm('/acl-tls/write-acl/empty-acl/test-file')
rm('/acl-tls/write-acl/test-file')
rm('/acl-tls/write-acl/test-file.acl')
})
})
})
describe('Origin', function () {
before(function () {
rm('acl-tls/origin/test-folder/.acl')
})
it('should PUT new ACL file', function (done) {
var options = createOptions('/acl-tls/origin/test-folder/.acl', 'user1', 'text/turtle')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<#Owner> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
' <http://www.w3.org/ns/auth/acl#accessTo> <https://localhost:3456/test/acl-tls/origin/test-folder/>;\n' +
' <http://www.w3.org/ns/auth/acl#agent> <' + user1 + '>;\n' +
' <http://www.w3.org/ns/auth/acl#origin> <' + origin1 + '>;\n' +
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write>, <http://www.w3.org/ns/auth/acl#Control> .\n' +
'<#Public> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
' <http://www.w3.org/ns/auth/acl#accessTo> <./>;\n' +
' <http://www.w3.org/ns/auth/acl#agentClass> <http://www.w3.org/ns/auth/acl#AuthenticatedAgent>;\n' +
' <http://www.w3.org/ns/auth/acl#origin> <' + origin1 + '>;\n' +
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
// TODO triple header
// TODO user header
})
})
it('user1 should be able to access test directory', function (done) {
var options = createOptions('/acl-tls/origin/test-folder/', 'user1')
options.headers.origin = origin1
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should be able to access to test directory when origin is valid',
function (done) {
var options = createOptions('/acl-tls/origin/test-folder/', 'user1')
options.headers.origin = origin1
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should not be able to access test directory when origin is invalid',
function (done) {
var options = createOptions('/acl-tls/origin/test-folder/', 'user1')
options.headers.origin = origin2
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('agent not should be able to access test directory', function (done) {
var options = createOptions('/acl-tls/origin/test-folder/')
options.headers.origin = origin1
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
it('agent should be able to access to test directory when origin is valid',
function (done) {
var options = createOptions('/acl-tls/origin/test-folder/', 'user1')
options.headers.origin = origin1
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('agent should not be able to access test directory when origin is invalid',
function (done) {
var options = createOptions('/acl-tls/origin/test-folder/')
options.headers.origin = origin2
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
after(function () {
rm('acl-tls/origin/test-folder/.acl')
})
})
describe('Mixed statement Origin', function () {
before(function () {
rm('acl-tls/origin/test-folder/.acl')
})
it('should PUT new ACL file', function (done) {
var options = createOptions('/acl-tls/origin/test-folder/.acl', 'user1', 'text/turtle')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<#Owner1> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
' <http://www.w3.org/ns/auth/acl#accessTo> <https://localhost:3456/test/acl-tls/origin/test-folder/>;\n' +
' <http://www.w3.org/ns/auth/acl#agent> <' + user1 + '>;\n' +
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write>, <http://www.w3.org/ns/auth/acl#Control> .\n' +
'<#Owner2> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
' <http://www.w3.org/ns/auth/acl#accessTo> <https://localhost:3456/test/acl-tls/origin/test-folder/>;\n' +
' <http://www.w3.org/ns/auth/acl#origin> <' + origin1 + '>;\n' +
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write>, <http://www.w3.org/ns/auth/acl#Control> .\n' +
'<#Public> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
' <http://www.w3.org/ns/auth/acl#accessTo> <./>;\n' +
' <http://www.w3.org/ns/auth/acl#agentClass> <http://www.w3.org/ns/auth/acl#AuthenticatedAgent>;\n' +
' <http://www.w3.org/ns/auth/acl#origin> <' + origin1 + '>;\n' +
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
// TODO triple header
// TODO user header
})
})
it('user1 should be able to access test directory', function (done) {
var options = createOptions('/acl-tls/origin/test-folder/', 'user1')
options.headers.origin = origin1
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should be able to access to test directory when origin is valid',
function (done) {
var options = createOptions('/acl-tls/origin/test-folder/', 'user1')
options.headers.origin = origin1
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should not be able to access test directory when origin is invalid',
function (done) {
var options = createOptions('/acl-tls/origin/test-folder/', 'user1')
options.headers.origin = origin2
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('agent should not be able to access test directory for logged in users', function (done) {
var options = createOptions('/acl-tls/origin/test-folder/')
options.headers.origin = origin1
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
it('agent should be able to access to test directory when origin is valid',
function (done) {
var options = createOptions('/acl-tls/origin/test-folder/', 'user1')
options.headers.origin = origin1
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('agent should not be able to access test directory when origin is invalid',
function (done) {
var options = createOptions('/acl-tls/origin/test-folder/')
options.headers.origin = origin2
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
after(function () {
rm('acl-tls/origin/test-folder/.acl')
})
})
describe('Read-only', function () {
var body = fs.readFileSync(path.join(__dirname, '../resources/acl-tls/tim.localhost/read-acl/.acl'))
it('user1 should be able to access ACL file', function (done) {
var options = createOptions('/acl-tls/read-acl/.acl', 'user1')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should be able to access test directory', function (done) {
var options = createOptions('/acl-tls/read-acl/', 'user1')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should be able to modify ACL file', function (done) {
var options = createOptions('/acl-tls/read-acl/.acl', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = body
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
})
})
it('user2 should be able to access test directory', function (done) {
var options = createOptions('/acl-tls/read-acl/', 'user2')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user2 should not be able to access ACL file', function (done) {
var options = createOptions('/acl-tls/read-acl/.acl', 'user2')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('user2 should not be able to modify ACL file', function (done) {
var options = createOptions('/acl-tls/read-acl/.acl', 'user2')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<d> <e> <f> .'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('agent should be able to access test direcotory', function (done) {
var options = createOptions('/acl-tls/read-acl/')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('agent should not be able to modify ACL file', function (done) {
var options = createOptions('/acl-tls/read-acl/.acl')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<d> <e> <f> .'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
})
describe.skip('Glob', function () {
it('user2 should be able to send glob request', function (done) {
var options = createOptions(globFile, 'user2')
request.get(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
var globGraph = $rdf.graph()
$rdf.parse(body, globGraph, address + testDir + '/', 'text/turtle')
var authz = globGraph.the(undefined, undefined, ns.acl('Authorization'))
assert.equal(authz, null)
done()
})
})
it('user1 should be able to send glob request', function (done) {
var options = createOptions(globFile, 'user1')
request.get(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
var globGraph = $rdf.graph()
$rdf.parse(body, globGraph, address + testDir + '/', 'text/turtle')
var authz = globGraph.the(undefined, undefined, ns.acl('Authorization'))
assert.equal(authz, null)
done()
})
})
it('user1 should be able to delete ACL file', function (done) {
var options = createOptions(testDirAclFile, 'user1')
request.del(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
})
describe('Append-only', function () {
// var body = fs.readFileSync(__dirname + '/resources/acl-tls/append-acl/abc.ttl.acl')
it("user1 should be able to access test file's ACL file", function (done) {
var options = createOptions('/acl-tls/append-acl/abc.ttl.acl', 'user1')
request.head(options, function (error, response) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it.skip('user1 should be able to PATCH a resource', function (done) {
var options = createOptions('/acl-tls/append-inherited/test.ttl', 'user1')
options.headers = {
'content-type': 'application/sparql-update'
}
options.body = 'INSERT DATA { :test :hello 456 .}'
request.patch(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should be able to access test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc.ttl', 'user1')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
// TODO POST instead of PUT
it('user1 should be able to modify test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc.ttl', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<a> <b> <c> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
})
})
it("user2 should not be able to access test file's ACL file", function (done) {
var options = createOptions('/acl-tls/append-acl/abc.ttl.acl', 'user2')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('user2 should not be able to access test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc.ttl', 'user2')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('user2 (with append permission) cannot use PUT to append', function (done) {
var options = createOptions('/acl-tls/append-acl/abc.ttl', 'user2')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<d> <e> <f> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('agent should not be able to access test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc.ttl')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
it('agent (with append permissions) should not PUT', function (done) {
var options = createOptions('/acl-tls/append-acl/abc.ttl')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<g> <h> <i> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
after(function () {
rm('acl-tls/append-inherited/test.ttl')
})
})
describe('Restricted', function () {
var body = '<#Owner> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
' <http://www.w3.org/ns/auth/acl#accessTo> <./abc2.ttl>;\n' +
' <http://www.w3.org/ns/auth/acl#agent> <' + user1 + '>;\n' +
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write>, <http://www.w3.org/ns/auth/acl#Control> .\n' +
'<#Restricted> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
' <http://www.w3.org/ns/auth/acl#accessTo> <./abc2.ttl>;\n' +
' <http://www.w3.org/ns/auth/acl#agent> <' + user2 + '>;\n' +
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write>.\n'
it("user1 should be able to modify test file's ACL file", function (done) {
var options = createOptions('/acl-tls/append-acl/abc2.ttl.acl', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = body
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
})
})
it("user1 should be able to access test file's ACL file", function (done) {
var options = createOptions('/acl-tls/append-acl/abc2.ttl.acl', 'user1')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should be able to access test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc2.ttl', 'user1')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should be able to modify test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc2.ttl', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<a> <b> <c> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
})
})
it('user2 should be able to access test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc2.ttl', 'user2')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it("user2 should not be able to access test file's ACL file", function (done) {
var options = createOptions('/acl-tls/append-acl/abc2.ttl.acl', 'user2')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('user2 should be able to modify test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc2.ttl', 'user2')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<d> <e> <f> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
})
})
it('agent should not be able to access test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc2.ttl')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
it('agent should not be able to modify test file', function (done) {
var options = createOptions('/acl-tls/append-acl/abc2.ttl')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<d> <e> <f> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
})
describe('default', function () {
before(function () {
rm('/acl-tls/write-acl/default-for-new/.acl')
rm('/acl-tls/write-acl/default-for-new/test-file.ttl')
})
var body = '<#Owner> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
' <http://www.w3.org/ns/auth/acl#accessTo> <./>;\n' +
' <http://www.w3.org/ns/auth/acl#agent> <' + user1 + '>;\n' +
' <http://www.w3.org/ns/auth/acl#default> <./>;\n' +
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write>, <http://www.w3.org/ns/auth/acl#Control> .\n' +
'<#Default> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
' <http://www.w3.org/ns/auth/acl#accessTo> <./>;\n' +
' <http://www.w3.org/ns/auth/acl#default> <./>;\n' +
' <http://www.w3.org/ns/auth/acl#agentClass> <http://xmlns.com/foaf/0.1/Agent>;\n' +
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read> .\n'
it("user1 should be able to modify test directory's ACL file", function (done) {
var options = createOptions('/acl-tls/write-acl/default-for-new/.acl', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = body
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
})
})
it("user1 should be able to access test direcotory's ACL file", function (done) {
var options = createOptions('/acl-tls/write-acl/default-for-new/.acl', 'user1')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user1 should be able to create new test file', function (done) {
var options = createOptions('/acl-tls/write-acl/default-for-new/test-file.ttl', 'user1')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<a> <b> <c> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
done()
})
})
it('user1 should be able to access new test file', function (done) {
var options = createOptions('/acl-tls/write-acl/default-for-new/test-file.ttl', 'user1')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it("user2 should not be able to access test direcotory's ACL file", function (done) {
var options = createOptions('/acl-tls/write-acl/default-for-new/.acl', 'user2')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('user2 should be able to access new test file', function (done) {
var options = createOptions('/acl-tls/write-acl/default-for-new/test-file.ttl', 'user2')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('user2 should not be able to modify new test file', function (done) {
var options = createOptions('/acl-tls/write-acl/default-for-new/test-file.ttl', 'user2')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<d> <e> <f> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
done()
})
})
it('agent should be able to access new test file', function (done) {
var options = createOptions('/acl-tls/write-acl/default-for-new/test-file.ttl')
request.head(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
it('agent should not be able to modify new test file', function (done) {
var options = createOptions('/acl-tls/write-acl/default-for-new/test-file.ttl')
options.headers = {
'content-type': 'text/turtle'
}
options.body = '<d> <e> <f> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
done()
})
})
after(function () {
rm('/acl-tls/write-acl/default-for-new/.acl')
rm('/acl-tls/write-acl/default-for-new/test-file.ttl')
})
})
describe('WebID delegation tests', function () {
it('user1 should be able delegate to user2', function (done) {
// var body = '<' + user1 + '> <http://www.w3.org/ns/auth/acl#delegates> <' + user2 + '> .'
var options = {
url: user1,
headers: {
'content-type': 'text/turtle'
},
agentOptions: {
key: userCredentials.user1.key,
cert: userCredentials.user1.cert
}
}
request.post(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
done()
})
})
// it("user2 should be able to make requests on behalf of user1", function(done) {
// var options = createOptions(abcdFile, 'user2')
// options.headers = {
// 'content-type': 'text/turtle',
// 'On-Behalf-Of': '<' + user1 + '>'
// }
// options.body = "<d> <e> <f> ."
// request.post(options, function(error, response, body) {
// assert.equal(error, null)
// assert.equal(response.statusCode, 200)
// done()
// })
// })
})
describe.skip('Cleanup', function () {
it('should remove all files and dirs created', function (done) {
try {
// must remove the ACLs in sync
fs.unlinkSync(path.join(__dirname, '../resources/' + testDir + '/dir1/dir2/abcd.ttl'))
fs.rmdirSync(path.join(__dirname, '../resources/' + testDir + '/dir1/dir2/'))
fs.rmdirSync(path.join(__dirname, '../resources/' + testDir + '/dir1/'))
fs.unlinkSync(path.join(__dirname, '../resources/' + abcFile))
fs.unlinkSync(path.join(__dirname, '../resources/' + testDirAclFile))
fs.unlinkSync(path.join(__dirname, '../resources/' + testDirMetaFile))
fs.rmdirSync(path.join(__dirname, '../resources/' + testDir))
fs.rmdirSync(path.join(__dirname, '../resources/acl-tls/'))
done()
} catch (e) {
done(e)
}
})
})
})