@@ -239,17 +239,14 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_CachedAuthority_
239
239
[ Fact ]
240
240
public async Task AzureReposProvider_GetCredentialAsync_JwtMode_CachedAuthority_DevAzureUrlOrgName_ReturnsCredential ( )
241
241
{
242
-
243
242
var input = new InputArguments ( new Dictionary < string , string >
244
243
{
245
244
[ "protocol" ] = "https" ,
246
245
[ "host" ] = "dev.azure.com" ,
247
- [ "path" ] = "org/project/_git/repo" ,
248
246
[ "username" ] = "org"
249
247
} ) ;
250
248
251
249
var expectedOrgUri = new Uri ( "https://dev.azure.com/org" ) ;
252
- var remoteUri = new Uri ( "https://dev.azure.com/org/project/_git/repo" ) ;
253
250
var authorityUrl = "https://login.microsoftonline.com/common" ;
254
251
var expectedClientId = AzureDevOpsConstants . AadClientId ;
255
252
var expectedRedirectUri = AzureDevOpsConstants . AadRedirectUri ;
@@ -385,7 +382,6 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_CachedAuthority_
385
382
[ Fact ]
386
383
public async Task AzureReposProvider_GetCredentialAsync_JwtMode_NoCachedAuthority_NoUser_ReturnsCredential ( )
387
384
{
388
-
389
385
var input = new InputArguments ( new Dictionary < string , string >
390
386
{
391
387
[ "protocol" ] = "https" ,
@@ -433,9 +429,52 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_NoCachedAuthorit
433
429
}
434
430
435
431
[ Fact ]
436
- public async Task AzureReposProvider_GetCredentialAsync_PatMode_NoExistingPat_GeneratesCredential ( )
432
+ public async Task AzureReposProvider_GetCredentialAsync_PatMode_OrgInUserName_NoExistingPat_GeneratesCredential ( )
437
433
{
434
+ var input = new InputArguments ( new Dictionary < string , string >
435
+ {
436
+ [ "protocol" ] = "https" ,
437
+ [ "host" ] = "dev.azure.com" ,
438
+ [ "username" ] = "org"
439
+ } ) ;
440
+
441
+ var expectedOrgUri = new Uri ( "https://dev.azure.com/org" ) ;
442
+ var authorityUrl = "https://login.microsoftonline.com/common" ;
443
+ var expectedClientId = AzureDevOpsConstants . AadClientId ;
444
+ var expectedRedirectUri = AzureDevOpsConstants . AadRedirectUri ;
445
+ var expectedScopes = AzureDevOpsConstants . AzureDevOpsDefaultScopes ;
446
+ var accessToken = "ACCESS-TOKEN" ;
447
+ var personalAccessToken = "PERSONAL-ACCESS-TOKEN" ;
448
+ var account = "john.doe" ;
449
+ var authResult = CreateAuthResult ( account , accessToken ) ;
450
+
451
+ var context = new TestCommandContext ( ) ;
452
+
453
+ var azDevOpsMock = new Mock < IAzureDevOpsRestApi > ( MockBehavior . Strict ) ;
454
+ azDevOpsMock . Setup ( x => x . GetAuthorityAsync ( expectedOrgUri ) ) . ReturnsAsync ( authorityUrl ) ;
455
+ azDevOpsMock . Setup ( x => x . CreatePersonalAccessTokenAsync ( expectedOrgUri , accessToken , It . IsAny < IEnumerable < string > > ( ) ) )
456
+ . ReturnsAsync ( personalAccessToken ) ;
457
+
458
+ var msAuthMock = new Mock < IMicrosoftAuthentication > ( MockBehavior . Strict ) ;
459
+ msAuthMock . Setup ( x => x . GetTokenForUserAsync ( authorityUrl , expectedClientId , expectedRedirectUri , expectedScopes , null , true ) )
460
+ . ReturnsAsync ( authResult ) ;
461
+
462
+ var authorityCacheMock = new Mock < IAzureDevOpsAuthorityCache > ( MockBehavior . Strict ) ;
463
+
464
+ var userMgrMock = new Mock < IAzureReposBindingManager > ( MockBehavior . Strict ) ;
438
465
466
+ var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object , authorityCacheMock . Object , userMgrMock . Object ) ;
467
+
468
+ ICredential credential = await provider . GetCredentialAsync ( input ) ;
469
+
470
+ Assert . NotNull ( credential ) ;
471
+ Assert . Equal ( account , credential . Account ) ;
472
+ Assert . Equal ( personalAccessToken , credential . Password ) ;
473
+ }
474
+
475
+ [ Fact ]
476
+ public async Task AzureReposProvider_GetCredentialAsync_PatMode_NoExistingPat_GeneratesCredential ( )
477
+ {
439
478
var input = new InputArguments ( new Dictionary < string , string >
440
479
{
441
480
[ "protocol" ] = "https" ,
0 commit comments