Skip to content

Commit

Permalink
Merge pull request #5198 from thaJeztah/27.0_backport_carry_fix_custo…
Browse files Browse the repository at this point in the history
…m_ports
  • Loading branch information
laurazard committed Jun 26, 2024
2 parents 37533c2 + 50fae20 commit 9a101a9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cli/config/credentials/file_store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package credentials

import (
"net"
"net/url"
"strings"

Expand Down Expand Up @@ -77,7 +78,7 @@ func ConvertToHostname(maybeURL string) string {
if u.Port() == "" {
return u.Hostname()
}
return u.Hostname() + ":" + u.Port()
return net.JoinHostPort(u.Hostname(), u.Port())
}
}
hostName, _, _ := strings.Cut(stripped, "/")
Expand Down
38 changes: 38 additions & 0 deletions cli/config/credentials/file_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ func TestFileStoreErase(t *testing.T) {

func TestConvertToHostname(t *testing.T) {
tests := []struct{ input, expected string }{
{
input: "127.0.0.1",
expected: "127.0.0.1",
},
{
input: "::1",
expected: "::1",
},
{
// FIXME(thaJeztah): this should be normalized to "::1" if there's no port (or vice-versa, as long as we're consistent)
input: "[::1]",
expected: "[::1]",
},
{
input: "example.com",
expected: "example.com",
Expand Down Expand Up @@ -168,10 +181,35 @@ func TestConvertToHostname(t *testing.T) {
expected: "example.com",
},
// should support non-standard port in registry url
{
input: "127.0.0.1:6556",
expected: "127.0.0.1:6556",
},
{
// FIXME(thaJeztah): this should be normalized to "[::1]:6556"
input: "::1:6556",
expected: "::1:6556",
},
{
input: "[::1]:6556",
expected: "[::1]:6556",
},
{
input: "example.com:6555",
expected: "example.com:6555",
},
{
input: "https://127.0.0.1:6555/v2/",
expected: "127.0.0.1:6555",
},
{
input: "https://::1:6555/v2/",
expected: "[::1]:6555",
},
{
input: "https://[::1]:6555/v2/",
expected: "[::1]:6555",
},
{
input: "http://example.com:6555",
expected: "example.com:6555",
Expand Down

0 comments on commit 9a101a9

Please sign in to comment.