unpkg/modules/__tests__/AuthAPI-test.js

40 lines
996 B
JavaScript
Raw Normal View History

2018-02-18 02:00:56 +00:00
const AuthAPI = require("../AuthAPI");
2017-11-11 20:18:13 +00:00
2017-11-25 21:25:01 +00:00
describe("Auth API", () => {
2017-11-11 20:18:13 +00:00
beforeEach(done => {
2018-02-18 02:00:56 +00:00
AuthAPI.removeAllRevokedTokens().then(() => done(), done);
});
2017-11-11 20:18:13 +00:00
2017-11-25 21:25:01 +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
AuthAPI.createToken(scopes).then(token => {
AuthAPI.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
2017-11-25 21:25:01 +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
AuthAPI.createToken(scopes).then(token => {
AuthAPI.revokeToken(token).then(() => {
AuthAPI.verifyToken(token).then(payload => {
2018-02-18 02:00:56 +00:00
expect(payload).toBe(null);
done();
});
});
});
});
});