1
0
Форкнуть 0

Merge pull request #727 from Foda/BBOauthBackmerge_1.6

bitbucket: Backmerge 1.17 oauth fix to 1.16
This commit is contained in:
J Wyman 2018-08-10 15:12:35 -04:00 коммит произвёл GitHub
Родитель c03cb812db 185ef99f87
Коммит 47e32db899
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 47 добавлений и 10 удалений

Просмотреть файл

@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Atlassian.Bitbucket.Authentication.BasicAuth;
using Atlassian.Bitbucket.Authentication.Rest;
using Microsoft.Alm.Authentication;
using Moq;
using Xunit;
@ -573,6 +575,43 @@ namespace Atlassian.Bitbucket.Authentication.Test
}
[Fact]
public async void VerifyGetUserFromRestTargetsValidURL()
{
var expectedUri = new TargetUri("https://api.bitbucket.org/2.0/user");
var storage = new Mock<IStorage>();
var trace = new Mock<Microsoft.Alm.Authentication.Git.ITrace>();
var gitWhere = new Mock<Microsoft.Alm.Authentication.Git.IWhere>();
var network = new Mock<INetwork>();
network
.Setup(a => a.HttpGetAsync(It.IsAny<TargetUri>(), It.IsAny<NetworkRequestOptions>()))
.Returns(Task.FromResult<HttpResponseMessage>(new HttpResponseMessage(HttpStatusCode.Unauthorized)));
network
.Setup(a => a.HttpGetAsync(expectedUri, It.IsAny<NetworkRequestOptions>()))
.Returns(Task.FromResult<HttpResponseMessage>(new HttpResponseMessage(HttpStatusCode.Unauthorized)));
network
.Setup(a => a.HttpGetAsync(It.IsAny<TargetUri>()))
.Returns(Task.FromResult<HttpResponseMessage>(new HttpResponseMessage(HttpStatusCode.Unauthorized)));
var restClient = new RestClient(
new RuntimeContext(storage.Object, network.Object, trace.Object, gitWhere.Object));
var user = await restClient.TryGetUser(
new TargetUri($"https://{_validUsername}@bitbucket.org/"),
42,
new Uri("https://api.bitbucket.org/"),
new Credential(_validUsername, _validPassword));
// Verify we got the same string result
network.Verify(a => a.HttpGetAsync(
It.Is<TargetUri>((uri) => uri.ToString() == expectedUri.ToString()),
It.IsAny<NetworkRequestOptions>()), Times.Once);
}
private bool MockValidAquireAuthenticationOAuthCallback(string title, TargetUri targetUri, AuthenticationResultType resultType, string username)
{
return true;

Просмотреть файл

@ -29,6 +29,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>

Просмотреть файл

@ -166,7 +166,7 @@ namespace Atlassian.Bitbucket.Authentication
}
// If the basic authentication test failed then try again as OAuth
if (await ValidateCredentials(targetUri, new Token(credentials.Password, TokenType.BitbucketPassword)))
if (await ValidateCredentials(targetUri, new Token(credentials.Password, TokenType.BitbucketAccess)))
{
return true;
}

Просмотреть файл

@ -26,7 +26,9 @@ namespace Atlassian.Bitbucket.Authentication.Rest
Authorization = authorization,
Timeout = TimeSpan.FromMilliseconds(requestTimeout),
};
var requestUri = new TargetUri(restRootUrl, targetUri.ProxyUri);
var apiUrl = new Uri(restRootUrl, UserUrl);
var requestUri = new TargetUri(apiUrl, targetUri.ProxyUri);
using (var response = await Network.HttpGetAsync(requestUri, options))
{

Просмотреть файл

@ -440,6 +440,7 @@ namespace Microsoft.Alm.Authentication
switch (token.Type)
{
case TokenType.AzureAccess:
case TokenType.BitbucketAccess:
{
// ADAL access tokens are packed into the Authorization header.
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Value);

Просмотреть файл

@ -60,22 +60,16 @@ namespace Microsoft.Alm.Authentication
[System.ComponentModel.Description("Test-only Token")]
Test = 5,
/// <summary>
/// Bitbucket Password Tokens.
/// </summary>
[System.ComponentModel.Description("Bitbucket Password Token")]
BitbucketPassword = 6,
/// <summary>
/// Bitbucket Access Tokens.
/// </summary>
[System.ComponentModel.Description("Bitbucket Access Token")]
BitbucketAccess = 7,
BitbucketAccess = 6,
/// <summary>
/// Used to auto-refresh Bitbucket Access Tokens.
/// </summary>
[System.ComponentModel.Description("Bitbucket Refresh Token")]
BitbucketRefresh = 8,
BitbucketRefresh = 7,
}
}