-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathverifyZoomSignature.js
More file actions
38 lines (34 loc) · 1.18 KB
/
Copy pathverifyZoomSignature.js
File metadata and controls
38 lines (34 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import assert from 'node:assert/strict';
import { verifyZoomWebhookRequest } from '../shared/zoomSignature.js';
import { buildDummyRtmsWebhook, signZoomWebhook } from './dummyRtms.js';
const secret = 'test-secret';
const bodyText = JSON.stringify(buildDummyRtmsWebhook({
event: 'meeting.rtms_started',
region: 'IAD',
streamId: 'test-stream',
rtmsId: 'test-meeting'
}));
const signed = signZoomWebhook(bodyText, secret);
assert.equal(verifyZoomWebhookRequest(mockRequest(bodyText, signed), secret).ok, true);
assert.equal(
verifyZoomWebhookRequest(mockRequest(bodyText, signed), 'wrong-secret').reason,
'invalid_x_zm_signature'
);
assert.equal(
verifyZoomWebhookRequest(mockRequest(bodyText, signZoomWebhook(bodyText, secret, 1)), secret).reason,
'stale_x_zm_request_timestamp'
);
assert.equal(
verifyZoomWebhookRequest(mockRequest(bodyText, {}), secret).reason,
'missing_x_zm_signature'
);
console.log('Zoom webhook signature verification tests passed');
function mockRequest(rawBody, signedHeaders) {
return {
rawBody: Buffer.from(rawBody),
headers: {
'x-zm-request-timestamp': signedHeaders.timestamp,
'x-zm-signature': signedHeaders.signature
}
};
}