From 78cd73fdd2c612298c855c190597e67255d14373 Mon Sep 17 00:00:00 2001 From: Sabine Schaller Date: Thu, 7 Mar 2024 10:58:03 +0100 Subject: [PATCH] fix: handle headers undefined use case --- packages/auth/src/signature/middleware.ts | 2 +- packages/auth/src/tests/context.ts | 2 +- packages/backend/src/open_payments/auth/middleware.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/auth/src/signature/middleware.ts b/packages/auth/src/signature/middleware.ts index b29f91ad9e..cfc797e148 100644 --- a/packages/auth/src/signature/middleware.ts +++ b/packages/auth/src/signature/middleware.ts @@ -19,7 +19,7 @@ function contextToRequestLike(ctx: AppContext): RequestLike { return { url, method: ctx.method, - headers: JSON.parse(JSON.stringify(ctx.headers)), + headers: ctx.headers ? JSON.parse(JSON.stringify(ctx.headers)) : undefined, body: ctx.request.body ? JSON.stringify(ctx.request.body) : undefined } } diff --git a/packages/auth/src/tests/context.ts b/packages/auth/src/tests/context.ts index 78eb9ad784..e9ab37a4c0 100644 --- a/packages/auth/src/tests/context.ts +++ b/packages/auth/src/tests/context.ts @@ -52,7 +52,7 @@ export async function createContextWithSigHeaders( const request = { url, method, - headers: JSON.parse(JSON.stringify(headers)), + headers: headers ? JSON.parse(JSON.stringify(headers)) : undefined, body: JSON.stringify(requestBody) } const sigHeaders = await createHeaders({ diff --git a/packages/backend/src/open_payments/auth/middleware.ts b/packages/backend/src/open_payments/auth/middleware.ts index 45a3665261..74266e13c0 100644 --- a/packages/backend/src/open_payments/auth/middleware.ts +++ b/packages/backend/src/open_payments/auth/middleware.ts @@ -42,7 +42,7 @@ function contextToRequestLike(ctx: HttpSigContext): RequestLike { return { url, method: ctx.method, - headers: JSON.parse(JSON.stringify(ctx.headers)), + headers: ctx.headers ? JSON.parse(JSON.stringify(ctx.headers)) : undefined, body: ctx.request.body ? JSON.stringify(ctx.request.body) : undefined } }