Skip to content

Commit c1d3130

Browse files
authored
chore(cli): new test for MFA + AWS_Profile (#32566)
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*
1 parent e9b5026 commit c1d3130

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/aws-cdk/test/api/sdk-provider.test.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,19 @@ describe('with intercepted network calls', () => {
300300
expect((await provider.defaultAccount())?.accountId).toEqual(uniq('22222'));
301301
});
302302

303-
test('mfa_serial in profile will ask user for token', async () => {
303+
const providersForMfa = [
304+
(() => providerFromProfile('mfa-role')),
305+
(async () => {
306+
// The profile is not passed explicitly. Should be picked from the environment variable
307+
process.env.AWS_PROFILE = 'mfa-role';
308+
// Awaiting to make sure the environment variable is only deleted after it's used
309+
const provider = await SdkProvider.withAwsCliCompatibleDefaults({ logger: console });
310+
delete process.env.AWS_PROFILE;
311+
return Promise.resolve(provider);
312+
}),
313+
];
314+
315+
test.each(providersForMfa)('mfa_serial in profile will ask user for token', async (metaProvider: () => Promise<SdkProvider>) => {
304316
// GIVEN
305317
const mockPrompt = jest.spyOn(promptly, 'prompt').mockResolvedValue('1234');
306318

@@ -320,7 +332,8 @@ describe('with intercepted network calls', () => {
320332
},
321333
},
322334
});
323-
const provider = await providerFromProfile('mfa-role');
335+
336+
const provider = await metaProvider();
324337

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

0 commit comments

Comments
 (0)