Skip to content

Commit

Permalink
chore(cli): new test for MFA + AWS_Profile (#32566)
Browse files Browse the repository at this point in the history
Adding a missing test, for the scenario that caused #32312.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
otaviomacedo authored Dec 18, 2024
1 parent e9b5026 commit c1d3130
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/aws-cdk/test/api/sdk-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,19 @@ describe('with intercepted network calls', () => {
expect((await provider.defaultAccount())?.accountId).toEqual(uniq('22222'));
});

test('mfa_serial in profile will ask user for token', async () => {
const providersForMfa = [
(() => providerFromProfile('mfa-role')),
(async () => {
// The profile is not passed explicitly. Should be picked from the environment variable
process.env.AWS_PROFILE = 'mfa-role';
// Awaiting to make sure the environment variable is only deleted after it's used
const provider = await SdkProvider.withAwsCliCompatibleDefaults({ logger: console });
delete process.env.AWS_PROFILE;
return Promise.resolve(provider);
}),
];

test.each(providersForMfa)('mfa_serial in profile will ask user for token', async (metaProvider: () => Promise<SdkProvider>) => {
// GIVEN
const mockPrompt = jest.spyOn(promptly, 'prompt').mockResolvedValue('1234');

Expand All @@ -320,7 +332,8 @@ describe('with intercepted network calls', () => {
},
},
});
const provider = await providerFromProfile('mfa-role');

const provider = await metaProvider();

// THEN
const sdk = (await provider.forEnvironment(env(uniq('66666')), Mode.ForReading)).sdk;
Expand Down

0 comments on commit c1d3130

Please sign in to comment.