This commit is contained in:
parent
8a264bfa58
commit
669bc19943
@ -22,7 +22,11 @@ interface SignatureResult {
|
|||||||
|
|
||||||
class Authority {
|
class Authority {
|
||||||
public verify (key: string): VerificationResult {
|
public verify (key: string): VerificationResult {
|
||||||
const result = { authorized: false, type: 'none', next_module: '' };
|
const result: VerificationResult = {
|
||||||
|
authorized: false,
|
||||||
|
type: 'none',
|
||||||
|
next_module: ''
|
||||||
|
};
|
||||||
const data = verify_signature_get_info (
|
const data = verify_signature_get_info (
|
||||||
key,
|
key,
|
||||||
(info) => keystore.get_key (info.iat / 1000),
|
(info) => keystore.get_key (info.iat / 1000),
|
||||||
@ -49,7 +53,7 @@ class Authority {
|
|||||||
next_module?: string
|
next_module?: string
|
||||||
): SignatureResult {
|
): SignatureResult {
|
||||||
const time = Date.now ();
|
const time = Date.now ();
|
||||||
const key = keystore.get_key (time / 1000);
|
const key = keystore.get_key (time / 1000, valid_for);
|
||||||
const attributes = {
|
const attributes = {
|
||||||
id: create_salt (),
|
id: create_salt (),
|
||||||
iat: time,
|
iat: time,
|
||||||
|
54
test/spec/Authority.ts
Normal file
54
test/spec/Authority.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
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');
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user