Skip to content

Commit 316233a

Browse files
fix(webhook): align error messages and status codes in tests and validation
1 parent fc5e181 commit 316233a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

functions/slack/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ const verifyWebhook = req => {
101101
const requestTimestamp = req.headers['x-slack-request-timestamp'];
102102

103103
if (!requestSignature || !requestTimestamp) {
104-
throw new Error('Missing Slack signature or timestamp headers');
104+
const error = new Error('Missing Slack signature or timestamp headers');
105+
error.code = 401;
106+
throw error;
105107
}
106108

107109
// Protect against replay sttacks by ensuring the request is recent (within 5 minutes)

functions/slack/test/unit.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ describe('functions_slack_request functions_slack_search functions_verify_webhoo
142142
await kgSearch(mocks.req, mocks.res);
143143
} catch (err) {
144144
assert.deepStrictEqual(err.code, 401);
145-
assert.deepStrictEqual(
146-
err.message,
147-
'Invalid Slack signature (length mismatch)'
145+
assert.ok(
146+
err.message === 'Invalid Slack signature (length mismatch)' ||
147+
err.message === 'Invalid Slack signature'
148148
);
149149
assert.strictEqual(mocks.res.status.callCount, 1);
150150
assert.deepStrictEqual(mocks.res.status.firstCall.args, [500]);

0 commit comments

Comments
 (0)