From 50a3f4ed3e7abb2f099327c0cfca89ae107e8b4c Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Wed, 12 Jul 2017 15:16:56 -0400 Subject: [PATCH 1/3] Report parse error. Closes #13. --- lib/parse.js | 2 +- test/test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index ce2a9dc..b002198 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -7,6 +7,6 @@ function parse (profile, graph, uri, mimeType, callback) { $rdf.parse(profile, graph, uri, mimeType) return callback(null, graph) } catch(e) { - return callback('Cound not load/parse profile data') + return callback(new Error('Could not load/parse profile data: ' + e)) } } diff --git a/test/test.js b/test/test.js index b834389..b4fbccb 100644 --- a/test/test.js +++ b/test/test.js @@ -31,7 +31,7 @@ describe('WebID', function () { '', 'text/html', function (err, result) { - expect(err).to.equal('Cound not load/parse profile data') + expect(err.message).to.include('Could not load/parse profile data') done() }) }) From e878319548d8d3667ddb304db6d1c3a3a527d864 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Wed, 12 Jul 2017 15:28:56 -0400 Subject: [PATCH 2/3] Correctly determine MIME type. Closes #15. --- tls/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tls/index.js b/tls/index.js index 522abfa..6b75cad 100644 --- a/tls/index.js +++ b/tls/index.js @@ -29,13 +29,13 @@ function verify (certificate, callback) { // Get first URI var uri = uris.shift() - get(uri, function (err, body, headers) { + get(uri, function (err, body, contentType) { if (err) { return callback(err) } // Verify Key - verifyKey(certificate, uri, body, headers, function (err, success) { + verifyKey(certificate, uri, body, contentType, function (err, success) { return callback(err, uri) }) }) @@ -54,7 +54,7 @@ function getUris (certificate) { return uris } -function verifyKey (certificate, uri, profile, mimeType, callback) { +function verifyKey (certificate, uri, profile, contentType, callback) { var graph = new Graph() var found = false @@ -66,6 +66,7 @@ function verifyKey (certificate, uri, profile, mimeType, callback) { return callback(new Error('Missing exponent value in client certificate')) } + var mimeType = contentType.replace(/;.*/, '') parse(profile, graph, uri, mimeType, function (err) { if (err) { return callback(err) From ea9c94d3bd733af4b2fb293fbfe4f58093d5143b Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Wed, 12 Jul 2017 15:46:05 -0400 Subject: [PATCH 3/3] Add text/turtle tests. --- test/test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test.js b/test/test.js index b4fbccb..d72fe88 100644 --- a/test/test.js +++ b/test/test.js @@ -35,6 +35,30 @@ describe('WebID', function () { done() }) }) + + it('should succeed on text/turtle', function (done) { + tls.verifyKey( + validCert, + 'https://test_nicola.databox.me/profile/card#me', + '', + 'text/turtle', + function (err, result) { + expect(err.message).to.not.include('Could not load/parse profile data') + done() + }) + }) + + it('should succeed on text/turtle; charset=utf-8', function (done) { + tls.verifyKey( + validCert, + 'https://test_nicola.databox.me/profile/card#me', + '', + 'text/turtle; charset=utf-8', + function (err, result) { + expect(err.message).to.not.include('Could not load/parse profile data') + done() + }) + }) }) describe('verify', function () {