Skip to content

Commit 15e2e66

Browse files
committed
README updated, test for wrong key verification added
1 parent ebe8316 commit 15e2e66

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ The verification would fail and return `false`, if...
9494
- `obj` doesn't provide a HMAC to check against
9595
- `obj` was manipulated: at least one attribute was changed, added or deleted (deep-inspection including all nested objects/arrays)
9696
- the HMAC of `obj` was manipulated
97+
- `key` is deviating from the one the HMAC was created with
9798

9899
#### obj
99100

@@ -105,7 +106,7 @@ The object of which the HMAC should be verified. The given HMAC to be verified i
105106

106107
Type: `String`
107108

108-
The key to calculate the objects HMAC and validate against the given one. Must be identical to the `key` that was used to create the original HMAC for the object.
109+
The key to calculate the objects HMAC and validate against the given one. Must be identical to the `key` that was used to create the original HMAC for the object for a successful verification.
109110

110111
#### hmacAttribute
111112

test/object-hmac.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ describe('object-hmac test suite', () => {
22

33
const objectHmac = require('../object-hmac');
44
const testKey = 'HmacSecret-0815';
5+
const testKeyBroken = 'HmacSecret-4711';
56
const testHmac = 'bb83e36f2c030af71803fd6a82b49ea638944bb6638351754a967f4f5638ac3b';
67
const testHmacAttribute = '__hmac';
78
const testHmacAttributeDifferent = '_signature';
@@ -74,6 +75,11 @@ describe('object-hmac test suite', () => {
7475
done();
7576
});
7677

78+
it('test a failed HMAC verification - wrong key', async (done) => {
79+
expect(objectHmac.verifyHmac(testObjects.testObjectWithHmac, testKeyBroken)).toBeFalsy();
80+
done();
81+
});
82+
7783
it('test a failed HMAC verification - obj is null', async (done) => {
7884
expect(objectHmac.verifyHmac(null, testKey)).toBeFalsy();
7985
done();

0 commit comments

Comments
 (0)