From 107da91ae3230feef28e7c738de3b3bbfef11e31 Mon Sep 17 00:00:00 2001 From: Benjamin Kroeger Date: Wed, 13 Apr 2016 16:34:41 +0200 Subject: [PATCH 1/2] add missing unit tests for #2108 subsequent token middleware tries to read `token.id` when `enableDoublecheck: true`. That caused a "Cannot read property `id` of `null`" error when the first middleware didn't actually find a valid accessToken. --- test/access-token.test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/access-token.test.js b/test/access-token.test.js index 17a9d481..a20dc507 100644 --- a/test/access-token.test.js +++ b/test/access-token.test.js @@ -249,6 +249,39 @@ describe('loopback.token(options)', function() { }); }); + it('should overwrite invalid existing token (is !== undefined and has no "id" property) ' + + ' when enableDoubkecheck is true', + function(done) { + var token = this.token; + + app.use(function(req, res, next) { + req.accessToken = null; + next(); + }); + + app.use(loopback.token({ + model: Token, + enableDoublecheck: true, + })); + + app.get('/', function(req, res, next) { + res.send(req.accessToken); + }); + + request(app).get('/') + .set('Authorization', token.id) + .expect(200) + .end(function(err, res) { + if (err) return done(err); + expect(res.body).to.eql({ + id: token.id, + ttl: token.ttl, + userId: token.userId, + created: token.created.toJSON(), + }); + done(); + }); + }); it('should overwrite existing token when enableDoublecheck ' + 'and overwriteExistingToken options are truthy', function(done) { From c2604c9049f5e388263f3604f202186486379874 Mon Sep 17 00:00:00 2001 From: Benjamin Kroeger Date: Wed, 13 Apr 2016 17:26:26 +0200 Subject: [PATCH 2/2] add empty line after unit test for better readablility --- test/access-token.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/access-token.test.js b/test/access-token.test.js index a20dc507..419f73f7 100644 --- a/test/access-token.test.js +++ b/test/access-token.test.js @@ -282,6 +282,7 @@ describe('loopback.token(options)', function() { done(); }); }); + it('should overwrite existing token when enableDoublecheck ' + 'and overwriteExistingToken options are truthy', function(done) {