diff --git a/.changeset/fifty-news-serve.md b/.changeset/fifty-news-serve.md new file mode 100644 index 00000000000..ed495bf936e --- /dev/null +++ b/.changeset/fifty-news-serve.md @@ -0,0 +1,5 @@ +--- +"@smithy/middleware-endpoint": patch +--- + +fix resolving file/env configured endpoint diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.spec.ts b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.spec.ts new file mode 100644 index 00000000000..812e4ebe430 --- /dev/null +++ b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.spec.ts @@ -0,0 +1,54 @@ +import { afterAll, describe, expect, test as it, vi } from "vitest"; + +import { getEndpointFromInstructions } from "./getEndpointFromInstructions"; + +describe(getEndpointFromInstructions.name, () => { + afterAll(async () => { + delete process.env.AWS_ENDPOINT_URL; + }); + + it("should set the isCustomEndpoint flag after resolving an externally configured endpoint", async () => { + process.env.AWS_ENDPOINT_URL = "https://localhost"; + + const config = { + serviceId: "service id", + isCustomEndpoint: false, + endpointProvider: vi.fn(), + }; + + await getEndpointFromInstructions( + {}, + { + getEndpointParameterInstructions() { + return {}; + }, + }, + config + ); + + expect(config.isCustomEndpoint).toBe(true); + }); + + it("should not use externally configured endpoint if code-level endpoint was set", async () => { + process.env.AWS_ENDPOINT_URL = "https://localhost"; + + const config = { + serviceId: "service id", + isCustomEndpoint: true, + endpointProvider: vi.fn().mockReturnValue(Symbol.for("endpoint")), + }; + + const endpoint = await getEndpointFromInstructions( + {}, + { + getEndpointParameterInstructions() { + return {}; + }, + }, + config + ); + + expect(config.isCustomEndpoint).toBe(true); + expect(endpoint).toBe(Symbol.for("endpoint")); + }); +}); diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts index c2ceca75dc3..0889ea27151 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts @@ -52,6 +52,7 @@ export const getEndpointFromInstructions = async < if (endpointFromConfig) { clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig!)); + clientConfig.isCustomEndpoint = true; } }