Skip to content

Commit 3afe36b

Browse files
committed
added example test and recursive suffix checking in ldp.post
1 parent e4bb2e9 commit 3afe36b

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/ldp.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class LDP {
137137
}
138138

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

156157
if (container) {
157158
// the name of a container cannot be a valid auxiliary resource document
158-
if (this._containsInvalidSuffixes(slug + '/')) slug = slug.split('.')[0]
159+
while (this._containsInvalidSuffixes(slug + '/')) {
160+
console.log('splitting slug', slug)
161+
// slug = slug.split('.')[0]
162+
const idx = slug.lastIndexOf('.')
163+
slug = slug.substr(0, idx)
164+
console.log('new slug', slug)
165+
}
159166
} else if (this.isAuxResource(slug, extension)) throw error(403, 'POST is not allowed for auxiliary resources')
160167

161168
if (slug.match(/\/|\||:/)) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
"validate": "node ./test/validate-turtle.js",
147147
"nyc": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 nyc --reporter=text-summary mocha --recursive test/integration/ test/unit/",
148148
"mocha": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 mocha --recursive test/integration/ test/unit/",
149+
"mocha-integration": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 mocha --recursive test/integration/http-test.js",
149150
"prepublishOnly": "npm test",
150151
"postpublish": "git push --follow-tags",
151152
"test": "npm run standard && npm run validate && npm run nyc",

test/integration/http-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,15 @@ describe('HTTP APIs', function () {
923923
.expect(hasHeader('acl', suffixAcl))
924924
.expect(201, done)
925925
})
926+
it('should do something', function (done) {
927+
server.post('/post-tests/')
928+
.set('content-type', 'text/turtle')
929+
.set('slug', 'foo.bar.acl.meta')
930+
.set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"')
931+
.send(postRequest2Body)
932+
.expect('location', /\/post-tests\/foo.bar\//)
933+
.expect(201, done)
934+
})
926935
it('should fail return 404 if no parent container found', function (done) {
927936
server.post('/hello.html/')
928937
.send(postRequest1Body)

0 commit comments

Comments
 (0)