|
| 1 | +import { HttpRequest } from "@aws-sdk/protocol-http"; |
| 2 | +import { SignatureV4 } from "./signer"; |
| 3 | +describe("transcribe streaming", () => { |
| 4 | + describe("WebSocket request signer", () => { |
| 5 | + const toSign = new HttpRequest({ |
| 6 | + headers: { |
| 7 | + "x-amz-foo": "foo", |
| 8 | + bar: "bar", |
| 9 | + "amz-sdk-invocation-id": "123", |
| 10 | + "amz-sdk-request": "attempt=1", |
| 11 | + host: "aws.amazon.com" |
| 12 | + }, |
| 13 | + body: "hello world", |
| 14 | + query: { |
| 15 | + prop1: "A", |
| 16 | + prop2: "B" |
| 17 | + } |
| 18 | + }); |
| 19 | + beforeEach(() => { |
| 20 | + jest.mock("@aws-sdk/protocol-http"); |
| 21 | + ((HttpRequest as any) as jest.Mock).mockReturnValue({ |
| 22 | + isInstance: () => true |
| 23 | + }); |
| 24 | + }); |
| 25 | + it("should invoke base SigV4 signer correctly", async () => { |
| 26 | + expect.assertions(5); |
| 27 | + const mockBaseSigner = { |
| 28 | + presign: jest |
| 29 | + .fn() |
| 30 | + .mockImplementation(request => Promise.resolve(request)) |
| 31 | + }; |
| 32 | + const signer = new SignatureV4({ signer: mockBaseSigner as any }); |
| 33 | + const signed = await signer.sign(toSign); |
| 34 | + expect(toSign).toMatchObject(signed); |
| 35 | + expect(mockBaseSigner.presign).toBeCalled(); |
| 36 | + // The request's body should not be presigned |
| 37 | + expect(mockBaseSigner.presign.mock.calls[0][0].body).toEqual(""); |
| 38 | + expect( |
| 39 | + mockBaseSigner.presign.mock.calls[0][1]!.unsignableHeaders |
| 40 | + ).toBeDefined(); |
| 41 | + const unsignableHeaders: Set<string> = mockBaseSigner.presign.mock |
| 42 | + .calls[0][1]!.unsignableHeaders; |
| 43 | + expect([...unsignableHeaders.entries()].map(([value]) => value)).toEqual( |
| 44 | + Object.keys(toSign.headers).filter(a => a !== "host") |
| 45 | + ); |
| 46 | + }); |
| 47 | + }); |
| 48 | +}); |
0 commit comments