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