mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-01-06 13:36:54 +00:00
don't change public signature of endpointaddr.Parse()
This commit is contained in:
@@ -42,7 +42,7 @@ func (h *HostPort) Endpoint() string {
|
||||
// - "[<IPv6>]:<port>" (IPv6 address with port, brackets are required)
|
||||
//
|
||||
// If the input does not specify a port number, then defaultPort will be used.
|
||||
func Parse(endpoint string, defaultPort uint16, paths ...string) (HostPort, error) {
|
||||
func Parse(endpoint string, defaultPort uint16) (HostPort, error) {
|
||||
// Try parsing it both with and without an implicit port 443 at the end.
|
||||
host, port, err := net.SplitHostPort(endpoint)
|
||||
|
||||
@@ -62,13 +62,9 @@ func Parse(endpoint string, defaultPort uint16, paths ...string) (HostPort, erro
|
||||
return HostPort{}, fmt.Errorf("invalid port %q", port)
|
||||
}
|
||||
|
||||
if len(paths) < 1 {
|
||||
paths = []string{"UNKNOWN_PATH"}
|
||||
}
|
||||
|
||||
// Check if the host part is a IPv4 or IPv6 address or a valid hostname according to RFC 1123.
|
||||
switch {
|
||||
case len(validation.IsValidIP(field.NewPath(paths[0], paths[1:]...), host)) == 0:
|
||||
case len(validation.IsValidIP(field.NewPath("UNKNOWN_PATH"), host)) == 0:
|
||||
case len(validation.IsDNS1123Subdomain(host)) == 0:
|
||||
default:
|
||||
return HostPort{}, fmt.Errorf("host %q is not a valid hostname or IP address", host)
|
||||
|
||||
@@ -17,7 +17,6 @@ func TestParse(t *testing.T) {
|
||||
name string
|
||||
input string
|
||||
defaultPort uint16
|
||||
paths []string
|
||||
expectErr string
|
||||
expect HostPort
|
||||
expectEndpoint string
|
||||
@@ -47,7 +46,6 @@ func TestParse(t *testing.T) {
|
||||
name: "invalid IPv4",
|
||||
input: "1.1.1.",
|
||||
defaultPort: 443,
|
||||
paths: []string{"does", "not", "matter", "because", "this", "error", "is", "ignored"},
|
||||
expectErr: `host "1.1.1." is not a valid hostname or IP address`,
|
||||
},
|
||||
{
|
||||
@@ -178,7 +176,7 @@ func TestParse(t *testing.T) {
|
||||
} {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := Parse(tt.input, tt.defaultPort, tt.paths...)
|
||||
got, err := Parse(tt.input, tt.defaultPort)
|
||||
if tt.expectErr == "" {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.expect, got)
|
||||
|
||||
Reference in New Issue
Block a user