From 55866516f92a4e36a50fc586b08ee7a9fe799e7e Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 26 Jul 2023 15:23:16 +0000 Subject: [PATCH 1/2] fix(middleware-websocket): pass signing options in WebsocketSignatureV4 sign --- packages/middleware-websocket/src/WebsocketSignatureV4.ts | 1 + 1 file changed, 1 insertion(+) 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 From ce3fadbd98c395ecb22b1e7b8320e1db01a43d47 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:09:17 +0000 Subject: [PATCH 2/2] test(middleware-websocket): case for options being passed in presign --- .../src/WebsocketSignatureV4.spec.ts | 10 +++++----- 1 file changed, 5 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); }); });