-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: assure bucket endpoint middleware inserted before host-header-mi…
…ddleware (#574) * fix: use host name from request instead of endpont provider * fix: assure bucketEndpointMw applies before hostHeaderMw
- Loading branch information
1 parent
ae04135
commit c9c4127
Showing
6 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const base = require("../../jest.config.base.js"); | ||
|
||
module.exports = { | ||
...base | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { hostHeaderMiddleware } from "./index"; | ||
import { HttpRequest } from "@aws-sdk/protocol-http"; | ||
describe("hostHeaderMiddleware", () => { | ||
const mockNextHandler = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should set host header if not already set", async () => { | ||
expect.assertions(2); | ||
const middleware = hostHeaderMiddleware({ requestHandler: {} as any }); | ||
const handler = middleware(mockNextHandler, {} as any); | ||
await handler({ | ||
input: {}, | ||
request: new HttpRequest({ hostname: "foo.amazonaws.com" }) | ||
}); | ||
expect(mockNextHandler.mock.calls.length).toEqual(1); | ||
expect(mockNextHandler.mock.calls[0][0].request.headers.host).toBe( | ||
"foo.amazonaws.com" | ||
); | ||
}); | ||
|
||
it("should not set host header if already set", async () => { | ||
expect.assertions(2); | ||
const middleware = hostHeaderMiddleware({ requestHandler: {} as any }); | ||
const handler = middleware(mockNextHandler, {} as any); | ||
await handler({ | ||
input: {}, | ||
request: new HttpRequest({ | ||
hostname: "foo.amazonaws.com", | ||
headers: { host: "random host" } | ||
}) | ||
}); | ||
expect(mockNextHandler.mock.calls.length).toEqual(1); | ||
expect(mockNextHandler.mock.calls[0][0].request.headers.host).toBe( | ||
"random host" | ||
); | ||
}); | ||
|
||
it("should set :authority header for H2 requests", async () => { | ||
expect.assertions(3); | ||
const middleware = hostHeaderMiddleware({ | ||
requestHandler: { metadata: { handlerProtocol: "h2" } } | ||
} as any); | ||
const handler = middleware(mockNextHandler, {} as any); | ||
await handler({ | ||
input: {}, | ||
request: new HttpRequest({ | ||
hostname: "foo.amazonaws.com", | ||
headers: { host: "random host" } | ||
}) | ||
}); | ||
expect(mockNextHandler.mock.calls.length).toEqual(1); | ||
expect( | ||
mockNextHandler.mock.calls[0][0].request.headers.host | ||
).not.toBeDefined(); | ||
expect( | ||
mockNextHandler.mock.calls[0][0].request.headers[":authority"] | ||
).toEqual(""); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters