Skip to content

Commit

Permalink
test(credential-provider-node): fix tests related to defaultProvider …
Browse files Browse the repository at this point in the history
…chain (#6285)
  • Loading branch information
kuhe authored Jul 16, 2024
1 parent d1105e3 commit 9ca8bae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions packages/credential-provider-node/src/defaultProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ describe(defaultProvider.name, () => {
const mockTokenFileFn = jest.fn().mockImplementation(() => credentials());
const mockRemoteProviderFn = jest.fn().mockImplementation(() => finalCredentials());

const ORIGINAL_ENV = {
...process.env,
};

beforeEach(() => {
process.env = {
...ORIGINAL_ENV,
};
delete process.env.AWS_PROFILE;
delete process.env.AWS_ACCESS_KEY_ID;
delete process.env.AWS_SECRET_ACCESS_KEY;
[
[fromEnv, mockEnvFn],
[fromSSO, mockSsoFn],
Expand All @@ -64,6 +74,7 @@ describe(defaultProvider.name, () => {

afterEach(async () => {
jest.clearAllMocks();
process.env = ORIGINAL_ENV;
});

describe("without fromEnv", () => {
Expand Down Expand Up @@ -102,9 +113,7 @@ describe(defaultProvider.name, () => {
});

it(`if env['${ENV_PROFILE}'] is set`, async () => {
const ORIGINAL_ENV = process.env;
process.env = {
...ORIGINAL_ENV,
[ENV_PROFILE]: "envProfile",
};

Expand All @@ -117,8 +126,6 @@ describe(defaultProvider.name, () => {
expect(fromFn).toHaveBeenCalledWith(mockInitWithoutProfile);
}
expect(fromSSO).not.toHaveBeenCalled();

process.env = ORIGINAL_ENV;
});
});

Expand Down
8 changes: 4 additions & 4 deletions packages/credential-provider-node/src/defaultProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ export const defaultProvider = (init: DefaultProviderInit = {}): MemoizedProvide
);
multipleCredentialSourceWarningEmitted = true;
}
throw new CredentialsProviderError("AWS_PROFILE is set, skipping fromEnv provider.", {
logger: init.logger,
tryNextLink: true,
});
}
throw new CredentialsProviderError("AWS_PROFILE is set, skipping fromEnv provider.", {
logger: init.logger,
tryNextLink: true,
});
}
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromEnv");
return fromEnv(init)();
Expand Down

0 comments on commit 9ca8bae

Please sign in to comment.