Skip to content

Commit 9a2c1a4

Browse files
committed
refactor(webhook): improve redirect handling in webhook deliverer and update test mocks
1 parent ef40375 commit 9a2c1a4

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

workers/email/tests/provider.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ nodemailerMock.createTransport = jest.fn(() => ({
1010

1111
jest.mock('nodemailer', () => nodemailerMock);
1212

13-
import { DecodedGroupedEvent, ProjectDBScheme } from '@hawk.so/types';
13+
import { DecodedGroupedEvent, ProjectDBScheme, UserDBScheme } from '@hawk.so/types';
1414
import '../src/env';
1515
import EmailProvider from '../src/provider';
1616
import Templates from '../src/templates/names';
@@ -187,6 +187,11 @@ describe('EmailProvider', () => {
187187
password: '$argon2i$v=19$m=4096,t=3,p=1$QOo3u8uEor0t+nqCLpEW3g$aTCDEaHht9ro9VZDD1yZGpaTi+g1OWsfHbYd5TQBRPs',
188188
name: 'Hahahawk',
189189
},
190+
assignee: {
191+
_id: new ObjectId('5ec3ffe769c0030022f88f25'),
192+
email: 'assignee@email.ru',
193+
name: 'Assignee User',
194+
} as UserDBScheme,
190195
project: {
191196
_id: new ObjectId('5d206f7f9aaf7c0071d64596'),
192197
token: 'project-token',

workers/webhook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"license": "MIT",
77
"workerType": "sender/webhook",
88
"scripts": {
9-
"test": "echo \"Error: no test specified\" && exit 1"
9+
"test": "jest"
1010
}
1111
}

workers/webhook/src/deliverer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ export default class WebhookDeliverer {
8484

8585
const status = res.statusCode || 0;
8686

87-
if (status >= HttpStatusCode.MultipleChoices && status <= HttpStatusCode.PermanentRedirect) {
87+
const isRedirect = (
88+
status === HttpStatusCode.MovedPermanently ||
89+
status === HttpStatusCode.Found ||
90+
status === HttpStatusCode.SeeOther ||
91+
status === HttpStatusCode.TemporaryRedirect ||
92+
status === HttpStatusCode.PermanentRedirect
93+
) && res.headers.location;
94+
95+
if (isRedirect) {
8896
this.logger.log('error', `Webhook blocked — redirect ${status} to ${res.headers.location} from ${endpoint}`);
8997
resolve();
9098

workers/webhook/tests/provider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const deliver = jest.fn();
1818
/**
1919
* Webhook Deliverer mock
2020
*/
21-
jest.mock('./../src/deliverer.ts', () => {
21+
jest.mock('../src/deliverer', () => {
2222
return jest.fn().mockImplementation(() => {
2323
return {
2424
deliver: deliver,

0 commit comments

Comments
 (0)