Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IPv6 url without 80/443 port #1636

Merged
merged 1 commit into from Apr 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 3 additions & 12 deletions utils.go
Expand Up @@ -161,27 +161,18 @@ func isValidEndpointURL(endpointURL url.URL) error {
if endpointURL.Path != "/" && endpointURL.Path != "" {
return errInvalidArgument("Endpoint url cannot have fully qualified paths.")
}

host, _, err := net.SplitHostPort(endpointURL.Host)
if err != nil {
if strings.Contains(err.Error(), "missing port in address") {
err = nil
host = endpointURL.Host
} else {
return err
}
}
host := endpointURL.Hostname()
if !s3utils.IsValidIP(host) && !s3utils.IsValidDomain(host) {
msg := "Endpoint: " + endpointURL.Host + " does not follow ip address or domain name standards."
return errInvalidArgument(msg)
}

if strings.Contains(endpointURL.Host, ".s3.amazonaws.com") {
if strings.Contains(host, ".s3.amazonaws.com") {
if !s3utils.IsAmazonEndpoint(endpointURL) {
return errInvalidArgument("Amazon S3 endpoint should be 's3.amazonaws.com'.")
}
}
if strings.Contains(endpointURL.Host, ".googleapis.com") {
if strings.Contains(host, ".googleapis.com") {
if !s3utils.IsGoogleEndpoint(endpointURL) {
return errInvalidArgument("Google Cloud Storage endpoint should be 'storage.googleapis.com'.")
}
Expand Down
6 changes: 6 additions & 0 deletions utils_test.go
Expand Up @@ -113,6 +113,12 @@ func TestGetEndpointURL(t *testing.T) {
{"192.168.1.1:9000", false, "http://192.168.1.1:9000", nil, true},
{"192.168.1.1:9000", true, "https://192.168.1.1:9000", nil, true},
{"s3.amazonaws.com:443", true, "https://s3.amazonaws.com:443", nil, true},
{"[::1]", false, "http://[::1]", nil, true},
{"[::1]", true, "https://[::1]", nil, true},
{"[::1]:80", false, "http://[::1]:80", nil, true},
{"[::1]:443", true, "https://[::1]:443", nil, true},
{"[::1]:9000", false, "http://[::1]:9000", nil, true},
{"[::1]:9000", true, "https://[::1]:9000", nil, true},
{"13333.123123.-", true, "", errInvalidArgument(fmt.Sprintf("Endpoint: %s does not follow ip address or domain name standards.", "13333.123123.-")), false},
{"13333.123123.-", true, "", errInvalidArgument(fmt.Sprintf("Endpoint: %s does not follow ip address or domain name standards.", "13333.123123.-")), false},
{"storage.googleapis.com:4000", true, "", errInvalidArgument("Google Cloud Storage endpoint should be 'storage.googleapis.com'."), false},
Expand Down