UNPKG

649 BPlain TextView Raw
1import * as jwt from 'jsonwebtoken';
2import * as express from 'express';
3import { expressjwt, ExpressJwtRequest } from '../src';
4import assert from 'assert';
5
6
7describe('string tokens', function () {
8 const req = {} as ExpressJwtRequest<string>;
9 const res = {} as express.Response;
10
11 it('should work with a valid string token', function (done) {
12 const secret = 'shhhhhh';
13 const token = jwt.sign('foo', secret);
14
15 req.headers = {};
16 req.headers.authorization = 'Bearer ' + token;
17 expressjwt({ secret: secret, algorithms: ['HS256'] })(req, res, function () {
18 assert.equal(req.auth, 'foo');
19 done();
20 });
21 });
22
23});