Timo Hocker 669bc19943
Some checks failed
continuous-integration/drone/push Build is failing
tests for authority
2020-12-19 16:19:09 +01:00

55 lines
1.3 KiB
TypeScript

import auth from '../../lib/Authority';
describe ('authority', () => {
beforeEach (() => {
jasmine.clock ()
.install ();
jasmine.clock ()
.mockDate (new Date);
});
afterEach (() => {
jasmine.clock ()
.uninstall ();
});
it ('should create an access token', () => {
const token = auth.sign ('access_token', 60);
jasmine.clock ()
.tick (30000);
const res = auth.verify (token.signature);
expect (res.authorized)
.toBeTrue ();
expect (res.type)
.toEqual ('access_token');
expect (res.next_module)
.toBeUndefined ();
});
it ('should create a refresh token', () => {
const token = auth.sign ('refresh_token', 600);
jasmine.clock ()
.tick (30000);
const res = auth.verify (token.signature);
expect (res.authorized)
.toBeFalse ();
expect (res.type)
.toEqual ('refresh_token');
expect (res.next_module)
.toBeUndefined ();
});
it ('should create a part token', () => {
const token = auth.sign ('part_token', 60, '2fa');
jasmine.clock ()
.tick (30000);
const res = auth.verify (token.signature);
expect (res.authorized)
.toBeFalse ();
expect (res.type)
.toEqual ('part_token');
expect (res.next_module)
.toEqual ('2fa');
});
});