Skip to content

Commit a3c9587

Browse files
authored
chore(point-of-sale, card-service): update webhook handling (#3725)
* chore(card-service): rename `/payment-event` route to `/webhook` * chore(point-of-sale): make webhook signature signing optional * chore(testenv): update CARD_WEBHOOK_SERVICE_URL * test(point-of-sale): allow optional webhook signature
1 parent 5f6e296 commit a3c9587

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

localenv/cloud-nine-wallet/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ services:
117117
KEY_ID: 7097F83B-CB84-469E-96C6-2141C72E22C0
118118
OPERATOR_TENANT_ID: 438fa74a-fa7d-4317-9ced-dde32ece1787
119119
CARD_SERVICE_URL: 'http://cloud-nine-wallet-card-service:3007'
120-
CARD_WEBHOOK_SERVICE_URL: 'http://cloud-nine-wallet-card-service:3007/payment-event'
120+
CARD_WEBHOOK_SERVICE_URL: 'http://cloud-nine-wallet-card-service:3007/webhook'
121121
depends_on:
122122
- shared-database
123123
- shared-redis

packages/card-service/src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ export class App {
6363
)
6464

6565
router.post<DefaultState, PaymentEventContext>(
66-
'/payment-event',
66+
'/webhook',
6767
createValidatorMiddleware<PaymentEventContext>(openApi.cardServerSpec, {
68-
path: '/payment-event',
68+
path: '/webhook',
6969
method: HttpMethod.POST
7070
}),
7171
paymentRoutes.handlePaymentEvent

packages/card-service/src/openapi/specs/card-server.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ paths:
105105
description: 'POS service calls this endpoint to initiate a payment request.'
106106
tags:
107107
- payment
108-
/payment-event:
108+
/webhook:
109109
post:
110110
summary: Handle payment event result from backend
111111
operationId: handlePaymentEvent

packages/point-of-sale/src/webhook-handlers/middleware.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,17 @@ describe('Webhook Signature Middleware', (): void => {
5858
expect(next).toHaveBeenCalled()
5959
})
6060

61-
test('Does not verify invalid signature header', async (): Promise<void> => {
61+
test('Allows empty signature header', async (): Promise<void> => {
6262
const ctx = createWebhookSignatureContext(
6363
webhookBody,
6464
Config,
6565
appContainer.container
6666
)
6767
ctx.headers['rafiki-signature'] = undefined
68-
await expect(webhookHttpSigMiddleware(ctx, next)).rejects.toMatchObject({
69-
status: 401,
70-
message: 'invalid webhook signature header'
71-
})
72-
expect(next).not.toHaveBeenCalled()
68+
69+
await webhookHttpSigMiddleware(ctx, next)
70+
expect(ctx.response.status).toEqual(200)
71+
expect(next).toHaveBeenCalled()
7372
})
7473

7574
test('Does not verify invalid signature digest', async (): Promise<void> => {

packages/point-of-sale/src/webhook-handlers/middleware.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ export async function webhookHttpSigMiddleware(
4242
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4343
next: () => Promise<any>
4444
): Promise<void> {
45-
if (!ctx.request.headers['rafiki-signature'])
46-
ctx.throw(401, 'invalid webhook signature header')
47-
4845
const config = await ctx.container.use('config')
4946

5047
if (
48+
ctx.request.headers['rafiki-signature'] &&
5149
!verifyWebhookSignatureDigest(
5250
ctx.request.headers['rafiki-signature'] as string,
5351
ctx.request,

test/testenv/cloud-nine-wallet/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ services:
4343
OPERATOR_TENANT_ID: 438fa74a-fa7d-4317-9ced-dde32ece1787
4444
ADMIN_API_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964=
4545
ADMIN_API_SIGNATURE_VERSION: 1
46-
CARD_WEBHOOK_SERVICE_URL: http://cloud-nine-wallet-test-card-service:3104/payment-event
46+
CARD_WEBHOOK_SERVICE_URL: http://cloud-nine-wallet-test-card-service:3104/webhook
4747
SIGNATURE_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964= # webhook signature
4848
SIGNATURE_VERSION: 1
4949
volumes:

0 commit comments

Comments
 (0)