Skip to content

Commit 12ab89b

Browse files
committed
recognise BitBucket hosts by WWW-Authenticate header
Tested with https://bitbucket.hl7.org
1 parent ac0b264 commit 12ab89b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/shared/Atlassian.Bitbucket.Tests/BitbucketHostProviderTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public void BitbucketHostProvider_IsSupported(string protocol, string host, bool
5555
Assert.Equal(expected, provider.IsSupported(input));
5656
}
5757

58+
[Theory]
59+
[InlineData("Basic realm=\"Atlassian Bitbucket\"", true)]
60+
[InlineData("Basic realm=\"GitSponge\"", false)]
61+
public void BitbucketHostProvider_IsSupported_WWWAuth(string wwwauth, bool expected)
62+
{
63+
var input = new InputArguments(new Dictionary<string, string>
64+
{
65+
["wwwauth"] = wwwauth,
66+
});
67+
68+
var provider = new BitbucketHostProvider(new TestCommandContext());
69+
Assert.Equal(expected, provider.IsSupported(input));
70+
}
71+
5872
[Fact]
5973
public void BitbucketHostProvider_IsSupported_FailsForNullInput()
6074
{

src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Net.Http;
45
using System.Threading.Tasks;
56
using Atlassian.Bitbucket.Cloud;
@@ -43,6 +44,11 @@ public bool IsSupported(InputArguments input)
4344
return false;
4445
}
4546

47+
if (input.WwwAuth.Any(x => x.Contains("realm=\"Atlassian Bitbucket\"", StringComparison.InvariantCultureIgnoreCase)))
48+
{
49+
return true;
50+
}
51+
4652
// Split port number and hostname from host input argument
4753
if (!input.TryGetHostAndPort(out string hostName, out _))
4854
{

0 commit comments

Comments
 (0)