From 23da604e3661f7fde849dbbfa1369b9fe813a586 Mon Sep 17 00:00:00 2001 From: jaxoncreed Date: Mon, 21 Oct 2019 16:40:44 -0400 Subject: [PATCH 1/2] Fix error when content type is not provided --- lib/ldp.js | 2 +- test/integration/http-test.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/ldp.js b/lib/ldp.js index 76663685b..fcc40dbf7 100644 --- a/lib/ldp.js +++ b/lib/ldp.js @@ -158,7 +158,7 @@ class LDP { // HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data // for JSON bodies. So, the stream needs to be reset - if (contentType.includes('application/json')) { + if (contentType && contentType.includes('application/json')) { stream = intoStream(JSON.stringify(stream.body)) } diff --git a/test/integration/http-test.js b/test/integration/http-test.js index f1e70a1e3..51f3984f5 100644 --- a/test/integration/http-test.js +++ b/test/integration/http-test.js @@ -559,6 +559,29 @@ describe('HTTP APIs', function () { .expect(hasHeader('acl', suffixAcl)) .expect(201, done) }) + it('should create new resource even if body is empty', function (done) { + server.post('/post-tests/') + .set('slug', 'post-resource-empty') + .set('content-type', 'text/turtle') + .expect(hasHeader('describedBy', suffixMeta)) + .expect(hasHeader('acl', suffixAcl)) + .expect('location', /.*\.ttl/) + .expect(201, done) + }) + it('should error with 415 if the body is empty and no content type is provided', function (done) { + server.post('/post-tests/') + .set('slug', 'post-resource-empty-fail') + .expect(415, done) + }) + it('should create a resource if parsable rdf is provided but with no content-type header', function (done) { + server.post('/post-tests/') + .set('slug', 'post-resource-rdf-no-content-type') + .send(postRequest1Body) + .expect(hasHeader('describedBy', suffixMeta)) + .expect(hasHeader('acl', suffixAcl)) + .expect('location', '/post-tests/post-resource-rdf-no-content-type') + .expect(201, done) + }) it('should create new resource even if no trailing / is in the target', function (done) { server.post('') From bb2309d17baf6275d5de52ca2b1b4a6de71c06c3 Mon Sep 17 00:00:00 2001 From: jaxoncreed Date: Tue, 22 Oct 2019 15:22:11 -0400 Subject: [PATCH 2/2] Updated test to properly reflect not sending a content-type --- test/integration/http-test.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/integration/http-test.js b/test/integration/http-test.js index 51f3984f5..1df460360 100644 --- a/test/integration/http-test.js +++ b/test/integration/http-test.js @@ -573,14 +573,12 @@ describe('HTTP APIs', function () { .set('slug', 'post-resource-empty-fail') .expect(415, done) }) - it('should create a resource if parsable rdf is provided but with no content-type header', function (done) { + it('should error with 415 if the body is provided but there is no content-type header', function (done) { server.post('/post-tests/') .set('slug', 'post-resource-rdf-no-content-type') .send(postRequest1Body) - .expect(hasHeader('describedBy', suffixMeta)) - .expect(hasHeader('acl', suffixAcl)) - .expect('location', '/post-tests/post-resource-rdf-no-content-type') - .expect(201, done) + .set('content-type', '') + .expect(415, done) }) it('should create new resource even if no trailing / is in the target', function (done) {