Skip to content

Commit 02cfdd5

Browse files
fix(slack): continue shared legacy webhook fanout
1 parent 300a190 commit 02cfdd5

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

apps/sim/app/api/webhooks/trigger/[path]/route.test.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,88 @@ describe('Webhook Trigger API Route', () => {
10491049
expect(dispatchResolvedWebhookTargetMock).not.toHaveBeenCalled()
10501050
})
10511051

1052+
it('continues past a missing credential to another valid legacy credential', async () => {
1053+
testData.webhooks.push(
1054+
{
1055+
id: 'missing-legacy-slack-webhook',
1056+
provider: 'slack',
1057+
path: 'shared-legacy-slack-path',
1058+
routingKey: 'missing-credential',
1059+
isActive: true,
1060+
providerConfig: {
1061+
triggerId: 'slack_webhook',
1062+
credentialId: 'missing-credential',
1063+
ingressMode: 'legacy_custom_bot',
1064+
},
1065+
workflowId: 'test-workflow-id',
1066+
},
1067+
{
1068+
id: 'valid-legacy-slack-webhook',
1069+
provider: 'slack',
1070+
path: 'shared-legacy-slack-path',
1071+
routingKey: 'valid-credential',
1072+
isActive: true,
1073+
providerConfig: {
1074+
triggerId: 'slack_webhook',
1075+
credentialId: 'valid-credential',
1076+
ingressMode: 'legacy_custom_bot',
1077+
},
1078+
workflowId: 'test-workflow-id',
1079+
}
1080+
)
1081+
verifySlackCustomBotCredentialRequestMock.mockImplementation(
1082+
async ({ credentialId }: { credentialId: string }) =>
1083+
credentialId === 'missing-credential' ? new NextResponse(null, { status: 404 }) : null
1084+
)
1085+
1086+
const response = await POST(createMockRequest('POST', { type: 'event_callback' }), {
1087+
params: Promise.resolve({ path: 'shared-legacy-slack-path' }),
1088+
})
1089+
1090+
expect(response.status).toBe(200)
1091+
expect(dispatchSlackCustomBotCredentialMock).toHaveBeenCalledOnce()
1092+
expect(dispatchSlackCustomBotCredentialMock).toHaveBeenCalledWith(
1093+
expect.objectContaining({ credentialId: 'valid-credential' })
1094+
)
1095+
})
1096+
1097+
it('continues to a direct webhook when every legacy credential is unavailable', async () => {
1098+
testData.webhooks.push(
1099+
{
1100+
id: 'missing-legacy-slack-webhook',
1101+
provider: 'slack',
1102+
path: 'shared-direct-path',
1103+
routingKey: 'missing-credential',
1104+
isActive: true,
1105+
providerConfig: {
1106+
triggerId: 'slack_webhook',
1107+
credentialId: 'missing-credential',
1108+
ingressMode: 'legacy_custom_bot',
1109+
},
1110+
workflowId: 'test-workflow-id',
1111+
},
1112+
{
1113+
id: 'direct-webhook',
1114+
provider: 'generic',
1115+
path: 'shared-direct-path',
1116+
isActive: true,
1117+
providerConfig: { requireAuth: false },
1118+
workflowId: 'test-workflow-id',
1119+
}
1120+
)
1121+
verifySlackCustomBotCredentialRequestMock.mockResolvedValueOnce(
1122+
new NextResponse(null, { status: 404 })
1123+
)
1124+
1125+
const response = await POST(createMockRequest('POST', { type: 'event_callback' }), {
1126+
params: Promise.resolve({ path: 'shared-direct-path' }),
1127+
})
1128+
1129+
expect(response.status).toBe(200)
1130+
expect(dispatchSlackCustomBotCredentialMock).not.toHaveBeenCalled()
1131+
expect(dispatchResolvedWebhookTargetMock).toHaveBeenCalledOnce()
1132+
})
1133+
10521134
it('propagates a legacy fan-out failure when no target queues successfully', async () => {
10531135
testData.webhooks.push({
10541136
id: 'legacy-slack-webhook',

apps/sim/app/api/webhooks/trigger/[path]/route.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ async function handleWebhookDelivery(
228228
requestId,
229229
})
230230
if (authError) {
231-
if (authError.status === 404) return authError
232231
firstLegacySlackAuthError ??= authError
233232
continue
234233
}
@@ -244,7 +243,11 @@ async function handleWebhookDelivery(
244243
legacySlackDispatchResults.push(...dispatchResults)
245244
}
246245

247-
if (legacySlackCredentialIds.size > 0 && !authenticatedLegacySlackAlias) {
246+
if (
247+
legacySlackCredentialIds.size > 0 &&
248+
!authenticatedLegacySlackAlias &&
249+
directWebhooksForPath.length === 0
250+
) {
248251
return (
249252
firstLegacySlackAuthError ??
250253
new NextResponse('Unauthorized - Invalid Slack signature', { status: 401 })

0 commit comments

Comments
 (0)