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.
This commit is contained in:
Benjamin Kroeger 2016-04-13 16:34:41 +02:00 committed by Miroslav Bajtoš
parent 6bbe7be266
commit 83b5d72073
1 changed files with 34 additions and 0 deletions

View File

@ -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 ' + it('should overwrite existing token when enableDoublecheck ' +
'and overwriteExistingToken options are truthy', 'and overwriteExistingToken options are truthy',
function(done) { function(done) {