Skip to content

Commit c892f7f

Browse files
authored
test(auth): deprecated InputBox usage causes flakiness aws#6596
## Problem aws#6594 The `getMfaCodeFromUser` currently uses a deprecated version of `createInputBox` and the following `promptUser` function: https://github.com/aws/aws-toolkit-vscode/blob/0fa1b5b47ab642458df934192832a4ffcb6c9d1e/packages/core/src/shared/ui/input.ts#L72-L135 Based on the stack trace, there is a race condition here that can lead to a type error, but unsure how? Stack trace: ``` TypeError: inputBox.hide is not a function at promptUser (/Users/runner/work/aws-toolkit-vscode/aws-toolkit-vscode/packages/core/src/shared/ui/input.ts:133:18) at async getMfaTokenFromUser (/Users/runner/work/aws-toolkit-vscode/aws-toolkit-vscode/packages/core/src/auth/credentials/utils.ts:124:19) at async /Users/runner/work/aws-toolkit-vscode/aws-toolkit-vscode/packages/core/src/auth/providers/sharedCredentialsProvider.ts:422:38 ``` ### Investigation Notes: - The error only happens when running the test suite as a whole. - The error only happens in CI (unable to reproduce locally). ## Solution - avoid use of deprecated `createInputBox` [function](https://github.com/aws/aws-toolkit-vscode/blob/0fa1b5b47ab642458df934192832a4ffcb6c9d1e/packages/core/src/shared/ui/input.ts#L31-L58), prefer new version instead. - Ran the tests 4x with 1000x on the test, and did not see a failure. ## Future Work - Migrate existing cases away from this deprecated `createInputBox` if there is evidence it leads to flaky tests or unreliable behavior.
1 parent 06b3725 commit c892f7f

File tree

1 file changed

+8
-9
lines changed
  • packages/core/src/auth/credentials

1 file changed

+8
-9
lines changed

packages/core/src/auth/credentials/utils.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import { messages, showMessageWithCancel, showViewLogsMessage } from '../../shar
1414
import { Timeout, waitTimeout } from '../../shared/utilities/timeoutUtils'
1515
import { fromExtensionManifest } from '../../shared/settings'
1616
import { Profile } from './sharedCredentials'
17-
import { createInputBox, promptUser } from '../../shared/ui/input'
1817
import { openUrl } from '../../shared/utilities/vsCodeUtils'
18+
import { createInputBox } from '../../shared/ui/inputPrompter'
19+
import { isValidResponse } from '../../shared/wizards/wizard'
1920

2021
const credentialsTimeout = 300000 // 5 minutes
2122
const credentialsProgressDelay = 1000
@@ -113,18 +114,16 @@ const errorMessageUserCancelled = localize('AWS.error.mfa.userCancelled', 'User
113114
*/
114115
export async function getMfaTokenFromUser(mfaSerial: string, profileName: string): Promise<string> {
115116
const inputBox = createInputBox({
116-
options: {
117-
ignoreFocusOut: true,
118-
placeHolder: localize('AWS.prompt.mfa.enterCode.placeholder', 'Enter Authentication Code Here'),
119-
title: localize('AWS.prompt.mfa.enterCode.title', 'MFA Challenge for {0}', profileName),
120-
prompt: localize('AWS.prompt.mfa.enterCode.prompt', 'Enter code for MFA device {0}', mfaSerial),
121-
},
117+
ignoreFocusOut: true,
118+
placeholder: localize('AWS.prompt.mfa.enterCode.placeholder', 'Enter Authentication Code Here'),
119+
title: localize('AWS.prompt.mfa.enterCode.title', 'MFA Challenge for {0}', profileName),
120+
prompt: localize('AWS.prompt.mfa.enterCode.prompt', 'Enter code for MFA device {0}', mfaSerial),
122121
})
123122

124-
const token = await promptUser({ inputBox: inputBox })
123+
const token = await inputBox.prompt()
125124

126125
// Distinguish user cancel vs code entry issues with the error message
127-
if (!token) {
126+
if (!isValidResponse(token)) {
128127
throw new Error(errorMessageUserCancelled)
129128
}
130129

0 commit comments

Comments
 (0)