improve signature structure, more tests
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
66
test/spec/Blacklist.ts
Normal file
66
test/spec/Blacklist.ts
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) Sapphirecode - All Rights Reserved
|
||||
* This file is part of Auth-Server-Helper which is released under MIT.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, December 2020
|
||||
*/
|
||||
|
||||
import blacklist from '../../lib/Blacklist';
|
||||
|
||||
// eslint-disable-next-line max-lines-per-function
|
||||
describe ('blacklist', () => {
|
||||
beforeAll (() => {
|
||||
jasmine.clock ()
|
||||
.install ();
|
||||
jasmine.clock ()
|
||||
.mockDate (new Date);
|
||||
});
|
||||
|
||||
it ('should validate any string', () => {
|
||||
expect (blacklist.is_valid ('foo'))
|
||||
.toBeTrue ();
|
||||
expect (blacklist.is_valid ('bar'))
|
||||
.toBeTrue ();
|
||||
expect (blacklist.is_valid ('baz'))
|
||||
.toBeTrue ();
|
||||
});
|
||||
|
||||
it ('should blacklist strings', () => {
|
||||
blacklist.add_signature ('foo');
|
||||
blacklist.add_signature ('bar');
|
||||
expect (blacklist.is_valid ('foo'))
|
||||
.toBeFalse ();
|
||||
expect (blacklist.is_valid ('bar'))
|
||||
.toBeFalse ();
|
||||
expect (blacklist.is_valid ('baz'))
|
||||
.toBeTrue ();
|
||||
});
|
||||
|
||||
it ('should remove one string', () => {
|
||||
blacklist.remove_signature ('foo');
|
||||
expect (blacklist.is_valid ('foo'))
|
||||
.toBeTrue ();
|
||||
expect (blacklist.is_valid ('bar'))
|
||||
.toBeFalse ();
|
||||
expect (blacklist.is_valid ('baz'))
|
||||
.toBeTrue ();
|
||||
});
|
||||
|
||||
it ('should clear after time', () => {
|
||||
jasmine.clock ()
|
||||
.tick (5000);
|
||||
blacklist.add_signature ('baz');
|
||||
blacklist.clear_before (new Date (Date.now () - 100));
|
||||
expect (blacklist.is_valid ('foo'))
|
||||
.toBeTrue ();
|
||||
expect (blacklist.is_valid ('bar'))
|
||||
.toBeTrue ();
|
||||
expect (blacklist.is_valid ('baz'))
|
||||
.toBeFalse ();
|
||||
});
|
||||
|
||||
afterAll (() => {
|
||||
jasmine.clock ()
|
||||
.uninstall ();
|
||||
});
|
||||
});
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* Copyright (C) Sapphirecode - All Rights Reserved
|
||||
* This file is part of Auth-Server-Helper which is released under MIT.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, December 2020
|
||||
*/
|
||||
|
||||
import ks from '../../lib/KeyStore';
|
||||
|
||||
/* eslint-disable-next-line max-lines-per-function */
|
||||
|
Reference in New Issue
Block a user