Skip to content

Commit c3abe25

Browse files
committed
Update unit tests to new ResourceMapper
1 parent 73cae8a commit c3abe25

File tree

10 files changed

+126
-75
lines changed

10 files changed

+126
-75
lines changed

lib/ldp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class LDP {
331331
} catch (err) {
332332
throw error(404, 'Can\'t find file requested: ' + options)
333333
}
334-
const baseUri = this.resourceMapper.getBaseUrl(options.hostname)
334+
const baseUri = this.resourceMapper.resolveUrl(options.hostname)
335335

336336
// Just return, since resource exists
337337
if (!options.includeBody) {

test/integration/account-manager-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ chai.should()
99
const LDP = require('../../lib/ldp')
1010
const SolidHost = require('../../lib/models/solid-host')
1111
const AccountManager = require('../../lib/models/account-manager')
12-
const LegacyResourceMapper = require('../../lib/legacy-resource-mapper')
12+
const ResourceMapper = require('../../lib/resource-mapper')
1313

1414
const testAccountsDir = path.join(__dirname, '../resources/accounts')
1515
const accountTemplatePath = path.join(__dirname, '../../default-templates/new-account')
@@ -30,7 +30,7 @@ describe('AccountManager', () => {
3030

3131
describe('in multi user mode', () => {
3232
let multiuser = true
33-
let resourceMapper = new LegacyResourceMapper({
33+
let resourceMapper = new ResourceMapper({
3434
rootUrl: 'https://localhost:8443/',
3535
rootPath: process.cwd(),
3636
includeHost: multiuser,
@@ -61,7 +61,7 @@ describe('AccountManager', () => {
6161
let multiuser = false
6262

6363
it('resolves to true if root .acl exists in root storage', () => {
64-
let resourceMapper = new LegacyResourceMapper({
64+
let resourceMapper = new ResourceMapper({
6565
rootUrl: 'https://localhost:8443/',
6666
includeHost: multiuser,
6767
rootPath: path.join(testAccountsDir, 'tim.localhost'),
@@ -81,7 +81,7 @@ describe('AccountManager', () => {
8181
})
8282

8383
it('resolves to false if root .acl does not exist in root storage', () => {
84-
let resourceMapper = new LegacyResourceMapper({
84+
let resourceMapper = new ResourceMapper({
8585
rootUrl: 'https://localhost:8443/',
8686
includeHost: multiuser,
8787
rootPath: testAccountsDir,
@@ -105,7 +105,7 @@ describe('AccountManager', () => {
105105
describe('createAccountFor()', () => {
106106
it('should create an account directory', () => {
107107
let multiuser = true
108-
let resourceMapper = new LegacyResourceMapper({
108+
let resourceMapper = new ResourceMapper({
109109
rootUrl: 'https://localhost:8443/',
110110
includeHost: multiuser,
111111
rootPath: testAccountsDir,

test/integration/acl-oidc-test.js

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ describe('ACL with WebID+OIDC over HTTP', function () {
9292
const origin1 = 'http://example.org/'
9393
const origin2 = 'http://example.com/'
9494

95-
function createOptions (path, user) {
95+
function createOptions (path, user, contentType = 'text/plain') {
9696
const options = {
9797
url: timAccountUri + path,
9898
headers: {
9999
'accept': 'text/turtle',
100-
'content-type': 'text/plain'
100+
'content-type': contentType
101101
}
102102
}
103103
if (user) {
@@ -220,7 +220,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
220220
})
221221
})
222222
it("should create test file's acl file", function (done) {
223-
var options = createOptions('/write-acl/test-file.acl', 'user1')
223+
var options = createOptions('/write-acl/test-file.acl', 'user1', 'text/turtle')
224224
options.body = ''
225225
request.put(options, function (error, response, body) {
226226
assert.equal(error, null)
@@ -254,7 +254,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
254254
})
255255

256256
it('should PUT new ACL file', function (done) {
257-
var options = createOptions('/origin/test-folder/.acl', 'user1')
257+
var options = createOptions('/origin/test-folder/.acl', 'user1', 'text/turtle')
258258
options.body = '<#Owner> a <http://www.w3.org/ns/auth/acl#Authorization>;\n' +
259259
' <http://www.w3.org/ns/auth/acl#accessTo> <https://localhost:3456/origin/test-folder/.acl>;\n' +
260260
' <http://www.w3.org/ns/auth/acl#agent> <' + user1 + '>;\n' +
@@ -362,7 +362,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
362362
})
363363
})
364364
it('user1 should be able to modify ACL file', function (done) {
365-
var options = createOptions('/read-acl/.acl', 'user1')
365+
var options = createOptions('/read-acl/.acl', 'user1', 'text/turtle')
366366
options.body = body
367367
request.put(options, function (error, response, body) {
368368
assert.equal(error, null)
@@ -387,7 +387,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
387387
})
388388
})
389389
it('user2 should not be able to modify ACL file', function (done) {
390-
var options = createOptions('/read-acl/.acl', 'user2')
390+
var options = createOptions('/read-acl/.acl', 'user2', 'text/turtle')
391391
options.body = '<d> <e> <f> .'
392392
request.put(options, function (error, response, body) {
393393
assert.equal(error, null)
@@ -404,7 +404,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
404404
})
405405
})
406406
it('agent should not be able to modify ACL file', function (done) {
407-
var options = createOptions('/read-acl/.acl')
407+
var options = createOptions('/read-acl/.acl', null, 'text/turtle')
408408
options.body = '<d> <e> <f> .'
409409
request.put(options, function (error, response, body) {
410410
assert.equal(error, null)
@@ -434,6 +434,16 @@ describe('ACL with WebID+OIDC over HTTP', function () {
434434
done()
435435
})
436436
})
437+
it('user1 should be able to PATCH an existing resource', function (done) {
438+
var options = createOptions('/append-inherited/test.ttl', 'user1')
439+
options.body = 'INSERT DATA { :test :hello 789 .}'
440+
options.headers['content-type'] = 'application/sparql-update'
441+
request.patch(options, function (error, response, body) {
442+
assert.equal(error, null)
443+
assert.equal(response.statusCode, 200)
444+
done()
445+
})
446+
})
437447
it('user1 should be able to access test file', function (done) {
438448
var options = createOptions('/append-acl/abc.ttl', 'user1')
439449
request.head(options, function (error, response, body) {
@@ -444,7 +454,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
444454
})
445455
// TODO POST instead of PUT
446456
it('user1 should be able to modify test file', function (done) {
447-
var options = createOptions('/append-acl/abc.ttl', 'user1')
457+
var options = createOptions('/append-acl/abc.ttl', 'user1', 'text/turtle')
448458
options.body = '<a> <b> <c> .\n'
449459
request.put(options, function (error, response, body) {
450460
assert.equal(error, null)
@@ -453,23 +463,23 @@ describe('ACL with WebID+OIDC over HTTP', function () {
453463
})
454464
})
455465
it("user2 should not be able to access test file's ACL file", function (done) {
456-
var options = createOptions('/append-acl/abc.ttl.acl', 'user2')
466+
var options = createOptions('/append-acl/abc.ttl.acl', 'user2', 'text/turtle')
457467
request.head(options, function (error, response, body) {
458468
assert.equal(error, null)
459469
assert.equal(response.statusCode, 403)
460470
done()
461471
})
462472
})
463473
it('user2 should not be able to access test file', function (done) {
464-
var options = createOptions('/append-acl/abc.ttl', 'user2')
474+
var options = createOptions('/append-acl/abc.ttl', 'user2', 'text/turtle')
465475
request.head(options, function (error, response, body) {
466476
assert.equal(error, null)
467477
assert.equal(response.statusCode, 403)
468478
done()
469479
})
470480
})
471481
it('user2 (with append permission) cannot use PUT to append', function (done) {
472-
var options = createOptions('/append-acl/abc.ttl', 'user2')
482+
var options = createOptions('/append-acl/abc.ttl', 'user2', 'text/turtle')
473483
options.body = '<d> <e> <f> .\n'
474484
request.put(options, function (error, response, body) {
475485
assert.equal(error, null)
@@ -486,7 +496,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
486496
})
487497
})
488498
it('agent (with append permissions) should not PUT', function (done) {
489-
var options = createOptions('/append-acl/abc.ttl')
499+
var options = createOptions('/append-acl/abc.ttl', null, 'text/turtle')
490500
options.body = '<g> <h> <i> .\n'
491501
request.put(options, function (error, response, body) {
492502
assert.equal(error, null)
@@ -540,7 +550,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
540550
})
541551
it.skip('user2 should be able to write a file in the test directory',
542552
function (done) {
543-
var options = createOptions('/group/test-folder/test.ttl', 'user2')
553+
var options = createOptions('/group/test-folder/test.ttl', 'user2', 'text/turtle')
544554
options.body = '<#Dahut> a <https://dbpedia.org/resource/Category:French_legendary_creatures>.\n'
545555

546556
request.put(options, function (error, response, body) {
@@ -550,7 +560,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
550560
})
551561
})
552562
it.skip('user1 should be able to get the file', function (done) {
553-
var options = createOptions('/group/test-folder/test.ttl', 'user1')
563+
var options = createOptions('/group/test-folder/test.ttl', 'user1', 'text/turtle')
554564

555565
request.get(options, function (error, response, body) {
556566
assert.equal(error, null)
@@ -560,7 +570,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
560570
})
561571
it.skip('user2 should not be able to write to the ACL',
562572
function (done) {
563-
var options = createOptions('/group/test-folder/.acl', 'user2')
573+
var options = createOptions('/group/test-folder/.acl', 'user2', 'text/turtle')
564574
options.body = '<#Dahut> a <https://dbpedia.org/resource/Category:French_legendary_creatures>.\n'
565575

566576
request.put(options, function (error, response, body) {
@@ -570,7 +580,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
570580
})
571581
})
572582
it.skip('user1 should be able to delete the file', function (done) {
573-
var options = createOptions('/group/test-folder/test.ttl', 'user1')
583+
var options = createOptions('/group/test-folder/test.ttl', 'user1', 'text/turtle')
574584

575585
request.delete(options, function (error, response, body) {
576586
assert.equal(error, null)
@@ -610,7 +620,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
610620
' <http://www.w3.org/ns/auth/acl#agent> <' + user2 + '>;\n' +
611621
' <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'
612622
it("user1 should be able to modify test file's ACL file", function (done) {
613-
var options = createOptions('/append-acl/abc2.ttl.acl', 'user1')
623+
var options = createOptions('/append-acl/abc2.ttl.acl', 'user1', 'text/turtle')
614624
options.body = body
615625
request.put(options, function (error, response, body) {
616626
assert.equal(error, null)
@@ -619,23 +629,23 @@ describe('ACL with WebID+OIDC over HTTP', function () {
619629
})
620630
})
621631
it("user1 should be able to access test file's ACL file", function (done) {
622-
var options = createOptions('/append-acl/abc2.ttl.acl', 'user1')
632+
var options = createOptions('/append-acl/abc2.ttl.acl', 'user1', 'text/turtle')
623633
request.head(options, function (error, response, body) {
624634
assert.equal(error, null)
625635
assert.equal(response.statusCode, 200)
626636
done()
627637
})
628638
})
629639
it('user1 should be able to access test file', function (done) {
630-
var options = createOptions('/append-acl/abc2.ttl', 'user1')
640+
var options = createOptions('/append-acl/abc2.ttl', 'user1', 'text/turtle')
631641
request.head(options, function (error, response, body) {
632642
assert.equal(error, null)
633643
assert.equal(response.statusCode, 200)
634644
done()
635645
})
636646
})
637647
it('user1 should be able to modify test file', function (done) {
638-
var options = createOptions('/append-acl/abc2.ttl', 'user1')
648+
var options = createOptions('/append-acl/abc2.ttl', 'user1', 'text/turtle')
639649
options.body = '<a> <b> <c> .\n'
640650
request.put(options, function (error, response, body) {
641651
assert.equal(error, null)
@@ -660,7 +670,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
660670
})
661671
})
662672
it('user2 should be able to modify test file', function (done) {
663-
var options = createOptions('/append-acl/abc2.ttl', 'user2')
673+
var options = createOptions('/append-acl/abc2.ttl', 'user2', 'text/turtle')
664674
options.body = '<d> <e> <f> .\n'
665675
request.put(options, function (error, response, body) {
666676
assert.equal(error, null)
@@ -677,7 +687,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
677687
})
678688
})
679689
it('agent should not be able to modify test file', function (done) {
680-
var options = createOptions('/append-acl/abc2.ttl')
690+
var options = createOptions('/append-acl/abc2.ttl', null, 'text/turtle')
681691
options.body = '<d> <e> <f> .\n'
682692
request.put(options, function (error, response, body) {
683693
assert.equal(error, null)
@@ -704,7 +714,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
704714
' <http://www.w3.org/ns/auth/acl#agentClass> <http://xmlns.com/foaf/0.1/Agent>;\n' +
705715
' <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read> .\n'
706716
it("user1 should be able to modify test directory's ACL file", function (done) {
707-
var options = createOptions('/write-acl/default-for-new/.acl', 'user1')
717+
var options = createOptions('/write-acl/default-for-new/.acl', 'user1', 'text/turtle')
708718
options.body = body
709719
request.put(options, function (error, response, body) {
710720
assert.equal(error, null)
@@ -721,7 +731,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
721731
})
722732
})
723733
it('user1 should be able to create new test file', function (done) {
724-
var options = createOptions('/write-acl/default-for-new/test-file.ttl', 'user1')
734+
var options = createOptions('/write-acl/default-for-new/test-file.ttl', 'user1', 'text/turtle')
725735
options.body = '<a> <b> <c> .\n'
726736
request.put(options, function (error, response, body) {
727737
assert.equal(error, null)
@@ -754,7 +764,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
754764
})
755765
})
756766
it('user2 should not be able to modify new test file', function (done) {
757-
var options = createOptions('/write-acl/default-for-new/test-file.ttl', 'user2')
767+
var options = createOptions('/write-acl/default-for-new/test-file.ttl', 'user2', 'text/turtle')
758768
options.body = '<d> <e> <f> .\n'
759769
request.put(options, function (error, response, body) {
760770
assert.equal(error, null)
@@ -771,7 +781,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
771781
})
772782
})
773783
it('agent should not be able to modify new test file', function (done) {
774-
var options = createOptions('/write-acl/default-for-new/test-file.ttl')
784+
var options = createOptions('/write-acl/default-for-new/test-file.ttl', null, 'text/turtle')
775785
options.body = '<d> <e> <f> .\n'
776786
request.put(options, function (error, response, body) {
777787
assert.equal(error, null)

test/integration/acl-tls-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ describe('ACL with WebID+TLS', function () {
272272
})
273273

274274
it('should PUT new ACL file', function (done) {
275-
var options = createOptions('/acl-tls/origin/test-folder/.acl', 'user1')
275+
var options = createOptions('/acl-tls/origin/test-folder/.acl', 'user1', 'text/turtle')
276276
options.headers = {
277277
'content-type': 'text/turtle'
278278
}
@@ -370,7 +370,7 @@ describe('ACL with WebID+TLS', function () {
370370
})
371371

372372
it('should PUT new ACL file', function (done) {
373-
var options = createOptions('/acl-tls/origin/test-folder/.acl', 'user1')
373+
var options = createOptions('/acl-tls/origin/test-folder/.acl', 'user1', 'text/turtle')
374374
options.headers = {
375375
'content-type': 'text/turtle'
376376
}

test/integration/formats-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,15 @@ describe('formats', function () {
9595
.expect(200, done)
9696
})
9797

98-
it('should return turtle when listing container', function (done) {
98+
it('should return turtle when listing container with an index page', function (done) {
9999
server.get('/sampleContainer/')
100+
.set('accept', 'application/rdf+xml;q=0.4, application/xhtml+xml;q=0.3, text/xml;q=0.2, application/xml;q=0.2, text/html;q=0.3, text/plain;q=0.1, text/turtle;q=1.0, application/n3;q=1')
101+
.expect('content-type', /text\/html/)
102+
.expect(200, done)
103+
})
104+
105+
it('should return turtle when listing container without an index page', function (done) {
106+
server.get('/sampleContainer2/')
100107
.set('accept', 'application/rdf+xml;q=0.4, application/xhtml+xml;q=0.3, text/xml;q=0.2, application/xml;q=0.2, text/html;q=0.3, text/plain;q=0.1, text/turtle;q=1.0, application/n3;q=1')
101108
.expect('content-type', /text\/turtle/)
102109
.expect(200, done)

0 commit comments

Comments
 (0)