From 83b5d72073397420c252093b9e52f1dc58d823b3 Mon Sep 17 00:00:00 2001 From: Benjamin Kroeger Date: Wed, 13 Apr 2016 16:34:41 +0200 Subject: [PATCH] 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 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/access-token.test.js b/test/access-token.test.js index ab391255..8844c486 100644 --- a/test/access-token.test.js +++ b/test/access-token.test.js @@ -267,6 +267,40 @@ 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) {