Skip to content

Commit 2a445ee

Browse files
authored
fix(amazonq): profile is not set after re-auth (#1690)
1 parent 02c4d64 commit 2a445ee

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

server/aws-lsp-codewhisperer/src/shared/amazonQServiceManager/AmazonQTokenServiceManager.test.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -838,27 +838,45 @@ describe('AmazonQTokenServiceManager', () => {
838838
})
839839

840840
describe('Connection types with no Developer Profiles support', () => {
841-
it('returns error when profile update is requested and connection type is none', async () => {
841+
it('handles reauthentication scenario when connection type is none but profile ARN is provided', async () => {
842842
setupServiceManager(true)
843843
clearCredentials()
844844

845845
assert.strictEqual(amazonQTokenServiceManager.getState(), 'PENDING_CONNECTION')
846+
assert.strictEqual(amazonQTokenServiceManager.getConnectionType(), 'none')
846847

847-
await assert.rejects(
848-
amazonQTokenServiceManager.handleOnUpdateConfiguration(
849-
{
850-
section: 'aws.q',
851-
settings: {
852-
profileArn: 'arn:aws:testprofilearn:us-east-1:11111111111111:profile/QQQQQQQQQQQQ',
853-
},
848+
await amazonQTokenServiceManager.handleOnUpdateConfiguration(
849+
{
850+
section: 'aws.q',
851+
settings: {
852+
profileArn: 'arn:aws:testprofilearn:us-east-1:11111111111111:profile/QQQQQQQQQQQQ',
854853
},
855-
{} as CancellationToken
856-
),
857-
new ResponseError(LSPErrorCodes.RequestFailed, 'Amazon Q service is not signed in', {
858-
awsErrorCode: 'E_AMAZON_Q_PENDING_CONNECTION',
859-
})
854+
},
855+
{} as CancellationToken
860856
)
861857

858+
assert.strictEqual(amazonQTokenServiceManager.getConnectionType(), 'identityCenter')
859+
assert.strictEqual(amazonQTokenServiceManager.getState(), 'INITIALIZED')
860+
})
861+
862+
it('ignores null profile when connection type is none', async () => {
863+
setupServiceManager(true)
864+
clearCredentials()
865+
866+
assert.strictEqual(amazonQTokenServiceManager.getState(), 'PENDING_CONNECTION')
867+
assert.strictEqual(amazonQTokenServiceManager.getConnectionType(), 'none')
868+
869+
await amazonQTokenServiceManager.handleOnUpdateConfiguration(
870+
{
871+
section: 'aws.q',
872+
settings: {
873+
profileArn: null,
874+
},
875+
},
876+
{} as CancellationToken
877+
)
878+
879+
assert.strictEqual(amazonQTokenServiceManager.getConnectionType(), 'none')
862880
assert.strictEqual(amazonQTokenServiceManager.getState(), 'PENDING_CONNECTION')
863881
})
864882

server/aws-lsp-codewhisperer/src/shared/amazonQServiceManager/AmazonQTokenServiceManager.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,14 @@ export class AmazonQTokenServiceManager extends BaseAmazonQServiceManager<
290290

291291
if (this.connectionType === 'none') {
292292
if (newProfileArn !== null) {
293-
throw new AmazonQServicePendingSigninError()
293+
// During reauthentication, connection might be temporarily 'none' but user is providing a profile
294+
// Set connection type to identityCenter to proceed with profile setting
295+
this.connectionType = 'identityCenter'
296+
this.state = 'PENDING_Q_PROFILE_UPDATE'
297+
} else {
298+
this.logServiceState('Received null profile while not connected, ignoring request')
299+
return
294300
}
295-
296-
this.logServiceState('Received null profile while not connected, ignoring request')
297-
return
298301
}
299302

300303
if (this.connectionType !== 'identityCenter') {

0 commit comments

Comments
 (0)