@@ -132,15 +132,17 @@ public async Task AzureReposProvider_GetCredentialAsync_UnencryptedHttp_ThrowsEx
132
132
var context = new TestCommandContext ( ) ;
133
133
var azDevOps = Mock . Of < IAzureDevOpsRestApi > ( ) ;
134
134
var msAuth = Mock . Of < IMicrosoftAuthentication > ( ) ;
135
+ var authorityCache = Mock . Of < IAzureDevOpsAuthorityCache > ( ) ;
135
136
136
- var provider = new AzureReposHostProvider ( context , azDevOps , msAuth ) ;
137
+ var provider = new AzureReposHostProvider ( context , azDevOps , msAuth , authorityCache ) ;
137
138
138
139
await Assert . ThrowsAsync < Exception > ( ( ) => provider . GetCredentialAsync ( input ) ) ;
139
140
}
140
141
141
142
[ Fact ]
142
- public async Task AzureReposProvider_GetCredentialAsync_JwtMode_VsComUrlUser_ReturnsCredential ( )
143
+ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_CachedAuthority_VsComUrlUser_ReturnsCredential ( )
143
144
{
145
+ var orgName = "org" ;
144
146
var urlAccount = "jane.doe" ;
145
147
146
148
var input = new InputArguments ( new Dictionary < string , string >
@@ -172,7 +174,10 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_VsComUrlUser_Ret
172
174
msAuthMock . Setup ( x => x . GetTokenAsync ( authorityUrl , expectedClientId , expectedRedirectUri , expectedScopes , urlAccount ) )
173
175
. ReturnsAsync ( authResult ) ;
174
176
175
- var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object ) ;
177
+ var authorityCacheMock = new Mock < IAzureDevOpsAuthorityCache > ( MockBehavior . Strict ) ;
178
+ authorityCacheMock . Setup ( x => x . GetAuthority ( orgName ) ) . Returns ( authorityUrl ) ;
179
+
180
+ var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object , authorityCacheMock . Object ) ;
176
181
177
182
ICredential credential = await provider . GetCredentialAsync ( input ) ;
178
183
@@ -182,8 +187,9 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_VsComUrlUser_Ret
182
187
}
183
188
184
189
[ Fact ]
185
- public async Task AzureReposProvider_GetCredentialAsync_JwtMode_DevAzureUrlUser_ReturnsCredential ( )
190
+ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_CachedAuthority_DevAzureUrlUser_ReturnsCredential ( )
186
191
{
192
+ var orgName = "org" ;
187
193
var urlAccount = "jane.doe" ;
188
194
189
195
var input = new InputArguments ( new Dictionary < string , string >
@@ -216,7 +222,10 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_DevAzureUrlUser_
216
222
msAuthMock . Setup ( x => x . GetTokenAsync ( authorityUrl , expectedClientId , expectedRedirectUri , expectedScopes , urlAccount ) )
217
223
. ReturnsAsync ( authResult ) ;
218
224
219
- var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object ) ;
225
+ var authorityCacheMock = new Mock < IAzureDevOpsAuthorityCache > ( MockBehavior . Strict ) ;
226
+ authorityCacheMock . Setup ( x => x . GetAuthority ( orgName ) ) . Returns ( authorityUrl ) ;
227
+
228
+ var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object , authorityCacheMock . Object ) ;
220
229
221
230
ICredential credential = await provider . GetCredentialAsync ( input ) ;
222
231
@@ -226,8 +235,10 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_DevAzureUrlUser_
226
235
}
227
236
228
237
[ Fact ]
229
- public async Task AzureReposProvider_GetCredentialAsync_JwtMode_DevAzureUrlOrgName_ReturnsCredential ( )
238
+ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_CachedAuthority_DevAzureUrlOrgName_ReturnsCredential ( )
230
239
{
240
+ var orgName = "org" ;
241
+
231
242
var input = new InputArguments ( new Dictionary < string , string >
232
243
{
233
244
[ "protocol" ] = "https" ,
@@ -259,7 +270,10 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_DevAzureUrlOrgNa
259
270
msAuthMock . Setup ( x => x . GetTokenAsync ( authorityUrl , expectedClientId , expectedRedirectUri , expectedScopes , null ) )
260
271
. ReturnsAsync ( authResult ) ;
261
272
262
- var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object ) ;
273
+ var authorityCacheMock = new Mock < IAzureDevOpsAuthorityCache > ( MockBehavior . Strict ) ;
274
+ authorityCacheMock . Setup ( x => x . GetAuthority ( orgName ) ) . Returns ( authorityUrl ) ;
275
+
276
+ var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object , authorityCacheMock . Object ) ;
263
277
264
278
ICredential credential = await provider . GetCredentialAsync ( input ) ;
265
279
@@ -269,8 +283,10 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_DevAzureUrlOrgNa
269
283
}
270
284
271
285
[ Fact ]
272
- public async Task AzureReposProvider_GetCredentialAsync_JwtMode_NoUser_ReturnsCredential ( )
286
+ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_NoCachedAuthority_ReturnsCredential ( )
273
287
{
288
+ var orgName = "org" ;
289
+
274
290
var input = new InputArguments ( new Dictionary < string , string >
275
291
{
276
292
[ "protocol" ] = "https" ,
@@ -301,7 +317,11 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_NoUser_ReturnsCr
301
317
msAuthMock . Setup ( x => x . GetTokenAsync ( authorityUrl , expectedClientId , expectedRedirectUri , expectedScopes , null ) )
302
318
. ReturnsAsync ( authResult ) ;
303
319
304
- var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object ) ;
320
+ var authorityCacheMock = new Mock < IAzureDevOpsAuthorityCache > ( MockBehavior . Strict ) ;
321
+ authorityCacheMock . Setup ( x => x . GetAuthority ( It . IsAny < string > ( ) ) ) . Returns ( ( string ) null ) ;
322
+ authorityCacheMock . Setup ( x => x . UpdateAuthority ( orgName , authorityUrl ) ) ;
323
+
324
+ var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object , authorityCacheMock . Object ) ;
305
325
306
326
ICredential credential = await provider . GetCredentialAsync ( input ) ;
307
327
@@ -313,6 +333,8 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_NoUser_ReturnsCr
313
333
[ Fact ]
314
334
public async Task AzureReposProvider_GetCredentialAsync_PatMode_NoExistingPat_GeneratesCredential ( )
315
335
{
336
+ var orgName = "org" ;
337
+
316
338
var input = new InputArguments ( new Dictionary < string , string >
317
339
{
318
340
[ "protocol" ] = "https" ,
@@ -342,7 +364,9 @@ public async Task AzureReposProvider_GetCredentialAsync_PatMode_NoExistingPat_Ge
342
364
msAuthMock . Setup ( x => x . GetTokenAsync ( authorityUrl , expectedClientId , expectedRedirectUri , expectedScopes , null ) )
343
365
. ReturnsAsync ( authResult ) ;
344
366
345
- var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object ) ;
367
+ var authorityCacheMock = new Mock < IAzureDevOpsAuthorityCache > ( MockBehavior . Strict ) ;
368
+
369
+ var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object , authorityCacheMock . Object ) ;
346
370
347
371
ICredential credential = await provider . GetCredentialAsync ( input ) ;
348
372
@@ -372,8 +396,9 @@ public async Task AzureReposProvider_GetCredentialAsync_PatMode_ExistingPat_Retu
372
396
373
397
var azDevOps = Mock . Of < IAzureDevOpsRestApi > ( ) ;
374
398
var msAuth = Mock . Of < IMicrosoftAuthentication > ( ) ;
399
+ var authorityCache = Mock . Of < IAzureDevOpsAuthorityCache > ( ) ;
375
400
376
- var provider = new AzureReposHostProvider ( context , azDevOps , msAuth ) ;
401
+ var provider = new AzureReposHostProvider ( context , azDevOps , msAuth , authorityCache ) ;
377
402
378
403
ICredential credential = await provider . GetCredentialAsync ( input ) ;
379
404
0 commit comments