Skip to content

Commit 20b4afe

Browse files
authored
fix(3225): handling when the webhook is incorrect (#37)
1 parent 54cdfae commit 20b4afe

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ class ScmRouter extends Scm {
213213
if (!scm) {
214214
logger.info('Webhook does not match any expected events or actions.');
215215

216-
return null;
216+
const err = new Error(
217+
'Cannot parse this webhook. Please ensure that the signature is correct or that this SCM is supported.'
218+
);
219+
220+
err.statusCode = 400;
221+
222+
return Promise.reject(err);
217223
}
218224

219225
return scm.parseHook(headers, payload);

test/index.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,25 @@ describe('index test', () => {
614614
assert.calledOnce(exampleScm.parseHook);
615615
assert.calledWith(exampleScm.parseHook, headers, payload);
616616
}));
617+
618+
it('rejects error when all scm cannot parse the webhook', () => {
619+
scmGithub.canHandleWebhook.resolves(false);
620+
scmGitlab.canHandleWebhook.resolves(false);
621+
exampleScm.canHandleWebhook.resolves(false);
622+
623+
return scm
624+
._parseHook(headers, payload)
625+
.then(() => {
626+
assert.fail('This should not fail the tests');
627+
})
628+
.catch(err => {
629+
assert.include(err.message, 'Cannot parse this webhook');
630+
assert.strictEqual(err.statusCode, 400);
631+
assert.notCalled(scmGithub.parseHook);
632+
assert.notCalled(scmGitlab.parseHook);
633+
assert.notCalled(exampleScm.parseHook);
634+
});
635+
});
617636
});
618637

619638
describe('_getCheckoutCommand', () => {

0 commit comments

Comments
 (0)