Skip to content

Commit

Permalink
fix: Fixed the endpoint validation issue for GCS if port number is ad…
Browse files Browse the repository at this point in the history
…ded to the URL
  • Loading branch information
Ammar Husain Huk committed Jul 10, 2024
1 parent 5d99621 commit 11b4512
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/s3utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

// Sentinel URL is the default url value which is invalid.
var sentinelURL = url.URL{}
var host string

// IsValidDomain validates if input string is a valid domain name.
func IsValidDomain(host string) bool {
Expand Down Expand Up @@ -223,10 +224,11 @@ func IsAmazonPrivateLinkEndpoint(endpointURL url.URL) bool {

// IsGoogleEndpoint - Match if it is exactly Google cloud storage endpoint.
func IsGoogleEndpoint(endpointURL url.URL) bool {
host := HasPortNumber(endpointURL)
if endpointURL == sentinelURL {
return false
}
return endpointURL.Host == "storage.googleapis.com"
return host == "storage.googleapis.com"
}

// Expects ascii encoded strings - from output of urlEncodePath
Expand Down Expand Up @@ -409,3 +411,13 @@ func CheckValidObjectName(objectName string) error {
}
return CheckValidObjectNamePrefix(objectName)
}

//checks for port number
func HasPortNumber(endpointURL url.URL) string {
if colonIndex := strings.LastIndex(endpointURL.Host, ":"); colonIndex != -1 {
host = endpointURL.Host[:colonIndex]
} else {
host = endpointURL.Host
}
return host
}
2 changes: 2 additions & 0 deletions pkg/s3utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 11b4512

Please sign in to comment.