object signature improvements
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -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');
|
||||
|
Reference in New Issue
Block a user