From d77e5f8b000c78ea28773cac6d5b274ded9ad678 Mon Sep 17 00:00:00 2001 From: Javier Cortejoso Date: Wed, 9 Oct 2024 10:16:09 +0200 Subject: [PATCH] Fix Google URL check --- store/precomputed_key/s3/s3.go | 13 ++++++------ store/precomputed_key/s3/s3_test.go | 31 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 store/precomputed_key/s3/s3_test.go diff --git a/store/precomputed_key/s3/s3.go b/store/precomputed_key/s3/s3.go index eb8db66..f694910 100644 --- a/store/precomputed_key/s3/s3.go +++ b/store/precomputed_key/s3/s3.go @@ -6,8 +6,8 @@ import ( "encoding/hex" "errors" "io" - "net/url" "path" + "strings" "time" "github.com/Layr-Labs/eigenda-proxy/store" @@ -15,7 +15,6 @@ import ( "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" - "github.com/minio/minio-go/v7/pkg/s3utils" ) const ( @@ -58,13 +57,13 @@ type Store struct { stats *store.Stats } +func isGoogleEndpoint(endpoint string) bool { + return strings.Contains(endpoint, "storage.googleapis.com") +} + func NewS3(cfg Config) (*Store, error) { - endpointURL, err := url.Parse(cfg.Endpoint) - if err != nil { - return nil, err - } putObjectOptions := minio.PutObjectOptions{} - if s3utils.IsGoogleEndpoint(*endpointURL) { + if isGoogleEndpoint(cfg.Endpoint) { putObjectOptions.DisableContentSha256 = true // Avoid chunk signatures on GCS: https://github.com/minio/minio-go/issues/1922 } diff --git a/store/precomputed_key/s3/s3_test.go b/store/precomputed_key/s3/s3_test.go new file mode 100644 index 0000000..e30f505 --- /dev/null +++ b/store/precomputed_key/s3/s3_test.go @@ -0,0 +1,31 @@ +package s3 + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIsGoogleEndpoint_StorageGoogleapis(t *testing.T) { + endpoint := "storage.googleapis.com" + result := isGoogleEndpoint(endpoint) + assert.True(t, result, "Expected true for Google Cloud Storage endpoint") +} + +func TestIsGoogleEndpoint_HttpsStorageGoogleapis(t *testing.T) { + endpoint := "https://storage.googleapis.com" + result := isGoogleEndpoint(endpoint) + assert.True(t, result, "Expected true for Google Cloud Storage endpoint") +} + +func TestIsGoogleEndpoint_False(t *testing.T) { + endpoint := "https://s3.amazonaws.com/my-bucket" + result := isGoogleEndpoint(endpoint) + assert.False(t, result, "Expected false for non-Google endpoint") +} + +func TestIsGoogleEndpoint_Empty(t *testing.T) { + endpoint := "" + result := isGoogleEndpoint(endpoint) + assert.False(t, result, "Expected false for empty endpoint") +}