Skip to content

Commit bccb1b9

Browse files
authored
fix(middleware-endpoint): fix for resolving file/env endpoint (#1649)
1 parent 437f58f commit bccb1b9

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

.changeset/fifty-news-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/middleware-endpoint": patch
3+
---
4+
5+
fix resolving file/env configured endpoint
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { afterAll, describe, expect, test as it, vi } from "vitest";
2+
3+
import { getEndpointFromInstructions } from "./getEndpointFromInstructions";
4+
5+
describe(getEndpointFromInstructions.name, () => {
6+
afterAll(async () => {
7+
delete process.env.AWS_ENDPOINT_URL;
8+
});
9+
10+
it("should set the isCustomEndpoint flag after resolving an externally configured endpoint", async () => {
11+
process.env.AWS_ENDPOINT_URL = "https://localhost";
12+
13+
const config = {
14+
serviceId: "service id",
15+
isCustomEndpoint: false,
16+
endpointProvider: vi.fn(),
17+
};
18+
19+
await getEndpointFromInstructions(
20+
{},
21+
{
22+
getEndpointParameterInstructions() {
23+
return {};
24+
},
25+
},
26+
config
27+
);
28+
29+
expect(config.isCustomEndpoint).toBe(true);
30+
});
31+
32+
it("should not use externally configured endpoint if code-level endpoint was set", async () => {
33+
process.env.AWS_ENDPOINT_URL = "https://localhost";
34+
35+
const config = {
36+
serviceId: "service id",
37+
isCustomEndpoint: true,
38+
endpointProvider: vi.fn().mockReturnValue(Symbol.for("endpoint")),
39+
};
40+
41+
const endpoint = await getEndpointFromInstructions(
42+
{},
43+
{
44+
getEndpointParameterInstructions() {
45+
return {};
46+
},
47+
},
48+
config
49+
);
50+
51+
expect(config.isCustomEndpoint).toBe(true);
52+
expect(endpoint).toBe(Symbol.for("endpoint"));
53+
});
54+
});

packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const getEndpointFromInstructions = async <
5252

5353
if (endpointFromConfig) {
5454
clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig!));
55+
clientConfig.isCustomEndpoint = true;
5556
}
5657
}
5758

0 commit comments

Comments
 (0)