@@ -471,6 +471,46 @@ public async void VerifyInteractiveLoginDoesNotAquireInvalidBasicAuthCredentials
471
471
credentialStore . Verify ( c => c . WriteCredentials ( It . IsAny < TargetUri > ( ) , It . IsAny < Credential > ( ) ) , Times . Never ) ;
472
472
}
473
473
474
+ [ Fact ]
475
+ public async void VerifyInteractiveLoginDoesNotAquireInvalidBasicAuthCredentialsWithUsername ( )
476
+ {
477
+ var bitbucketUrl = "https://bitbucket.org" ;
478
+ var credentialStore = new Mock < ICredentialStore > ( ) ;
479
+
480
+ // mock the result that normally causes issues
481
+ var validAuthenticationResult = new AuthenticationResult ( AuthenticationResultType . Success )
482
+ {
483
+ Token = new Token ( _validPassword , TokenType . Personal ) ,
484
+ RemoteUsername = _validUsername
485
+ } ;
486
+
487
+ var targetUri = new TargetUri ( bitbucketUrl ) ;
488
+
489
+ // Mock the behaviour of IAuthority.AcquireToken() to basically mimic BasicAuthAuthenticator.GetAuthAsync() validating the useername/password
490
+ var authority = new Mock < IAuthority > ( ) ;
491
+ authority
492
+ . Setup ( a => a . AcquireToken ( It . IsAny < TargetUri > ( ) , It . IsAny < Credential > ( ) , It . IsAny < AuthenticationResultType > ( ) , It . IsAny < TokenScope > ( ) ) )
493
+ // return 'success' with the validated credentials
494
+ . Returns ( Task . FromResult ( validAuthenticationResult ) ) ;
495
+
496
+ var bbAuth = new Authentication ( RuntimeContext . Default , credentialStore . Object ,
497
+ MockInvalidBasicAuthCredentialsAquireCredentialsCallback , MockValidAquireAuthenticationOAuthCallback , authority . Object ) ;
498
+
499
+ // perform login with username
500
+ var credentials = await bbAuth . InteractiveLogon ( targetUri , _validUsername ) ;
501
+
502
+ Assert . NotNull ( credentials ) ;
503
+ Assert . Equal ( _validUsername , credentials . Username ) ;
504
+ Assert . Equal ( _validPassword , credentials . Password ) ;
505
+
506
+ // attempted to validate credentials
507
+ authority . Verify ( a => a . AcquireToken ( It . IsAny < TargetUri > ( ) , It . IsAny < Credential > ( ) , It . IsAny < AuthenticationResultType > ( ) ,
508
+ It . IsAny < TokenScope > ( ) ) , Times . Once ) ;
509
+
510
+ // must have a valid attempt to store the valid credentials
511
+ credentialStore . Verify ( c => c . WriteCredentials ( It . IsAny < TargetUri > ( ) , credentials ) , Times . Once ) ;
512
+ }
513
+
474
514
[ Fact ]
475
515
public async void VerifyInteractiveLoginDoesNothingIfUserDoesNotEnterCredentials ( )
476
516
{
0 commit comments