Skip to content

Commit

Permalink
added example test and recursive suffix checking in ldp.post
Browse files Browse the repository at this point in the history
  • Loading branch information
zg009 committed Mar 29, 2024
1 parent e4bb2e9 commit 3afe36b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/ldp.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class LDP {
}

async post (hostname, containerPath, stream, { container, slug, extension, contentType }) {
console.log('container:', container)
// POST without content type is forbidden
if (!contentType) {
throw error(400,
Expand All @@ -155,7 +156,13 @@ class LDP {

if (container) {
// the name of a container cannot be a valid auxiliary resource document
if (this._containsInvalidSuffixes(slug + '/')) slug = slug.split('.')[0]
while (this._containsInvalidSuffixes(slug + '/')) {
console.log('splitting slug', slug)
// slug = slug.split('.')[0]
const idx = slug.lastIndexOf('.')
slug = slug.substr(0, idx)
console.log('new slug', slug)
}
} else if (this.isAuxResource(slug, extension)) throw error(403, 'POST is not allowed for auxiliary resources')

if (slug.match(/\/|\||:/)) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"validate": "node ./test/validate-turtle.js",
"nyc": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 nyc --reporter=text-summary mocha --recursive test/integration/ test/unit/",
"mocha": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 mocha --recursive test/integration/ test/unit/",
"mocha-integration": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 mocha --recursive test/integration/http-test.js",
"prepublishOnly": "npm test",
"postpublish": "git push --follow-tags",
"test": "npm run standard && npm run validate && npm run nyc",
Expand Down
9 changes: 9 additions & 0 deletions test/integration/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,15 @@ describe('HTTP APIs', function () {
.expect(hasHeader('acl', suffixAcl))
.expect(201, done)
})
it('should do something', function (done) {
server.post('/post-tests/')
.set('content-type', 'text/turtle')
.set('slug', 'foo.bar.acl.meta')
.set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"')
.send(postRequest2Body)
.expect('location', /\/post-tests\/foo.bar\//)
.expect(201, done)
})
it('should fail return 404 if no parent container found', function (done) {
server.post('/hello.html/')
.send(postRequest1Body)
Expand Down

0 comments on commit 3afe36b

Please sign in to comment.