-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change typing of verifyWebhook and patch security issue (#1090)
Co-authored-by: Federico Guerinoni <[email protected]>
- Loading branch information
1 parent
9d40ba2
commit 716db00
Showing
3 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect } from 'chai'; | ||
import { CheckSignature } from '../../src'; | ||
|
||
const MOCK_SECRET = 'porewqKAFDSAKZssecretsercretfads'; | ||
const MOCK_TEXT = 'text'; | ||
const MOCK_JSON_BODY = { a: 1 }; | ||
const MOCK_TEXT_SHA256 = 'd0b770e93a56adc3ee9ac5734533cc0acd71eea8e5e8204a28042ca0f60de1f3'; | ||
const MOCK_JSON_SHA256 = 'e527a6ad4993a4c9a30680c8be4b3eda1c36ab104f1f7d39c744bd27016a9624'; | ||
|
||
describe('Signing', () => { | ||
describe('CheckSignature', () => { | ||
it('validates correct text body and signature', () => { | ||
const rawBody = Buffer.from(MOCK_TEXT); | ||
expect(CheckSignature(rawBody, MOCK_SECRET, MOCK_TEXT_SHA256)).to.be.true; | ||
}); | ||
|
||
it('validates correct json body and signature', () => { | ||
const rawBody = Buffer.from(JSON.stringify(MOCK_JSON_BODY)); | ||
expect(CheckSignature(rawBody, MOCK_SECRET, MOCK_JSON_SHA256)).to.be.true; | ||
}); | ||
|
||
it('refutes incorrect json body', () => { | ||
const rawBody = Buffer.from(JSON.stringify({ ...MOCK_JSON_BODY, b: 2 })); | ||
expect(CheckSignature(rawBody, MOCK_SECRET, MOCK_JSON_SHA256)).to.be.false; | ||
}); | ||
}); | ||
}); |