Skip to content

Commit dbee984

Browse files
authored
Merge pull request #1710 from nodeSolidServer/issue1707-1708
issues 1707-1708
2 parents 698f73c + 8639f28 commit dbee984

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

lib/handlers/put.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ async function handler (req, res, next) {
1111
res.header('MS-Author-Via', 'SPARQL')
1212

1313
const contentType = req.get('content-type')
14-
if (isAuxiliary(req)) {
14+
// check for valid rdf content for auxiliary resource and /profile/card
15+
// in future we may check that /profile/card is a minimal valid WebID card
16+
if (isAuxiliary(req) || req.originalUrl === '/profile/card') {
1517
if (contentType === 'text/turtle') {
16-
return bodyParser.text({ type: () => true })(req, res, () => putAuxiliary(req, res, next))
18+
return bodyParser.text({ type: () => true })(req, res, () => putValidRdf(req, res, next))
1719
} else return next(new HTTPError(415, 'RDF file contains invalid syntax'))
1820
}
1921
return putStream(req, res, next)
@@ -37,7 +39,7 @@ async function putStream (req, res, next, stream = req) {
3739

3840
// needed to avoid breaking access with bad acl
3941
// or breaking containement triples for meta
40-
function putAuxiliary (req, res, next) {
42+
function putValidRdf (req, res, next) {
4143
const ldp = req.app.locals.ldp
4244
const contentType = req.get('content-type')
4345
const requestUri = ldp.resourceMapper.getRequestUrl(req)

lib/ldp.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ class LDP {
535535
return this.deleteContainer(path)
536536
} else {
537537
// DELETE method not allowed on podRoot/.acl
538-
if ((url.url || url) === '/' + this.suffixAcl) {
539-
throw error(405, 'DELETE of PodRoot/.acl is not allowed')
538+
if (['/' + this.suffixAcl, '/profile/card'].some(item => (url.url || url) === item)) {
539+
throw error(405, `DELETE of ${url.url || url} is not allowed`)
540540
}
541541
return this.deleteDocument(path)
542542
}

test/integration/http-test.js

+16
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ describe('HTTP APIs', function () {
587587
return Promise.all([
588588
rm('/false-file-48484848'),
589589
createTestResource('/.acl'),
590+
createTestResource('/profile/card$.ttl'),
590591
createTestResource('/delete-test-empty-container/.meta.acl'),
591592
createTestResource('/put-resource-1.ttl'),
592593
createTestResource('/put-resource-with-acl.ttl'),
@@ -625,6 +626,20 @@ describe('HTTP APIs', function () {
625626
})
626627
})
627628

629+
it('should return 405 status when deleting /profile/card', function (done) {
630+
server.delete('/profile/card')
631+
.expect(405)
632+
.end((err, res) => {
633+
if (err) return done(err)
634+
try {
635+
assert.equal(res.get('allow').includes('DELETE'), false) // ,'res methods')
636+
} catch (err) {
637+
return done(err)
638+
}
639+
done()
640+
})
641+
})
642+
628643
it('should return 404 status when deleting a file that does not exists',
629644
function (done) {
630645
server.delete('/false-file-48484848')
@@ -672,6 +687,7 @@ describe('HTTP APIs', function () {
672687

673688
after(function () {
674689
// Clean up after DELETE API tests
690+
rm('/profile/')
675691
rm('/put-resource-1.ttl')
676692
rm('/delete-test-non-empty/')
677693
rm('/delete-test-empty-container/test.txt.acl')

0 commit comments

Comments
 (0)