Skip to content

Commit 430abd1

Browse files
authored
.meta and remove mashlib hack (#1563)
* check .meta and remove mashlib patch * cleaning * remove mashlib patch * add bach charlie card
1 parent 2e65a19 commit 430abd1

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

lib/handlers/put.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ const debug = require('debug')('solid:put')
55
const getContentType = require('../utils').getContentType
66
const HTTPError = require('../http-error')
77
const { stringToStream } = require('../utils')
8-
const LDP = require('../ldp')
98

109
async function handler (req, res, next) {
1110
debug(req.originalUrl)
1211
res.header('MS-Author-Via', 'SPARQL')
1312

1413
const contentType = req.get('content-type')
15-
if (LDP.mimeTypeIsRdf(contentType) && isAclFile(req)) {
16-
return bodyParser.text({ type: () => true })(req, res, () => putAcl(req, res, next))
14+
if (isAuxiliary(req)) {
15+
if (contentType === 'text/turtle') {
16+
return bodyParser.text({ type: () => true })(req, res, () => putAuxiliary(req, res, next))
17+
} else return next(new HTTPError(415, 'RDF file contains invalid syntax'))
1718
}
1819
return putStream(req, res, next)
1920
}
@@ -34,7 +35,9 @@ async function putStream (req, res, next, stream = req) {
3435
}
3536
}
3637

37-
function putAcl (req, res, next) {
38+
// needed to avoid breaking access with bad acl
39+
// or breaking containement triples for meta
40+
function putAuxiliary (req, res, next) {
3841
const ldp = req.app.locals.ldp
3942
const contentType = req.get('content-type')
4043
const requestUri = ldp.resourceMapper.getRequestUrl(req)
@@ -46,7 +49,8 @@ function putAcl (req, res, next) {
4649
next(new HTTPError(400, 'RDF file contains invalid syntax'))
4750
}
4851

49-
function isAclFile (req) {
52+
function isAuxiliary (req) {
5053
const originalUrlParts = req.originalUrl.split('.')
51-
return originalUrlParts[originalUrlParts.length - 1] === 'acl'
54+
const ext = originalUrlParts[originalUrlParts.length - 1]
55+
return (ext === 'acl' || ext === 'meta')
5256
}

lib/ldp.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ class LDP {
4545
constructor (argv = {}) {
4646
extend(this, argv)
4747

48-
// Acl contentType
49-
if (!this.aclContentType) {
50-
this.aclContentType = 'text/turtle'
51-
}
52-
5348
// Suffixes
5449
if (!this.suffixAcl) {
5550
this.suffixAcl = suffixAcl
@@ -242,9 +237,6 @@ class LDP {
242237
async put (url, stream, contentType) {
243238
const container = (url.url || url).endsWith('/')
244239

245-
// mashlib patch
246-
if ((url.url || url).endsWith('.dummy')) contentType = 'text/turtle'
247-
248240
// PUT without content type is forbidden, unless PUTting container
249241
if (!contentType && !container) {
250242
throw error(400,
@@ -254,11 +246,6 @@ class LDP {
254246
// check if a folder or file with same name exists
255247
await this.checkItemName(url)
256248

257-
// not to break pod : url ACL must have text/turtle contentType
258-
if ((url.url || url).endsWith(this.suffixAcl) && contentType !== this.aclContentType) {
259-
throw error(415, 'PUT contentType for ACL must be text-turtle')
260-
}
261-
262249
// First check if we are above quota
263250
let isOverQuota
264251
// Someone had a reason to make url actually a req sometimes but not
@@ -273,7 +260,7 @@ class LDP {
273260
throw error(413, 'User has exceeded their storage quota')
274261
}
275262

276-
// Create folder using folder/.meta. This is Hack to find folder path
263+
// Set url using folder/.meta. This is Hack to find folder path
277264
if (container) {
278265
if (typeof url !== 'string') {
279266
url.url = url.url + suffixMeta

test/integration/http-test.js

+18
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,24 @@ describe('HTTP APIs', function () {
486486
.set('content-type', 'text/plain')
487487
.expect(415, done)
488488
})
489+
it('should reject create .acl resource, if body is not valid turtle', function (done) {
490+
server.put('/put-resource-1.acl')
491+
.send('bad turtle content')
492+
.set('content-type', 'text/turtle')
493+
.expect(400, done)
494+
})
495+
it('should reject create .meta resource, if contentType not text/turtle', function (done) {
496+
server.put('/.meta')
497+
.send(putRequestBody)
498+
.set('content-type', 'text/plain')
499+
.expect(415, done)
500+
})
501+
it('should reject create .meta resource, if body is not valid turtle', function (done) {
502+
server.put('/.meta')
503+
.send(JSON.stringify({}))
504+
.set('content-type', 'text/turtle')
505+
.expect(400, done)
506+
})
489507
it('should create directories if they do not exist', function (done) {
490508
server.put('/foo/bar/baz.ttl')
491509
.send(putRequestBody)

test/integration/ldp-test.js

-7
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,6 @@ describe('LDP', function () {
177177
assert.equal(err.status, 400)
178178
})
179179
})
180-
181-
it('should fail if file.acl and content type not text/turtle', () => {
182-
const stream = stringToStream('hello world')
183-
return ldp.put('/resources/testPut.txt.acl', stream, 'text/plain').catch(err => {
184-
assert.equal(err.status, 415)
185-
})
186-
})
187180
})
188181

189182
describe('delete', function () {

0 commit comments

Comments
 (0)