unpkg/modules/utils/__tests__/auth-test.js

40 lines
972 B
JavaScript
Raw Normal View History

2019-01-06 00:50:05 +00:00
import * as auth from '../auth';
2017-11-11 20:18:13 +00:00
2018-12-17 17:38:05 +00:00
describe('Auth API', () => {
2017-11-11 20:18:13 +00:00
beforeEach(done => {
2019-01-06 00:50:05 +00:00
auth.removeAllRevokedTokens().then(() => done(), done);
2018-02-18 02:00:56 +00:00
});
2017-11-11 20:18:13 +00:00
2018-12-17 17:38:05 +00:00
it('creates tokens with the right scopes', done => {
2017-11-11 20:18:13 +00:00
const scopes = {
blacklist: {
add: true,
remove: true
}
2018-02-18 02:00:56 +00:00
};
2017-11-11 20:18:13 +00:00
2019-01-06 00:50:05 +00:00
auth.createToken(scopes).then(token => {
auth.verifyToken(token).then(payload => {
2018-02-18 02:00:56 +00:00
expect(payload.jti).toEqual(expect.any(String));
expect(payload.iss).toEqual(expect.any(String));
expect(payload.iat).toEqual(expect.any(Number));
expect(payload.scopes).toMatchObject(scopes);
done();
});
});
});
2017-11-11 20:18:13 +00:00
2018-12-17 17:38:05 +00:00
it('refuses to verify revoked tokens', done => {
2018-02-18 02:00:56 +00:00
const scopes = {};
2017-11-11 20:18:13 +00:00
2019-01-06 00:50:05 +00:00
auth.createToken(scopes).then(token => {
auth.revokeToken(token).then(() => {
auth.verifyToken(token).then(payload => {
2018-02-18 02:00:56 +00:00
expect(payload).toBe(null);
done();
});
});
});
});
});