From 302ef628b235a4f882b562483c344a5ffd1cb506 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 30 Jan 2024 10:40:48 +0100 Subject: [PATCH 1/3] Change translation error to not acceptable --- lib/handlers/get.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/handlers/get.js b/lib/handlers/get.js index f4aed8eeb..f4350f70f 100644 --- a/lib/handlers/get.js +++ b/lib/handlers/get.js @@ -128,8 +128,8 @@ async function handler (req, res, next) { res.send(data) return next() } catch (err) { - debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 500 + ' ' + err.message) - return next(error(500, 'Error translating between RDF formats')) + debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 406 + ' ' + err.message) + return next(error(406, 'Cannot serve requested type: ' + requestedType)) } } From 65b04bbff7153d601c8b7de625d27cfc4365d336 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 30 Jan 2024 13:33:49 +0100 Subject: [PATCH 2/3] Check untranslatable requested type for RDF --- lib/handlers/get.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/handlers/get.js b/lib/handlers/get.js index f4350f70f..dd46461af 100644 --- a/lib/handlers/get.js +++ b/lib/handlers/get.js @@ -116,10 +116,9 @@ async function handler (req, res, next) { // If it is not in our RDFs we can't even translate, // Sorry, we can't help - if (!possibleRDFType) { - return next(error(406, 'Cannot serve requested type: ' + contentType)) + if (!possibleRDFType || !RDFs.includes(requestedType)) { + return next(error(406, 'Cannot serve requested type: ' + requestedType)) } - try { // Translate from the contentType found to the possibleRDFType desired const data = await translate(stream, baseUri, contentType, possibleRDFType) @@ -127,7 +126,8 @@ async function handler (req, res, next) { res.setHeader('Content-Type', possibleRDFType) res.send(data) return next() - } catch (err) { + } + catch (err) { debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 406 + ' ' + err.message) return next(error(406, 'Cannot serve requested type: ' + requestedType)) } From 69ef87c35c005e0b142c5027a58a3764ae4809fd Mon Sep 17 00:00:00 2001 From: bourgeoa Date: Mon, 5 Feb 2024 18:35:35 +0100 Subject: [PATCH 3/3] non RDFs translation error --- lib/handlers/get.js | 9 ++++----- test/integration/acl-oidc-test.js | 4 ++-- test/integration/formats-test.js | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/handlers/get.js b/lib/handlers/get.js index dd46461af..a35924ea6 100644 --- a/lib/handlers/get.js +++ b/lib/handlers/get.js @@ -116,8 +116,8 @@ async function handler (req, res, next) { // If it is not in our RDFs we can't even translate, // Sorry, we can't help - if (!possibleRDFType || !RDFs.includes(requestedType)) { - return next(error(406, 'Cannot serve requested type: ' + requestedType)) + if (!possibleRDFType || !RDFs.includes(contentType)) { // possibleRDFType defaults to text/turtle + return next(error(406, 'Cannot serve requested type: ' + contentType)) } try { // Translate from the contentType found to the possibleRDFType desired @@ -126,10 +126,9 @@ async function handler (req, res, next) { res.setHeader('Content-Type', possibleRDFType) res.send(data) return next() - } - catch (err) { + } catch (err) { debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 406 + ' ' + err.message) - return next(error(406, 'Cannot serve requested type: ' + requestedType)) + return next(error(500, 'Cannot serve requested type: ' + requestedType)) } } diff --git a/test/integration/acl-oidc-test.js b/test/integration/acl-oidc-test.js index 37728724e..524faf4ec 100644 --- a/test/integration/acl-oidc-test.js +++ b/test/integration/acl-oidc-test.js @@ -742,12 +742,12 @@ describe('ACL with WebID+OIDC over HTTP', function () { done() }) }) - it('We should have a 500 with invalid group listings', function (done) { + it('We should have a 406 with invalid group listings', function (done) { const options = createOptions('/group/test-folder/some-other-file.txt', 'user2') request.get(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 500) + assert.equal(response.statusCode, 406) done() }) }) diff --git a/test/integration/formats-test.js b/test/integration/formats-test.js index 0fa43a60e..4a8ef11b1 100644 --- a/test/integration/formats-test.js +++ b/test/integration/formats-test.js @@ -108,6 +108,21 @@ describe('formats', function () { }) }) + describe('text/plain (non RDFs)', function () { + it('Accept text/plain', function (done) { + server.get('/put-input.txt') + .set('accept', 'text/plain') + .expect('Content-type', 'text/plain') + .expect(200, done) + }) + it('Accept text/turtle', function (done) { + server.get('/put-input.txt') + .set('accept', 'text/turtle') + .expect('Content-type', 'text/plain; charset=utf-8') + .expect(406, done) + }) + }) + describe('none', function () { it('should return turtle document if no Accept header is set', function (done) { server.get('/patch-5-initial.ttl')