string_token.test.js 582 B

12345678910111213141516171819202122
  1. var jwt = require('jsonwebtoken');
  2. var assert = require('assert');
  3. var expressjwt = require('../lib');
  4. var UnauthorizedError = require('../lib/errors/UnauthorizedError');
  5. describe('string tokens', function () {
  6. var req = {};
  7. var res = {};
  8. it('should work with a valid string token', function() {
  9. var secret = 'shhhhhh';
  10. var token = jwt.sign('foo', secret);
  11. req.headers = {};
  12. req.headers.authorization = 'Bearer ' + token;
  13. expressjwt({secret: secret, algorithms: ['HS256']})(req, res, function() {
  14. assert.equal('foo', req.user);
  15. });
  16. });
  17. });