@@ -115,4 +115,102 @@ describe('CodeCatalystAuthenticationProvider', async function () {
115
115
assert . deepStrictEqual ( conn . scopes , [ otherScope , ...defaultScopes ] )
116
116
} )
117
117
} )
118
+
119
+ describe ( 'tryConnectTo' , async ( ) => {
120
+ it ( 'should do nothing if connection is already active' , async function ( ) {
121
+ Sinon . stub ( codecatalystAuth , 'isConnectionOnboarded' ) . resolves ( true )
122
+ const connectToEnterpriseSso = Sinon . spy ( codecatalystAuth , 'connectToEnterpriseSso' )
123
+
124
+ getTestWindow ( ) . onDidShowQuickPick ( async picker => {
125
+ await picker . untilReady ( )
126
+ picker . acceptItem ( picker . items [ 1 ] )
127
+ } )
128
+
129
+ await codecatalystAuth . connectToEnterpriseSso ( enterpriseSsoStartUrl , 'us-east-1' )
130
+ let conn = codecatalystAuth . activeConnection
131
+ assert . strictEqual ( conn ?. type , 'sso' )
132
+ assert . strictEqual ( conn . label , 'IAM Identity Center (enterprise)' )
133
+
134
+ await codecatalystAuth . tryConnectTo ( { startUrl : enterpriseSsoStartUrl , region : 'us-east-1' } )
135
+ conn = codecatalystAuth . activeConnection
136
+ assert . strictEqual ( conn ?. type , 'sso' )
137
+ assert . strictEqual ( conn . label , 'IAM Identity Center (enterprise)' )
138
+
139
+ assert . strictEqual ( connectToEnterpriseSso . callCount , 1 , 'Expected no extra calls on active connection' )
140
+ } )
141
+
142
+ it ( 'should switch to IAM Identity Center' , async function ( ) {
143
+ Sinon . stub ( codecatalystAuth , 'isConnectionOnboarded' ) . resolves ( true )
144
+ const connectToEnterpriseSso = Sinon . spy ( codecatalystAuth , 'connectToEnterpriseSso' )
145
+
146
+ getTestWindow ( ) . onDidShowQuickPick ( async picker => {
147
+ await picker . untilReady ( )
148
+ picker . acceptItem ( picker . items [ 1 ] )
149
+ } )
150
+
151
+ await codecatalystAuth . connectToEnterpriseSso ( enterpriseSsoStartUrl , 'us-east-1' )
152
+ let conn = codecatalystAuth . activeConnection
153
+ assert . strictEqual ( conn ?. type , 'sso' )
154
+ assert . strictEqual ( conn . label , 'IAM Identity Center (enterprise)' )
155
+ assert . strictEqual ( connectToEnterpriseSso . callCount , 1 , 'Expected one call to connectToEnterpriseSso' )
156
+
157
+ getTestWindow ( ) . onDidShowQuickPick ( async picker => {
158
+ await picker . untilReady ( )
159
+ picker . acceptItem ( picker . items [ 1 ] )
160
+ } )
161
+
162
+ await codecatalystAuth . tryConnectTo ( {
163
+ startUrl : 'https://other-enterprise.awsapps.com/start' ,
164
+ region : 'us-east-1' ,
165
+ } )
166
+ conn = codecatalystAuth . activeConnection
167
+ assert . strictEqual ( conn ?. type , 'sso' )
168
+ assert . strictEqual ( conn . label , 'IAM Identity Center (other-enterprise)' )
169
+ assert . strictEqual ( conn . startUrl , 'https://other-enterprise.awsapps.com/start' )
170
+
171
+ assert . strictEqual (
172
+ connectToEnterpriseSso . callCount ,
173
+ 2 ,
174
+ 'Expected two calls to complete switch for connectToEnterpriseSso'
175
+ )
176
+ } )
177
+
178
+ it ( 'should switch to Builder ID' , async function ( ) {
179
+ Sinon . stub ( codecatalystAuth , 'isConnectionOnboarded' ) . resolves ( true )
180
+ const connectToAwsBuilderId = Sinon . spy ( codecatalystAuth , 'connectToAwsBuilderId' )
181
+ const connectToEnterpriseSso = Sinon . spy ( codecatalystAuth , 'connectToEnterpriseSso' )
182
+
183
+ getTestWindow ( ) . onDidShowQuickPick ( async picker => {
184
+ await picker . untilReady ( )
185
+ picker . acceptItem ( picker . items [ 1 ] )
186
+ } )
187
+
188
+ await codecatalystAuth . tryConnectTo ( {
189
+ startUrl : 'https://other-enterprise.awsapps.com/start' ,
190
+ region : 'us-east-1' ,
191
+ } )
192
+ let conn = codecatalystAuth . activeConnection
193
+ assert . strictEqual ( conn ?. type , 'sso' )
194
+ assert . strictEqual ( conn . label , 'IAM Identity Center (other-enterprise)' )
195
+ assert . strictEqual ( conn . startUrl , 'https://other-enterprise.awsapps.com/start' )
196
+
197
+ assert . strictEqual ( connectToEnterpriseSso . callCount , 1 , 'Expected one call to connectToEnterpriseSso' )
198
+
199
+ getTestWindow ( ) . onDidShowQuickPick ( async picker => {
200
+ await picker . untilReady ( )
201
+ picker . acceptItem ( picker . items [ 1 ] )
202
+ } )
203
+
204
+ await codecatalystAuth . connectToAwsBuilderId ( )
205
+ conn = codecatalystAuth . activeConnection
206
+ assert . strictEqual ( conn ?. type , 'sso' )
207
+ assert . strictEqual ( conn . label , 'AWS Builder ID' )
208
+ assert . strictEqual ( connectToAwsBuilderId . callCount , 1 , 'Expected one call to connectToAwsBuilderId' )
209
+ assert . strictEqual (
210
+ connectToEnterpriseSso . callCount ,
211
+ 1 ,
212
+ 'Expected no additional calls to connectToEnterpriseSso'
213
+ )
214
+ } )
215
+ } )
118
216
} )
0 commit comments