Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recognise BitBucket hosts by WWW-Authenticate header #1441

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/shared/Atlassian.Bitbucket.Tests/BitbucketHostProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ public void BitbucketHostProvider_IsSupported(string protocol, string host, bool
Assert.Equal(expected, provider.IsSupported(input));
}

[Theory]
[InlineData("Basic realm=\"Atlassian Bitbucket\"", true)]
[InlineData("Basic realm=\"GitSponge\"", false)]
public void BitbucketHostProvider_IsSupported_WWWAuth(string wwwauth, bool expected)
{
var input = new InputArguments(new Dictionary<string, string>
{
["wwwauth"] = wwwauth,
});

var provider = new BitbucketHostProvider(new TestCommandContext());
Assert.Equal(expected, provider.IsSupported(input));
}

[Fact]
public void BitbucketHostProvider_IsSupported_FailsForNullInput()
{
Expand Down
6 changes: 6 additions & 0 deletions src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Atlassian.Bitbucket.Cloud;
Expand Down Expand Up @@ -43,6 +44,11 @@ public bool IsSupported(InputArguments input)
return false;
}

if (input.WwwAuth.Any(x => x.Contains("realm=\"Atlassian Bitbucket\"", StringComparison.InvariantCultureIgnoreCase)))
{
return true;
}

// Split port number and hostname from host input argument
if (!input.TryGetHostAndPort(out string hostName, out _))
{
Expand Down