|
1 | 1 | const { createSignatureVerifier } = require('../dist/index.js'); |
2 | 2 | var crypto = require('crypto'); |
3 | 3 |
|
4 | | -test('Test Signature HMAC', () => { |
5 | | - const guard = createSignatureVerifier({ |
6 | | - secret: 'xXx', |
7 | | - sha256: (data) => crypto.createHash('sha256').update(data).digest('hex'), |
8 | | - jwtVerify: (token, secret) => ({ |
9 | | - hmac: '1101b34dac8c55e5590a37271f1c41c3d745463854613494a1624a15be24f1f8', |
10 | | - }), |
| 4 | +describe('Test Signature HMAC', () => { |
| 5 | + test('Test With a Body', () => { |
| 6 | + const guard = createSignatureVerifier({ |
| 7 | + secret: 'xXx', |
| 8 | + sha256: (data) => crypto.createHash('sha256').update(data).digest('hex'), |
| 9 | + jwtVerify: (token, secret) => ({ |
| 10 | + hmac: '1101b34dac8c55e5590a37271f1c41c3d745463854613494a1624a15be24f1f8', |
| 11 | + }), |
| 12 | + }); |
| 13 | + |
| 14 | + expect( |
| 15 | + guard('xXx.xXx.xXx', { |
| 16 | + url: 'https://a17e-2601-645-4500-330-b07d-351d-ece7-41c1.ngrok.io/test/signature', |
| 17 | + method: 'POST', |
| 18 | + body: '{"item":{"get":{"id":"63f2d3b2a94533f79fc6397b","createdAt":"2023-02-20T01:58:10.000Z","updatedAt":"2023-02-23T07:58:34.685Z","name":"test"}}}', |
| 19 | + }), |
| 20 | + ); |
11 | 21 | }); |
12 | 22 |
|
13 | | - expect( |
14 | | - guard('xXx.xXx.xXx', { |
15 | | - url: 'https://a17e-2601-645-4500-330-b07d-351d-ece7-41c1.ngrok.io/test/signature', |
16 | | - method: 'POST', |
17 | | - body: '{"item":{"get":{"id":"63f2d3b2a94533f79fc6397b","createdAt":"2023-02-20T01:58:10.000Z","updatedAt":"2023-02-23T07:58:34.685Z","name":"test"}}}', |
18 | | - }), |
19 | | - ); |
| 23 | + test('Test Without a Body App', () => { |
| 24 | + const guard = createSignatureVerifier({ |
| 25 | + secret: 'xXx', |
| 26 | + sha256: (data) => crypto.createHash('sha256').update(data).digest('hex'), |
| 27 | + jwtVerify: (token, secret) => ({ |
| 28 | + hmac: '157bee342a4856e14e964356fef54fd84b3a3508c1071ed674172d3f9b68892f', |
| 29 | + }), |
| 30 | + }); |
| 31 | + |
| 32 | + expect( |
| 33 | + guard('xXx.xXx.xXx', { |
| 34 | + url: 'https://helloworld.crystallize.app.local', |
| 35 | + method: 'GET', |
| 36 | + body: null, |
| 37 | + }), |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + test('Test Without a Body Webhook', () => { |
| 42 | + const guard = createSignatureVerifier({ |
| 43 | + secret: 'xXx', |
| 44 | + sha256: (data) => crypto.createHash('sha256').update(data).digest('hex'), |
| 45 | + jwtVerify: (token, secret) => ({ |
| 46 | + hmac: '61ce7a2e5072900a13369ac7f69b9e056e91c38c42f1bfe94389c80411d94b78', |
| 47 | + }), |
| 48 | + }); |
| 49 | + expect( |
| 50 | + guard('xXx.xXx.xXx', { |
| 51 | + url: 'https://webhook.site/b56870a7-9600-41a6-86a0-98be0c7532fd?id=65d8fc4ce2ba75beec481ec1&userId=61f9933ec63b0a44d5004c2d&tenantId=61f9937c3b63c8386ea9e153&type=document&language=en', |
| 52 | + webhookUrl: 'https://webhook.site/b56870a7-9600-41a6-86a0-98be0c7532fd', |
| 53 | + method: 'GET', |
| 54 | + }), |
| 55 | + ); |
| 56 | + }); |
20 | 57 | }); |
0 commit comments