From 3663a9b8221bb4bcc1362b30dd27b5b6a478b6ad Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Wed, 26 Jul 2023 09:24:22 -0700 Subject: [PATCH] fix(middleware-websocket): pass options to presign in WebsocketSignatureV4 sign (#5015) --- .../src/WebsocketSignatureV4.spec.ts | 10 +++++----- .../middleware-websocket/src/WebsocketSignatureV4.ts | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/middleware-websocket/src/WebsocketSignatureV4.spec.ts b/packages/middleware-websocket/src/WebsocketSignatureV4.spec.ts index 4b464e9711f6..d8e4b79729e6 100644 --- a/packages/middleware-websocket/src/WebsocketSignatureV4.spec.ts +++ b/packages/middleware-websocket/src/WebsocketSignatureV4.spec.ts @@ -58,7 +58,7 @@ describe("WebsocketSignatureV4", () => { (isInstance as unknown as jest.Mock).mockReturnValueOnce(true); }); - const expectSignArgs = (result: any) => { + const expectSignArgs = (result: any, options: RequestPresigningArguments = {}) => { expect(result).toStrictEqual({ ...mockPresignedRequest, body: request.body, @@ -69,6 +69,7 @@ describe("WebsocketSignatureV4", () => { expect(presign).toHaveBeenCalledWith( { ...request, body: "" }, { + ...options, expiresIn: 60, unsignableHeaders: new Set(Object.keys(request.headers).filter((header) => header !== "host")), } @@ -82,11 +83,10 @@ describe("WebsocketSignatureV4", () => { }); it("with options", async () => { - const options = { - unsignableHeaders: new Set(Object.keys(headers)), - }; + const signingDate = new Date(); + const options = { signingDate }; const result = await sigV4.sign(request as any, options); - expectSignArgs(result); + expectSignArgs(result, options); }); }); diff --git a/packages/middleware-websocket/src/WebsocketSignatureV4.ts b/packages/middleware-websocket/src/WebsocketSignatureV4.ts index 7f737f4dd1bb..d303270d8e23 100644 --- a/packages/middleware-websocket/src/WebsocketSignatureV4.ts +++ b/packages/middleware-websocket/src/WebsocketSignatureV4.ts @@ -27,6 +27,7 @@ export class WebsocketSignatureV4 implements RequestSigner, RequestPresigner { const signedRequest = await this.signer.presign( { ...toSign, body: "" }, { + ...options, // presigned url must be expired within 1 min. expiresIn: 60, // Not to sign headers. Transcribe-streaming WebSocket