Skip to content

Commit 2628a1a

Browse files
committed
Add 400 error for invalid source field
1 parent 780a143 commit 2628a1a

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/webhooks/generic-notifier/generic-notifier.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import testInvalidPayload from '@test/payloads/generic-notifier/testInvalidPayload.json';
12
import testPayload from '@test/payloads/generic-notifier/testPayload.json';
23
import { createNotifierRequest } from '@test/utils/createGenericMessageRequest';
34

@@ -28,6 +29,14 @@ describe('generic messages webhook', function () {
2829
expect(response.statusCode).toBe(200);
2930
});
3031

32+
it('returns 400 for an invalid source', async function () {
33+
const response = await fastify.inject({
34+
method: 'POST',
35+
url: '/event-notifier/v1',
36+
payload: testInvalidPayload,
37+
});
38+
expect(response.statusCode).toBe(400);
39+
});
3140
it('returns 400 for invalid signature', async function () {
3241
const response = await fastify.inject({
3342
method: 'POST',

src/webhooks/generic-notifier/generic-notifier.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function genericEventNotifier(
2121
body.source === undefined ||
2222
EVENT_NOTIFIER_SECRETS[body.source] === undefined
2323
) {
24+
reply.code(400).send('Invalid source or missing secret');
2425
throw new Error('Invalid source or missing secret');
2526
}
2627

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"source": "bad-source",
3+
"timestamp": 0,
4+
"service_name": "official_service_name",
5+
"data": {
6+
"title": "This is an Example Notification",
7+
"message": "Random text here",
8+
"tags": [
9+
"source:example-service", "sentry-region:all", "sentry-user:bob"
10+
],
11+
"misc": {},
12+
"channels": {
13+
"slack": ["#aaaaaa"],
14+
"datadog": ["example-proj-id"],
15+
"jira": ["TEST"]
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)