Skip to content

Commit a428198

Browse files
fix: GCS endpoint validation to allow ports (#1985)
1 parent 6c2c69f commit a428198

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

pkg/s3utils/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func IsGoogleEndpoint(endpointURL url.URL) bool {
226226
if endpointURL == sentinelURL {
227227
return false
228228
}
229-
return endpointURL.Host == "storage.googleapis.com"
229+
return endpointURL.Hostname() == "storage.googleapis.com"
230230
}
231231

232232
// Expects ascii encoded strings - from output of urlEncodePath

pkg/s3utils/utils_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ func TestIsGoogleEndpoint(t *testing.T) {
284284
// valid inputs.
285285
{"http://storage.googleapis.com", true},
286286
{"https://storage.googleapis.com", true},
287+
{"http://storage.googleapis.com:80", true},
288+
{"https://storage.googleapis.com:443", true},
287289
}
288290

289291
for i, testCase := range testCases {

utils_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func TestGetEndpointURL(t *testing.T) {
114114
{"192.168.1.1:9000", false, "http://192.168.1.1:9000", nil, true},
115115
{"192.168.1.1:9000", true, "https://192.168.1.1:9000", nil, true},
116116
{"s3.amazonaws.com:443", true, "https://s3.amazonaws.com:443", nil, true},
117+
{"storage.googleapis.com:443", true, "https://storage.googleapis.com:443", nil, true},
117118
{"[::1]", false, "http://[::1]", nil, true},
118119
{"[::1]", true, "https://[::1]", nil, true},
119120
{"[::1]:80", false, "http://[::1]:80", nil, true},
@@ -122,7 +123,6 @@ func TestGetEndpointURL(t *testing.T) {
122123
{"[::1]:9000", true, "https://[::1]:9000", nil, true},
123124
{"13333.123123.-", true, "", errInvalidArgument(fmt.Sprintf("Endpoint: %s does not follow ip address or domain name standards.", "13333.123123.-")), false},
124125
{"13333.123123.-", true, "", errInvalidArgument(fmt.Sprintf("Endpoint: %s does not follow ip address or domain name standards.", "13333.123123.-")), false},
125-
{"storage.googleapis.com:4000", true, "", errInvalidArgument("Google Cloud Storage endpoint should be 'storage.googleapis.com'."), false},
126126
{"s3.aamzza.-", true, "", errInvalidArgument(fmt.Sprintf("Endpoint: %s does not follow ip address or domain name standards.", "s3.aamzza.-")), false},
127127
{"", true, "", errInvalidArgument("Endpoint: does not follow ip address or domain name standards."), false},
128128
}

0 commit comments

Comments
 (0)