Skip to content
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
3 changes: 2 additions & 1 deletion cli/config/credentials/file_store.go
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
package credentials

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

Expand DownExpand 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 numberDiff line numberDiff 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 DownExpand 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