|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Linq;
|
4 | 4 | using System.Net;
|
| 5 | +using System.Net.Http; |
5 | 6 | using System.Threading.Tasks;
|
6 | 7 | using Atlassian.Bitbucket.Authentication.BasicAuth;
|
| 8 | +using Atlassian.Bitbucket.Authentication.Rest; |
7 | 9 | using Microsoft.Alm.Authentication;
|
8 | 10 | using Moq;
|
9 | 11 | using Xunit;
|
@@ -573,6 +575,43 @@ public async void VerifyInteractiveLoginAquiresAndStoresValidOAuthCredentials()
|
573 | 575 |
|
574 | 576 | }
|
575 | 577 |
|
| 578 | + [Fact] |
| 579 | + public async void VerifyGetUserFromRestTargetsValidURL() |
| 580 | + { |
| 581 | + var expectedUri = new TargetUri("https://api.bitbucket.org/2.0/user"); |
| 582 | + |
| 583 | + var storage = new Mock<IStorage>(); |
| 584 | + var trace = new Mock<Microsoft.Alm.Authentication.Git.ITrace>(); |
| 585 | + var gitWhere = new Mock<Microsoft.Alm.Authentication.Git.IWhere>(); |
| 586 | + |
| 587 | + var network = new Mock<INetwork>(); |
| 588 | + network |
| 589 | + .Setup(a => a.HttpGetAsync(It.IsAny<TargetUri>(), It.IsAny<NetworkRequestOptions>())) |
| 590 | + .Returns(Task.FromResult<HttpResponseMessage>(new HttpResponseMessage(HttpStatusCode.Unauthorized))); |
| 591 | + |
| 592 | + network |
| 593 | + .Setup(a => a.HttpGetAsync(expectedUri, It.IsAny<NetworkRequestOptions>())) |
| 594 | + .Returns(Task.FromResult<HttpResponseMessage>(new HttpResponseMessage(HttpStatusCode.Unauthorized))); |
| 595 | + |
| 596 | + network |
| 597 | + .Setup(a => a.HttpGetAsync(It.IsAny<TargetUri>())) |
| 598 | + .Returns(Task.FromResult<HttpResponseMessage>(new HttpResponseMessage(HttpStatusCode.Unauthorized))); |
| 599 | + |
| 600 | + var restClient = new RestClient( |
| 601 | + new RuntimeContext(storage.Object, network.Object, trace.Object, gitWhere.Object)); |
| 602 | + |
| 603 | + var user = await restClient.TryGetUser( |
| 604 | + new TargetUri($"https://{_validUsername}@bitbucket.org/"), |
| 605 | + 42, |
| 606 | + new Uri("https://api.bitbucket.org/"), |
| 607 | + new Credential(_validUsername, _validPassword)); |
| 608 | + |
| 609 | + // Verify we got the same string result |
| 610 | + network.Verify(a => a.HttpGetAsync( |
| 611 | + It.Is<TargetUri>((uri) => uri.ToString() == expectedUri.ToString()), |
| 612 | + It.IsAny<NetworkRequestOptions>()), Times.Once); |
| 613 | + } |
| 614 | + |
576 | 615 | private bool MockValidAquireAuthenticationOAuthCallback(string title, TargetUri targetUri, AuthenticationResultType resultType, string username)
|
577 | 616 | {
|
578 | 617 | return true;
|
|
0 commit comments