import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import crypto from 'crypto'; import { verifyWebhookSignature } from '../services/webexInbound.js'; describe('verifyWebhookSignature', () => { it('accepts valid signatures', () => { const secret = 'super-secret-webhook-key'; const rawBody = Buffer.from(JSON.stringify({ hello: 'world' })); const signature = crypto.createHmac('sha1', secret).update(rawBody).digest('hex'); assert.equal(verifyWebhookSignature(rawBody, signature, secret), true); }); it('rejects invalid signatures', () => { const rawBody = Buffer.from(JSON.stringify({ hello: 'world' })); assert.equal(verifyWebhookSignature(rawBody, 'bad-signature', 'secret'), false); }); it('rejects when secret is missing', () => { const rawBody = Buffer.from('{}'); assert.equal(verifyWebhookSignature(rawBody, 'abc', ''), false); }); });