diff --git a/internal/urlutil/urlutil.go b/internal/urlutil/urlutil.go index db482510d..02d263940 100644 --- a/internal/urlutil/urlutil.go +++ b/internal/urlutil/urlutil.go @@ -77,5 +77,19 @@ func SchemeHostAndPortMatches(u1, u2 *url.URL) bool { // Host on URL (returned from url.Parse) contains the port if present. // This check ensures credentials are not passed between different // services on different ports. - return u1.Scheme == u2.Scheme && u1.Host == u2.Host + getPort := func(url *url.URL) string { + if url.Port() == "" { + if url.Scheme == "https" { // is always lower case + return "443" + } + + if url.Scheme == "http" { + return "80" + } + } + return url.Port() + } + u1Port := getPort(u1) + u2Port := getPort(u2) + return u1.Scheme == u2.Scheme && u1.Hostname() == u2.Hostname() && u1Port == u2Port } diff --git a/internal/urlutil/urlutil_test.go b/internal/urlutil/urlutil_test.go index 56e4376b6..7e07c40ac 100644 --- a/internal/urlutil/urlutil_test.go +++ b/internal/urlutil/urlutil_test.go @@ -55,11 +55,12 @@ func TestSchemeHostAndPortMatches(t *testing.T) { {"https://example.com:443", "https://example.com:443", true}, {"http://example.com:1234", "http://example.com:5678", false}, {"https://example.com:1234", "https://example.com:5678", false}, - // The following lines are subject of change, currently only there - // to ensure that the existing logic works as expected and the - // upcoming fix / improvement works as wanted - {"http://example.com:80", "http://example.com", false}, - {"https://example.com:443", "https://example.com", false}, + {"http://example.com:80", "http://example.com", true}, + {"https://example.com:443", "https://example.com", true}, + {"http://example.com:80", "https://example.com", false}, + {"https://example.com:443", "http://example.com", false}, + {"http://example.com:1234", "http://example.com", false}, + {"https://example.com:1234", "https://example.com", false}, } { u1, _ := url.Parse(tt.a) u2, _ := url.Parse(tt.b)