From 12ab89ba3e850f12ae12a145cfb1240b97d9380c Mon Sep 17 00:00:00 2001 From: M Hickford Date: Thu, 19 Oct 2023 18:33:54 +0100 Subject: [PATCH] recognise BitBucket hosts by WWW-Authenticate header Tested with https://bitbucket.hl7.org --- .../BitbucketHostProviderTest.cs | 14 ++++++++++++++ .../Atlassian.Bitbucket/BitbucketHostProvider.cs | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/shared/Atlassian.Bitbucket.Tests/BitbucketHostProviderTest.cs b/src/shared/Atlassian.Bitbucket.Tests/BitbucketHostProviderTest.cs index 4e277d0f3..36b116615 100644 --- a/src/shared/Atlassian.Bitbucket.Tests/BitbucketHostProviderTest.cs +++ b/src/shared/Atlassian.Bitbucket.Tests/BitbucketHostProviderTest.cs @@ -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 + { + ["wwwauth"] = wwwauth, + }); + + var provider = new BitbucketHostProvider(new TestCommandContext()); + Assert.Equal(expected, provider.IsSupported(input)); + } + [Fact] public void BitbucketHostProvider_IsSupported_FailsForNullInput() { diff --git a/src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs b/src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs index f3f653f01..35472682c 100644 --- a/src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs +++ b/src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs @@ -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; @@ -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 _)) {