Skip to content

Commit

Permalink
Test for resultProperty option
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan committed Dec 21, 2016
1 parent 3acc373 commit 13ae992
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,34 @@ describe('work tests', function () {
});
});

it('should set resultProperty if option provided', function() {
var secret = 'shhhhhh';
var token = jwt.sign({foo: 'bar'}, secret);

req = { };
res = { };
req.headers = {};
req.headers.authorization = 'Bearer ' + token;
expressjwt({secret: secret, resultProperty: 'locals.user'})(req, res, function() {
assert.equal('bar', res.locals.user.foo);
assert.ok(typeof req.user === 'undefined');
});
});

it('should ignore userProperty if resultProperty option provided', function() {
var secret = 'shhhhhh';
var token = jwt.sign({foo: 'bar'}, secret);

req = { };
res = { };
req.headers = {};
req.headers.authorization = 'Bearer ' + token;
expressjwt({secret: secret, userProperty: 'auth', resultProperty: 'locals.user'})(req, res, function() {
assert.equal('bar', res.locals.user.foo);
assert.ok(typeof req.auth === 'undefined');
});
});

it('should work if no authorization header and credentials are not required', function() {
req = {};
expressjwt({ secret: 'shhhh', credentialsRequired: false })(req, res, function(err) {
Expand Down

0 comments on commit 13ae992

Please sign in to comment.