From 59cd8660c25252057dcef31d6df229c1869066bf Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 17 Feb 2025 11:47:45 -0500 Subject: [PATCH 1/5] test: run the test 1000 times --- .../sharedCredentialsProvider.test.ts | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts b/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts index b98ee128cbd..70b23e7834b 100644 --- a/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts +++ b/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts @@ -496,25 +496,27 @@ describe('SharedCredentialsProvider', async function () { assert.strictEqual(creds.sessionToken, 'token') }) - it('assumes role with mfa token', async function () { - const sections = await createTestSections(` - ${defaultSection} - [profile assume] - source_profile = default - role_arn = testarn - mfa_serial= mfaSerialToken - `) - const sut = new SharedCredentialsProvider('assume', sections) + for (const _ of Array.from({ length: 1000 })) { + it.only('assumes role with mfa token', async function () { + const sections = await createTestSections(` + ${defaultSection} + [profile assume] + source_profile = default + role_arn = testarn + mfa_serial= mfaSerialToken + `) + const sut = new SharedCredentialsProvider('assume', sections) + + getTestWindow().onDidShowInputBox((inputBox) => { + inputBox.acceptValue('mfaToken') + }) - getTestWindow().onDidShowInputBox((inputBox) => { - inputBox.acceptValue('mfaToken') + const creds = await sut.getCredentials() + assert.strictEqual(creds.accessKeyId, 'id') + assert.strictEqual(creds.secretAccessKey, 'secret') + assert.strictEqual(creds.sessionToken, 'token') }) - - const creds = await sut.getCredentials() - assert.strictEqual(creds.accessKeyId, 'id') - assert.strictEqual(creds.secretAccessKey, 'secret') - assert.strictEqual(creds.sessionToken, 'token') - }) + } it('does not assume role when no roleArn is present', async function () { const sut = new SharedCredentialsProvider('default', await createTestSections(defaultSection)) From 3a94183018c75c59c2ad665a004c0feba619eff9 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 17 Feb 2025 12:10:38 -0500 Subject: [PATCH 2/5] test: remove it.only --- .../test/credentials/provider/sharedCredentialsProvider.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts b/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts index 70b23e7834b..6f4f861a744 100644 --- a/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts +++ b/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts @@ -497,7 +497,7 @@ describe('SharedCredentialsProvider', async function () { }) for (const _ of Array.from({ length: 1000 })) { - it.only('assumes role with mfa token', async function () { + it('assumes role with mfa token', async function () { const sections = await createTestSections(` ${defaultSection} [profile assume] From 11a8ba26f7455d5f8fb5b33a6afdb3e8fb512357 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 17 Feb 2025 12:44:39 -0500 Subject: [PATCH 3/5] refactor: migrate to newer createInputBox --- packages/core/src/auth/credentials/utils.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/core/src/auth/credentials/utils.ts b/packages/core/src/auth/credentials/utils.ts index 28fa5df1c4c..885a4fb1f87 100644 --- a/packages/core/src/auth/credentials/utils.ts +++ b/packages/core/src/auth/credentials/utils.ts @@ -14,8 +14,9 @@ import { messages, showMessageWithCancel, showViewLogsMessage } from '../../shar import { Timeout, waitTimeout } from '../../shared/utilities/timeoutUtils' import { fromExtensionManifest } from '../../shared/settings' import { Profile } from './sharedCredentials' -import { createInputBox, promptUser } from '../../shared/ui/input' import { openUrl } from '../../shared/utilities/vsCodeUtils' +import { createInputBox } from '../../shared/ui/inputPrompter' +import { isValidResponse } from '../../shared/wizards/wizard' const credentialsTimeout = 300000 // 5 minutes const credentialsProgressDelay = 1000 @@ -113,18 +114,16 @@ const errorMessageUserCancelled = localize('AWS.error.mfa.userCancelled', 'User */ export async function getMfaTokenFromUser(mfaSerial: string, profileName: string): Promise { const inputBox = createInputBox({ - options: { - ignoreFocusOut: true, - placeHolder: localize('AWS.prompt.mfa.enterCode.placeholder', 'Enter Authentication Code Here'), - title: localize('AWS.prompt.mfa.enterCode.title', 'MFA Challenge for {0}', profileName), - prompt: localize('AWS.prompt.mfa.enterCode.prompt', 'Enter code for MFA device {0}', mfaSerial), - }, + ignoreFocusOut: true, + placeholder: localize('AWS.prompt.mfa.enterCode.placeholder', 'Enter Authentication Code Here'), + title: localize('AWS.prompt.mfa.enterCode.title', 'MFA Challenge for {0}', profileName), + prompt: localize('AWS.prompt.mfa.enterCode.prompt', 'Enter code for MFA device {0}', mfaSerial), }) - const token = await promptUser({ inputBox: inputBox }) + const token = await inputBox.prompt() // Distinguish user cancel vs code entry issues with the error message - if (!token) { + if (!isValidResponse(token)) { throw new Error(errorMessageUserCancelled) } From 93755092db567c885e97aed4f00f2d6f01ff38b6 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 17 Feb 2025 14:55:16 -0500 Subject: [PATCH 4/5] test: remove test repeating --- .../sharedCredentialsProvider.test.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts b/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts index 6f4f861a744..84842078860 100644 --- a/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts +++ b/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts @@ -496,27 +496,25 @@ describe('SharedCredentialsProvider', async function () { assert.strictEqual(creds.sessionToken, 'token') }) - for (const _ of Array.from({ length: 1000 })) { - it('assumes role with mfa token', async function () { - const sections = await createTestSections(` + it('assumes role with mfa token', async function () { + const sections = await createTestSections(` ${defaultSection} [profile assume] source_profile = default role_arn = testarn mfa_serial= mfaSerialToken `) - const sut = new SharedCredentialsProvider('assume', sections) - - getTestWindow().onDidShowInputBox((inputBox) => { - inputBox.acceptValue('mfaToken') - }) + const sut = new SharedCredentialsProvider('assume', sections) - const creds = await sut.getCredentials() - assert.strictEqual(creds.accessKeyId, 'id') - assert.strictEqual(creds.secretAccessKey, 'secret') - assert.strictEqual(creds.sessionToken, 'token') + getTestWindow().onDidShowInputBox((inputBox) => { + inputBox.acceptValue('mfaToken') }) - } + + const creds = await sut.getCredentials() + assert.strictEqual(creds.accessKeyId, 'id') + assert.strictEqual(creds.secretAccessKey, 'secret') + assert.strictEqual(creds.sessionToken, 'token') + }) it('does not assume role when no roleArn is present', async function () { const sut = new SharedCredentialsProvider('default', await createTestSections(defaultSection)) From ec7a586f0b37299c3b3bac4486d36e3eb395cd3c Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 17 Feb 2025 15:18:58 -0500 Subject: [PATCH 5/5] test: avoid formatting change --- .../provider/sharedCredentialsProvider.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts b/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts index 84842078860..b98ee128cbd 100644 --- a/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts +++ b/packages/core/src/test/credentials/provider/sharedCredentialsProvider.test.ts @@ -498,12 +498,12 @@ describe('SharedCredentialsProvider', async function () { it('assumes role with mfa token', async function () { const sections = await createTestSections(` - ${defaultSection} - [profile assume] - source_profile = default - role_arn = testarn - mfa_serial= mfaSerialToken - `) + ${defaultSection} + [profile assume] + source_profile = default + role_arn = testarn + mfa_serial= mfaSerialToken + `) const sut = new SharedCredentialsProvider('assume', sections) getTestWindow().onDidShowInputBox((inputBox) => {