@@ -26,19 +26,19 @@ describe('AuthUtil', async function () {
2626
2727 describe ( 'Auth state' , function ( ) {
2828 it ( 'login with BuilderId' , async function ( ) {
29- await auth . login ( constants . builderIdStartUrl , constants . builderIdRegion )
29+ await auth . login_sso ( constants . builderIdStartUrl , constants . builderIdRegion )
3030 assert . ok ( auth . isConnected ( ) )
3131 assert . ok ( auth . isBuilderIdConnection ( ) )
3232 } )
3333
3434 it ( 'login with IDC' , async function ( ) {
35- await auth . login ( 'https://example.awsapps.com/start' , 'us-east-1' )
35+ await auth . login_sso ( 'https://example.awsapps.com/start' , 'us-east-1' )
3636 assert . ok ( auth . isConnected ( ) )
3737 assert . ok ( auth . isIdcConnection ( ) )
3838 } )
3939
4040 it ( 'identifies internal users' , async function ( ) {
41- await auth . login ( constants . internalStartUrl , 'us-east-1' )
41+ await auth . login_sso ( constants . internalStartUrl , 'us-east-1' )
4242 assert . ok ( auth . isInternalAmazonUser ( ) )
4343 } )
4444
@@ -55,7 +55,7 @@ describe('AuthUtil', async function () {
5555
5656 describe ( 'Token management' , function ( ) {
5757 it ( 'can get token when connected with SSO' , async function ( ) {
58- await auth . login ( constants . builderIdStartUrl , constants . builderIdRegion )
58+ await auth . login_sso ( constants . builderIdStartUrl , constants . builderIdRegion )
5959 const token = await auth . getToken ( )
6060 assert . ok ( token )
6161 } )
@@ -68,14 +68,14 @@ describe('AuthUtil', async function () {
6868
6969 describe ( 'getTelemetryMetadata' , function ( ) {
7070 it ( 'returns valid metadata for BuilderId connection' , async function ( ) {
71- await auth . login ( constants . builderIdStartUrl , constants . builderIdRegion )
71+ await auth . login_sso ( constants . builderIdStartUrl , constants . builderIdRegion )
7272 const metadata = await auth . getTelemetryMetadata ( )
7373 assert . strictEqual ( metadata . credentialSourceId , 'awsId' )
7474 assert . strictEqual ( metadata . credentialStartUrl , constants . builderIdStartUrl )
7575 } )
7676
7777 it ( 'returns valid metadata for IDC connection' , async function ( ) {
78- await auth . login ( 'https://example.awsapps.com/start' , 'us-east-1' )
78+ await auth . login_sso ( 'https://example.awsapps.com/start' , 'us-east-1' )
7979 const metadata = await auth . getTelemetryMetadata ( )
8080 assert . strictEqual ( metadata . credentialSourceId , 'iamIdentityCenter' )
8181 assert . strictEqual ( metadata . credentialStartUrl , 'https://example.awsapps.com/start' )
@@ -96,37 +96,38 @@ describe('AuthUtil', async function () {
9696 } )
9797
9898 it ( 'returns BuilderId forms when using BuilderId' , async function ( ) {
99- await auth . login ( constants . builderIdStartUrl , constants . builderIdRegion )
99+ await auth . login_sso ( constants . builderIdStartUrl , constants . builderIdRegion )
100100 const forms = await auth . getAuthFormIds ( )
101101 assert . deepStrictEqual ( forms , [ 'builderIdCodeWhisperer' ] )
102102 } )
103103
104104 it ( 'returns IDC forms when using IDC without SSO account access' , async function ( ) {
105105 const session = ( auth as any ) . session
106- sinon . stub ( session , 'getProfile' ) . resolves ( {
106+ session && sinon . stub ( session , 'getProfile' ) . resolves ( {
107107 ssoSession : {
108108 settings : {
109109 sso_registration_scopes : [ 'codewhisperer:*' ] ,
110110 } ,
111111 } ,
112112 } )
113113
114- await auth . login ( 'https://example.awsapps.com/start' , 'us-east-1' )
114+ await auth . login_sso ( 'https://example.awsapps.com/start' , 'us-east-1' )
115115 const forms = await auth . getAuthFormIds ( )
116116 assert . deepStrictEqual ( forms , [ 'identityCenterCodeWhisperer' ] )
117117 } )
118118
119119 it ( 'returns IDC forms with explorer when using IDC with SSO account access' , async function ( ) {
120+ await auth . login_sso ( 'https://example.awsapps.com/start' , 'us-east-1' )
120121 const session = ( auth as any ) . session
121- sinon . stub ( session , 'getProfile' ) . resolves ( {
122+
123+ session && sinon . stub ( session , 'getProfile' ) . resolves ( {
122124 ssoSession : {
123125 settings : {
124126 sso_registration_scopes : [ 'codewhisperer:*' , 'sso:account:access' ] ,
125127 } ,
126128 } ,
127129 } )
128130
129- await auth . login ( 'https://example.awsapps.com/start' , 'us-east-1' )
130131 const forms = await auth . getAuthFormIds ( )
131132 assert . deepStrictEqual ( forms . sort ( ) , [ 'identityCenterCodeWhisperer' , 'identityCenterExplorer' ] . sort ( ) )
132133 } )
@@ -178,7 +179,7 @@ describe('AuthUtil', async function () {
178179 } )
179180
180181 it ( 'updates bearer token when state is refreshed' , async function ( ) {
181- await auth . login ( constants . builderIdStartUrl , 'us-east-1' )
182+ await auth . login_sso ( constants . builderIdStartUrl , 'us-east-1' )
182183
183184 await ( auth as any ) . stateChangeHandler ( { state : 'refreshed' } )
184185
@@ -187,7 +188,7 @@ describe('AuthUtil', async function () {
187188 } )
188189
189190 it ( 'cleans up when connection expires' , async function ( ) {
190- await auth . login ( constants . builderIdStartUrl , 'us-east-1' )
191+ await auth . login_sso ( constants . builderIdStartUrl , 'us-east-1' )
191192
192193 await ( auth as any ) . stateChangeHandler ( { state : 'expired' } )
193194
@@ -197,13 +198,15 @@ describe('AuthUtil', async function () {
197198 it ( 'deletes bearer token when disconnected' , async function ( ) {
198199 await ( auth as any ) . stateChangeHandler ( { state : 'notConnected' } )
199200
200- assert . ok ( mockLspAuth . deleteBearerToken . called )
201+ if ( auth . isSsoSession ( auth . session ) ) {
202+ assert . ok ( mockLspAuth . deleteBearerToken . called )
203+ }
201204 } )
202205
203206 it ( 'updates bearer token and restores profile on reconnection' , async function ( ) {
204207 const restoreProfileSelectionSpy = sinon . spy ( regionProfileManager , 'restoreProfileSelection' )
205208
206- await auth . login ( 'https://example.awsapps.com/start' , 'us-east-1' )
209+ await auth . login_sso ( 'https://example.awsapps.com/start' , 'us-east-1' )
207210
208211 await ( auth as any ) . stateChangeHandler ( { state : 'connected' } )
209212
@@ -215,7 +218,7 @@ describe('AuthUtil', async function () {
215218 const invalidateProfileSpy = sinon . spy ( regionProfileManager , 'invalidateProfile' )
216219 const clearCacheSpy = sinon . spy ( regionProfileManager , 'clearCache' )
217220
218- await auth . login ( 'https://example.awsapps.com/start' , 'us-east-1' )
221+ await auth . login_sso ( 'https://example.awsapps.com/start' , 'us-east-1' )
219222
220223 await ( auth as any ) . stateChangeHandler ( { state : 'expired' } )
221224
@@ -280,12 +283,16 @@ describe('AuthUtil', async function () {
280283 await auth . migrateSsoConnectionToLsp ( 'test-client' )
281284
282285 assert . ok ( memento . update . calledWith ( 'auth.profiles' , undefined ) )
283- assert . ok ( ! auth . session . updateProfile ?. called )
286+ assert . ok ( ! auth . session ? .updateProfile ?. called )
284287 } )
285288
286289 it ( 'proceeds with migration if LSP token check throws' , async function ( ) {
287290 memento . get . returns ( { profile1 : validProfile } )
288291 mockLspAuth . getSsoToken . rejects ( new Error ( 'Token check failed' ) )
292+
293+ if ( ! ( auth as any ) . session ) {
294+ auth . session = new auth2 . SsoLogin ( auth . profileName , auth . lspAuth , auth . eventEmitter )
295+ }
289296 const updateProfileStub = sinon . stub ( ( auth as any ) . session , 'updateProfile' ) . resolves ( )
290297
291298 await auth . migrateSsoConnectionToLsp ( 'test-client' )
@@ -297,22 +304,24 @@ describe('AuthUtil', async function () {
297304 it ( 'migrates valid SSO connection' , async function ( ) {
298305 memento . get . returns ( { profile1 : validProfile } )
299306
300- const updateProfileStub = sinon . stub ( ( auth as any ) . session , 'updateProfile' ) . resolves ( )
307+ if ( ( auth as any ) . session ) {
308+ const updateProfileStub = sinon . stub ( ( auth as any ) . session , 'updateProfile' ) . resolves ( )
301309
302- await auth . migrateSsoConnectionToLsp ( 'test-client' )
310+ await auth . migrateSsoConnectionToLsp ( 'test-client' )
303311
304- assert . ok ( updateProfileStub . calledOnce )
305- assert . ok ( memento . update . calledWith ( 'auth.profiles' , undefined ) )
312+ assert . ok ( updateProfileStub . calledOnce )
313+ assert . ok ( memento . update . calledWith ( 'auth.profiles' , undefined ) )
306314
307- const files = await fs . readdir ( cacheDir )
308- assert . strictEqual ( files . length , 2 ) // Should have both the token and registration file
309-
310- // Verify file contents were preserved
311- const newFiles = files . map ( ( f ) => path . join ( cacheDir , f [ 0 ] ) )
312- for ( const file of newFiles ) {
313- const content = await fs . readFileText ( file )
314- const parsed = JSON . parse ( content )
315- assert . ok ( parsed . test === 'registration' || parsed . test === 'token' )
315+ const files = await fs . readdir ( cacheDir )
316+ assert . strictEqual ( files . length , 2 ) // Should have both the token and registration file
317+
318+ // Verify file contents were preserved
319+ const newFiles = files . map ( ( f ) => path . join ( cacheDir , f [ 0 ] ) )
320+ for ( const file of newFiles ) {
321+ const content = await fs . readFileText ( file )
322+ const parsed = JSON . parse ( content )
323+ assert . ok ( parsed . test === 'registration' || parsed . test === 'token' )
324+ }
316325 }
317326 } )
318327
@@ -351,6 +360,10 @@ describe('AuthUtil', async function () {
351360 }
352361 memento . get . returns ( mockProfiles )
353362
363+ if ( ! ( auth as any ) . session ) {
364+ auth . session = new auth2 . SsoLogin ( auth . profileName , auth . lspAuth , auth . eventEmitter )
365+ }
366+
354367 const updateProfileStub = sinon . stub ( ( auth as any ) . session , 'updateProfile' ) . resolves ( )
355368
356369 await auth . migrateSsoConnectionToLsp ( 'test-client' )
@@ -376,6 +389,10 @@ describe('AuthUtil', async function () {
376389 }
377390 memento . get . returns ( mockProfiles )
378391
392+ if ( ! ( auth as any ) . session ) {
393+ auth . session = new auth2 . SsoLogin ( auth . profileName , auth . lspAuth , auth . eventEmitter )
394+ }
395+
379396 const updateProfileStub = sinon . stub ( ( auth as any ) . session , 'updateProfile' ) . resolves ( )
380397
381398 await auth . migrateSsoConnectionToLsp ( 'test-client' )
0 commit comments