Skip to content

Commit 4ed5e9c

Browse files
committed
fix authUtil tests and description for getMfaSerial
1 parent 7d69f1d commit 4ed5e9c

File tree

4 files changed

+48
-71
lines changed

4 files changed

+48
-71
lines changed

packages/amazonq/package.json

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,134 +1196,106 @@
11961196
"description": "AWS Contributed Icon",
11971197
"default": {
11981198
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1199-
"fontCharacter": "\\f1d3"
1199+
"fontCharacter": "\\f1d1"
12001200
}
12011201
},
12021202
"aws-mynah-MynahIconBlack": {
12031203
"description": "AWS Contributed Icon",
12041204
"default": {
12051205
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1206-
"fontCharacter": "\\f1d4"
1206+
"fontCharacter": "\\f1d2"
12071207
}
12081208
},
12091209
"aws-mynah-MynahIconWhite": {
12101210
"description": "AWS Contributed Icon",
12111211
"default": {
12121212
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1213-
"fontCharacter": "\\f1d5"
1213+
"fontCharacter": "\\f1d3"
12141214
}
12151215
},
12161216
"aws-mynah-logo": {
12171217
"description": "AWS Contributed Icon",
12181218
"default": {
12191219
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1220-
"fontCharacter": "\\f1d6"
1220+
"fontCharacter": "\\f1d4"
12211221
}
12221222
},
12231223
"aws-redshift-cluster": {
12241224
"description": "AWS Contributed Icon",
12251225
"default": {
12261226
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1227-
"fontCharacter": "\\f1d7"
1227+
"fontCharacter": "\\f1d5"
12281228
}
12291229
},
12301230
"aws-redshift-cluster-connected": {
12311231
"description": "AWS Contributed Icon",
12321232
"default": {
12331233
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1234-
"fontCharacter": "\\f1d8"
1234+
"fontCharacter": "\\f1d6"
12351235
}
12361236
},
12371237
"aws-redshift-database": {
12381238
"description": "AWS Contributed Icon",
12391239
"default": {
12401240
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1241-
"fontCharacter": "\\f1d9"
1241+
"fontCharacter": "\\f1d7"
12421242
}
12431243
},
12441244
"aws-redshift-redshift-cluster-connected": {
12451245
"description": "AWS Contributed Icon",
12461246
"default": {
12471247
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1248-
"fontCharacter": "\\f1da"
1248+
"fontCharacter": "\\f1d8"
12491249
}
12501250
},
12511251
"aws-redshift-schema": {
12521252
"description": "AWS Contributed Icon",
12531253
"default": {
12541254
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1255-
"fontCharacter": "\\f1db"
1255+
"fontCharacter": "\\f1d9"
12561256
}
12571257
},
12581258
"aws-redshift-table": {
12591259
"description": "AWS Contributed Icon",
12601260
"default": {
12611261
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1262-
"fontCharacter": "\\f1dc"
1262+
"fontCharacter": "\\f1da"
12631263
}
12641264
},
12651265
"aws-s3-bucket": {
12661266
"description": "AWS Contributed Icon",
12671267
"default": {
12681268
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1269-
"fontCharacter": "\\f1dd"
1269+
"fontCharacter": "\\f1db"
12701270
}
12711271
},
12721272
"aws-s3-create-bucket": {
12731273
"description": "AWS Contributed Icon",
12741274
"default": {
12751275
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1276-
"fontCharacter": "\\f1de"
1276+
"fontCharacter": "\\f1dc"
12771277
}
12781278
},
12791279
"aws-schemas-registry": {
12801280
"description": "AWS Contributed Icon",
12811281
"default": {
12821282
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1283-
"fontCharacter": "\\f1e1"
1283+
"fontCharacter": "\\f1dd"
12841284
}
12851285
},
12861286
"aws-schemas-schema": {
12871287
"description": "AWS Contributed Icon",
12881288
"default": {
12891289
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1290-
"fontCharacter": "\\f1e2"
1290+
"fontCharacter": "\\f1de"
12911291
}
12921292
},
12931293
"aws-stepfunctions-preview": {
1294-
"description": "AWS Contributed Icon",
1295-
"default": {
1296-
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1297-
"fontCharacter": "\\f1e3"
1298-
}
1299-
},
1300-
"aws-lambda-create-stack": {
1301-
"description": "AWS Contributed Icon",
1302-
"default": {
1303-
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1304-
"fontCharacter": "\\f1d1"
1305-
}
1306-
},
1307-
"aws-lambda-create-stack-light": {
1308-
"description": "AWS Contributed Icon",
1309-
"default": {
1310-
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1311-
"fontCharacter": "\\f1d2"
1312-
}
1313-
},
1314-
"aws-sagemaker-code-editor": {
13151294
"description": "AWS Contributed Icon",
13161295
"default": {
13171296
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13181297
"fontCharacter": "\\f1df"
13191298
}
1320-
},
1321-
"aws-sagemaker-jupyter-lab": {
1322-
"description": "AWS Contributed Icon",
1323-
"default": {
1324-
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1325-
"fontCharacter": "\\f1e0"
1326-
}
13271299
}
13281300
},
13291301
"walkthroughs": [

packages/amazonq/test/unit/codewhisperer/util/authUtil.test.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createTestAuthUtil, TestFolder } from 'aws-core-vscode/test'
1111
import { constants, cache } from 'aws-core-vscode/auth'
1212
import { auth2 } from 'aws-core-vscode/auth'
1313
import { mementoUtils, fs } from 'aws-core-vscode/shared'
14+
import { GetIamCredentialResult } from '@aws/language-server-runtimes/protocol'
1415

1516
describe('AuthUtil', async function () {
1617
let auth: any
@@ -413,16 +414,19 @@ describe('AuthUtil', async function () {
413414
describe('loginIam', function () {
414415
it('creates IAM session and logs in', async function () {
415416
const mockResponse = {
416-
id: 'test-credential-id',
417-
credentials: {
418-
accessKeyId: 'encrypted-access-key',
419-
secretAccessKey: 'encrypted-secret-key',
420-
sessionToken: 'encrypted-session-token',
417+
credential: {
418+
id: 'test-credential-id',
419+
kinds: [],
420+
credentials: {
421+
accessKeyId: 'encrypted-access-key',
422+
secretAccessKey: 'encrypted-secret-key',
423+
sessionToken: 'encrypted-session-token',
424+
},
421425
},
422426
updateCredentialsParams: {
423427
data: 'credential-data',
424428
},
425-
}
429+
} satisfies GetIamCredentialResult
426430

427431
const mockIamLogin = {
428432
login: sinon.stub().resolves(mockResponse),
@@ -431,32 +435,34 @@ describe('AuthUtil', async function () {
431435

432436
sinon.stub(auth2, 'IamLogin').returns(mockIamLogin as any)
433437

434-
const response = await auth.loginIam('accessKey', 'secretKey', 'sessionToken')
438+
const response = await auth.loginIam('testAccessKey', 'testSecretKey', 'testSessionToken')
435439

436440
assert.ok(mockIamLogin.login.calledOnce)
437441
assert.ok(
438442
mockIamLogin.login.calledWithMatch({
439-
accessKey: 'accessKey',
440-
secretKey: 'secretKey',
441-
sessionToken: 'sessionToken',
443+
accessKey: 'testAccessKey',
444+
secretKey: 'testSecretKey',
445+
sessionToken: 'testSessionToken',
442446
})
443447
)
444448
assert.strictEqual(response, mockResponse)
445449
})
446450

447451
it('creates IAM session with role ARN', async function () {
448452
const mockResponse = {
449-
id: 'test-credential-id',
450-
credentials: {
451-
accessKeyId: 'encrypted-access-key',
452-
secretAccessKey: 'encrypted-secret-key',
453-
sessionToken: 'encrypted-session-token',
454-
roleArn: 'arn:aws:iam::123456789012:role/TestRole',
453+
credential: {
454+
id: 'test-credential-id',
455+
kinds: [],
456+
credentials: {
457+
accessKeyId: 'encrypted-access-key',
458+
secretAccessKey: 'encrypted-secret-key',
459+
sessionToken: 'encrypted-session-token',
460+
},
455461
},
456462
updateCredentialsParams: {
457463
data: 'credential-data',
458464
},
459-
}
465+
} satisfies GetIamCredentialResult
460466

461467
const mockIamLoginArn = {
462468
login: sinon.stub().resolves(mockResponse),
@@ -466,18 +472,18 @@ describe('AuthUtil', async function () {
466472
sinon.stub(auth2, 'IamLogin').returns(mockIamLoginArn as any)
467473

468474
const response = await auth.loginIam(
469-
'accessKey',
470-
'secretKey',
471-
'sessionToken',
475+
'testAccessKey',
476+
'testSecretKey',
477+
'testSessionToken',
472478
'arn:aws:iam::123456789012:role/TestRole'
473479
)
474480

475481
assert.ok(mockIamLoginArn.login.calledOnce)
476482
assert.ok(
477483
mockIamLoginArn.login.calledWith({
478-
accessKey: 'accessKey',
479-
secretKey: 'secretKey',
480-
sessionToken: 'sessionToken',
484+
accessKey: 'testAccessKey',
485+
secretKey: 'testSecretKey',
486+
sessionToken: 'testSessionToken',
481487
roleArn: 'arn:aws:iam::123456789012:role/TestRole',
482488
})
483489
)

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,10 @@ const errorMessageUserCancelled = localize('AWS.error.mfa.userCancelled', 'User
105105
/**
106106
* @description Prompts user for MFA serial number
107107
*
108-
* Entered token is passed to the callback.
109-
* If user cancels out, the callback is passed an error with a fixed message string.
110-
*
111-
* @param profileName Name of Credentials profile we are asking an MFA Token for
112-
* @param callback tokens/errors are passed through here
108+
* @param defaultSerial Default MFA serial number to pre-fill
109+
* @param profileName Name of Credentials profile we are asking an MFA serial for
110+
* @returns Promise that resolves to the entered MFA serial number
111+
* @throws Error if user cancels the input
113112
*/
114113
export async function getMfaSerialFromUser(defaultSerial: string, profileName: string): Promise<string> {
115114
const inputBox = createInputBox({

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class AuthUtil implements IAuthProvider {
154154
await this.session.restore()
155155
if (!this.isConnected()) {
156156
// If both fail, reset the session
157-
await this.session?.logout()
157+
this.session = undefined
158158
}
159159
}
160160
}

0 commit comments

Comments
 (0)