This commit is contained in:
@ -28,7 +28,7 @@ describe ('crypto helper', () => {
|
||||
.toMatch (/^[0-9a-f]+$/iu);
|
||||
});
|
||||
|
||||
it ('random_hex should refuse lenght smaller 1', () => {
|
||||
it ('random_hex should refuse length smaller 1', () => {
|
||||
expect (
|
||||
() => (crypto.random_hex (0))
|
||||
)
|
||||
@ -55,7 +55,7 @@ describe ('crypto helper', () => {
|
||||
.toEqual (8);
|
||||
});
|
||||
|
||||
it ('random_string should refuse lenght smaller 1', () => {
|
||||
it ('random_string should refuse length smaller 1', () => {
|
||||
expect (
|
||||
() => (crypto.random_string (0))
|
||||
)
|
||||
@ -126,6 +126,14 @@ describe ('crypto helper', () => {
|
||||
.toEqual (dec);
|
||||
});
|
||||
|
||||
it ('should reject tampered signatures', () => {
|
||||
const obj = { foo: 'bar' };
|
||||
const str = crypto.sign_object (obj, 'baz');
|
||||
const dec = crypto.verify_signature (str, 'foo');
|
||||
expect (dec)
|
||||
.toEqual (null);
|
||||
});
|
||||
|
||||
it ('should return null on invalid input', () => {
|
||||
const ver = crypto.verify_signature (null, 'foo');
|
||||
expect (ver)
|
||||
@ -136,44 +144,86 @@ describe ('crypto helper', () => {
|
||||
});
|
||||
|
||||
it ('should not fail verification if timeout unspecified', async () => {
|
||||
jasmine.clock ()
|
||||
.install ();
|
||||
const base_time = (new Date);
|
||||
jasmine.clock ()
|
||||
.mockDate (base_time);
|
||||
|
||||
const obj = { foo: 'bar' };
|
||||
const str = crypto.sign_object (obj, 'baz');
|
||||
await new Promise ((res) => {
|
||||
setTimeout (res, 10);
|
||||
});
|
||||
|
||||
jasmine.clock ()
|
||||
.tick (36e5);
|
||||
|
||||
const dec = crypto.verify_signature (str, 'baz');
|
||||
expect (obj)
|
||||
.toEqual (dec);
|
||||
});
|
||||
|
||||
it ('should reject tampered signatures', () => {
|
||||
const obj = { foo: 'bar' };
|
||||
const str = crypto.sign_object (obj, 'baz');
|
||||
const dec = crypto.verify_signature (str, 'foo');
|
||||
expect (dec)
|
||||
.toEqual (null);
|
||||
jasmine.clock ()
|
||||
.uninstall ();
|
||||
});
|
||||
|
||||
it ('should reject old signatures', async () => {
|
||||
jasmine.clock ()
|
||||
.install ();
|
||||
const base_time = (new Date);
|
||||
jasmine.clock ()
|
||||
.mockDate (base_time);
|
||||
|
||||
const obj = { foo: 'bar' };
|
||||
const str = crypto.sign_object (obj, 'baz');
|
||||
await new Promise ((res) => {
|
||||
setTimeout (res, 10);
|
||||
});
|
||||
|
||||
jasmine.clock ()
|
||||
.tick (50);
|
||||
|
||||
const dec = crypto.verify_signature (str, 'baz', 1);
|
||||
expect (dec)
|
||||
.toEqual (null);
|
||||
|
||||
jasmine.clock ()
|
||||
.uninstall ();
|
||||
});
|
||||
|
||||
it ('should not reject valid signatures', async () => {
|
||||
jasmine.clock ()
|
||||
.install ();
|
||||
const base_time = (new Date);
|
||||
jasmine.clock ()
|
||||
.mockDate (base_time);
|
||||
|
||||
const obj = { foo: 'bar' };
|
||||
const str = crypto.sign_object (obj, 'baz');
|
||||
await new Promise ((res) => {
|
||||
setTimeout (res, 10);
|
||||
});
|
||||
|
||||
jasmine.clock ()
|
||||
.tick (50);
|
||||
|
||||
const dec = crypto.verify_signature (str, 'baz', 100);
|
||||
expect (obj)
|
||||
.toEqual (dec);
|
||||
|
||||
jasmine.clock ()
|
||||
.uninstall ();
|
||||
});
|
||||
|
||||
it ('verify_signature on almost timed out packet', () => {
|
||||
jasmine.clock ()
|
||||
.install ();
|
||||
const base_time = (new Date);
|
||||
jasmine.clock ()
|
||||
.mockDate (base_time);
|
||||
|
||||
const obj = { foo: 'bar' };
|
||||
const str = crypto.sign_object (obj, 'baz');
|
||||
|
||||
jasmine.clock ()
|
||||
.tick (10);
|
||||
const dec = crypto.verify_signature (str, 'baz', 10);
|
||||
expect (obj)
|
||||
.toEqual (dec);
|
||||
|
||||
jasmine.clock ()
|
||||
.uninstall ();
|
||||
});
|
||||
|
||||
it ('should decode problematic token', () => {
|
||||
|
Reference in New Issue
Block a user