object signature improvements
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-12-13 13:09:34 +01:00
parent b12ffc17b8
commit 4d6e028fca
6 changed files with 93 additions and 11 deletions

View File

@ -110,6 +110,36 @@ describe ('crypto helper', () => {
}).not.toThrow ();
});
it ('should sign object with key info', () => {
const obj = { foo: 'bar' };
expect (() => {
const str = crypto.sign_object (obj, 'baz', 'baz');
const res = crypto.get_signature_info (str);
expect (res.key_info)
.toEqual ('baz');
}).not.toThrow ();
});
it ('should sign object with custom properties', () => {
const obj = { foo: 'bar' };
expect (() => {
const str = crypto.sign_object (obj, 'baz', { bar: 'baz' });
const res = crypto.get_signature_info (str);
expect (res.bar)
.toEqual ('baz');
}).not.toThrow ();
});
it ('should sign object with custom override properties', () => {
const obj = { foo: 'bar' };
expect (() => {
const str = crypto.sign_object (obj, 'baz', { iat: 'baz' });
const res = crypto.get_signature_info (str);
expect (res.iat)
.toEqual ('baz');
}).not.toThrow ();
});
it ('decode_signed', () => {
const obj = { foo: 'bar' };
const str = crypto.sign_object (obj, 'baz');
@ -126,6 +156,24 @@ describe ('crypto helper', () => {
.toEqual (dec);
});
it ('should verify and return all info', () => {
const obj = { foo: 'bar' };
const str = crypto.sign_object (obj, 'baz', { iat: 'baz' });
const dec = crypto.verify_signature_get_info (str, 'baz');
expect (dec.obj)
.toEqual (obj);
expect (dec.iat)
.toEqual ('baz');
});
it ('should verify signature using function retrieved key', () => {
const obj = { foo: 'bar' };
const str = crypto.sign_object (obj, 'baz');
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');