diff --git a/packages/credential-provider-ini/src/fromIni.integ.spec.ts b/packages/credential-provider-ini/src/fromIni.integ.spec.ts index 0cb0e93c00bd..db15da42fa6c 100644 --- a/packages/credential-provider-ini/src/fromIni.integ.spec.ts +++ b/packages/credential-provider-ini/src/fromIni.integ.spec.ts @@ -174,7 +174,7 @@ describe("fromIni region search order", () => { }); }); - it("should use 2nd priority for the context client", async () => { + it("should use 2nd priority for the profile region", async () => { const sts = new STS({ requestHandler: new MockNodeHttpHandler(), region: "ap-northeast-2", @@ -190,21 +190,21 @@ describe("fromIni region search order", () => { expect(credentials).toContain({ accessKeyId: "STS_AR_ACCESS_KEY_ID", secretAccessKey: "STS_AR_SECRET_ACCESS_KEY", - sessionToken: "STS_AR_SESSION_TOKEN_ap-northeast-2", + sessionToken: "STS_AR_SESSION_TOKEN_us-stsar-1", }); }); - it("should use 3rd priority for the profile region if not used in the context of a client with a region", async () => { - const credentialsData = await fromIni({ - clientConfig: { - requestHandler: new MockNodeHttpHandler(), - }, - })(); + it("should use 3rd priority for the caller client", async () => { + delete iniProfileData.default.region; const sts = new STS({ requestHandler: new MockNodeHttpHandler(), region: "ap-northeast-2", - credentials: credentialsData, + credentials: fromIni({ + clientConfig: { + requestHandler: new MockNodeHttpHandler(), + }, + }), }); await sts.getCallerIdentity({}); @@ -212,7 +212,7 @@ describe("fromIni region search order", () => { expect(credentials).toContain({ accessKeyId: "STS_AR_ACCESS_KEY_ID", secretAccessKey: "STS_AR_SECRET_ACCESS_KEY", - sessionToken: "STS_AR_SESSION_TOKEN_us-stsar-1", + sessionToken: "STS_AR_SESSION_TOKEN_ap-northeast-2", }); }); diff --git a/packages/credential-provider-ini/src/resolveAssumeRoleCredentials.ts b/packages/credential-provider-ini/src/resolveAssumeRoleCredentials.ts index 1e9b7942555a..29d5648cee04 100644 --- a/packages/credential-provider-ini/src/resolveAssumeRoleCredentials.ts +++ b/packages/credential-provider-ini/src/resolveAssumeRoleCredentials.ts @@ -119,10 +119,7 @@ export const resolveAssumeRoleCredentials = async ( credentialProviderLogger: options.logger, parentClientConfig: { ...options?.parentClientConfig, - // The profile region is the last fallback, and only applies - // if the clientConfig.region is not defined by the user - // and no contextual outer client configuration region can be found. - region: options?.parentClientConfig?.region ?? region, + region: region ?? options?.parentClientConfig?.region, }, }, options.clientPlugins diff --git a/packages/credential-provider-node/src/credential-provider-node.integ.spec.ts b/packages/credential-provider-node/src/credential-provider-node.integ.spec.ts index b57651770bb9..b2ac2def6744 100644 --- a/packages/credential-provider-node/src/credential-provider-node.integ.spec.ts +++ b/packages/credential-provider-node/src/credential-provider-node.integ.spec.ts @@ -398,7 +398,7 @@ describe("credential-provider-node integration test", () => { expect(credentials).toEqual({ accessKeyId: "STS_AR_ACCESS_KEY_ID", secretAccessKey: "STS_AR_SECRET_ACCESS_KEY", - sessionToken: "STS_AR_SESSION_TOKEN_us-west-2", + sessionToken: "STS_AR_SESSION_TOKEN_us-stsar-1", expiration: new Date("3000-01-01T00:00:00.000Z"), $source: { CREDENTIALS_PROFILE_SOURCE_PROFILE: "o", @@ -805,7 +805,7 @@ describe("credential-provider-node integration test", () => { }); describe("Region resolution for code-level providers given to a client", () => { - it("fromCognitoIdentity provider should use context client region", async () => { + it("fromCognitoIdentity provider should use caller client region", async () => { sts = new STS({ region: "ap-northeast-1", credentials: fromCognitoIdentity({ @@ -824,7 +824,7 @@ describe("credential-provider-node integration test", () => { }); }); - it("fromCognitoIdentityPool provider should use context client region", async () => { + it("fromCognitoIdentityPool provider should use caller client region", async () => { sts = new STS({ region: "ap-northeast-1", credentials: fromCognitoIdentityPool({ @@ -843,7 +843,7 @@ describe("credential-provider-node integration test", () => { }); }); - it("fromIni assumeRole provider should use the context client's region for STS", async () => { + it("fromIni assumeRole provider should use the caller client's region for STS", async () => { sts = new STS({ region: "eu-west-1", credentials: fromIni(), @@ -875,7 +875,7 @@ describe("credential-provider-node integration test", () => { }); }); - it("fromWebToken provider should use context client region", async () => { + it("fromWebToken provider should use caller client region", async () => { sts = new STS({ region: "ap-northeast-1", credentials: fromWebToken({ @@ -899,7 +899,7 @@ describe("credential-provider-node integration test", () => { it.skip( "fromSSO (SSO) provider is excluded from testing because the SSO_REGION is a required parameter and is used " + - "instead of any fallback to the context client region", + "instead of any fallback to the caller client region", async () => {} ); diff --git a/packages/credential-providers/src/createCredentialChain.spec.ts b/packages/credential-providers/src/createCredentialChain.spec.ts index 04f5fbb67962..0cbee3d05553 100644 --- a/packages/credential-providers/src/createCredentialChain.spec.ts +++ b/packages/credential-providers/src/createCredentialChain.spec.ts @@ -82,11 +82,11 @@ describe(createCredentialChain.name, () => { }); it("is compatible with contextual-region-aware credential providers", async () => { - const provider: RegionalAwsCredentialIdentityProvider = async ({ contextClientConfig } = {}) => { + const provider: RegionalAwsCredentialIdentityProvider = async ({ callerClientConfig } = {}) => { return { accessKeyId: "", secretAccessKey: "", - sessionToken: (await contextClientConfig?.region()) ?? "wrong_region", + sessionToken: (await callerClientConfig?.region()) ?? "wrong_region", }; }; const errorProvider = async () => { @@ -97,7 +97,7 @@ describe(createCredentialChain.name, () => { expect( await chain({ - contextClientConfig: { + callerClientConfig: { async region() { return "ap-northeast-1"; },