From 580bd229f6ef74811d4649e876a141ec75e915cd Mon Sep 17 00:00:00 2001 From: Ammar Husain Huk Date: Wed, 10 Jul 2024 22:41:50 +0530 Subject: [PATCH 1/2] fix: Fixed the endpoint validation issue for GCS if port number is added to the URL --- pkg/s3utils/utils.go | 2 +- pkg/s3utils/utils_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/s3utils/utils.go b/pkg/s3utils/utils.go index 056e78a67a..0e63ce2f7d 100644 --- a/pkg/s3utils/utils.go +++ b/pkg/s3utils/utils.go @@ -226,7 +226,7 @@ func IsGoogleEndpoint(endpointURL url.URL) bool { if endpointURL == sentinelURL { return false } - return endpointURL.Host == "storage.googleapis.com" + return endpointURL.Hostname() == "storage.googleapis.com" } // Expects ascii encoded strings - from output of urlEncodePath diff --git a/pkg/s3utils/utils_test.go b/pkg/s3utils/utils_test.go index f99738ba9a..9d545f4b9e 100644 --- a/pkg/s3utils/utils_test.go +++ b/pkg/s3utils/utils_test.go @@ -284,6 +284,8 @@ func TestIsGoogleEndpoint(t *testing.T) { // valid inputs. {"http://storage.googleapis.com", true}, {"https://storage.googleapis.com", true}, + {"http://storage.googleapis.com:80", true}, + {"https://storage.googleapis.com:443", true}, } for i, testCase := range testCases { From 117537457084ef12cfc99d8d98beaa5fd7ddf396 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 15 Jul 2024 15:31:10 -0700 Subject: [PATCH 2/2] fix: test --- utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils_test.go b/utils_test.go index 117fdbb15a..0e2ed08b44 100644 --- a/utils_test.go +++ b/utils_test.go @@ -114,6 +114,7 @@ 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}, + {"storage.googleapis.com:443", true, "https://storage.googleapis.com:443", nil, true}, {"[::1]", false, "http://[::1]", nil, true}, {"[::1]", true, "https://[::1]", nil, true}, {"[::1]:80", false, "http://[::1]:80", nil, true}, @@ -122,7 +123,6 @@ func TestGetEndpointURL(t *testing.T) { {"[::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}, {"s3.aamzza.-", true, "", errInvalidArgument(fmt.Sprintf("Endpoint: %s does not follow ip address or domain name standards.", "s3.aamzza.-")), false}, {"", true, "", errInvalidArgument("Endpoint: does not follow ip address or domain name standards."), false}, }