Skip to content

Commit

Permalink
test: unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Dec 12, 2024
1 parent c2a9541 commit c8ab6fa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
20 changes: 10 additions & 10 deletions packages/credential-provider-ini/src/fromIni.integ.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -190,29 +190,29 @@ 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({});
const credentials = await sts.config.credentials();
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",
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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(),
Expand Down Expand Up @@ -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({
Expand All @@ -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 () => {}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -97,7 +97,7 @@ describe(createCredentialChain.name, () => {

expect(
await chain({
contextClientConfig: {
callerClientConfig: {
async region() {
return "ap-northeast-1";
},
Expand Down

0 comments on commit c8ab6fa

Please sign in to comment.