From ffc9803e1cdc1a5425b28eb3b51c0b84ef675746 Mon Sep 17 00:00:00 2001 From: Jason Del Ponte Date: Wed, 16 Sep 2015 09:40:53 -0700 Subject: [PATCH] service/s3: GetBucketLocation should use path style for cross region buckets Fixes GetBucketLocation to always use path style URL so that buckets which exist in different regions than the service client is configured for will work. Fix #380 --- service/s3/host_style_bucket.go | 6 ++++++ service/s3/host_style_bucket_test.go | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/service/s3/host_style_bucket.go b/service/s3/host_style_bucket.go index 82ced88b396..47c8495e87f 100644 --- a/service/s3/host_style_bucket.go +++ b/service/s3/host_style_bucket.go @@ -34,6 +34,12 @@ func hostStyleBucketName(r *request.Request, bucket string) bool { return false } + // GetBucketLocation should be able to be called from any region within + // a partition, and return the associated region of the bucket. + if r.Operation.Name == opGetBucketLocation { + return false + } + // Use host-style if the bucket is DNS compatible return dnsCompatibleBucketName(bucket) } diff --git a/service/s3/host_style_bucket_test.go b/service/s3/host_style_bucket_test.go index c4347d44b99..0d202e92b8c 100644 --- a/service/s3/host_style_bucket_test.go +++ b/service/s3/host_style_bucket_test.go @@ -1,12 +1,15 @@ package s3_test import ( + "net/url" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/internal/test/unit" "github.com/aws/aws-sdk-go/service/s3" - "github.com/stretchr/testify/assert" ) type s3BucketTest struct { @@ -59,3 +62,16 @@ func TestPathStyleBucketBuild(t *testing.T) { s := s3.New(&aws.Config{S3ForcePathStyle: aws.Bool(true)}) runTests(t, s, forcepathTests) } + +func TestHostStyleBucketGetBucketLocation(t *testing.T) { + s := s3.New(nil) + req, _ := s.GetBucketLocationRequest(&s3.GetBucketLocationInput{ + Bucket: aws.String("bucket"), + }) + + req.Build() + require.NoError(t, req.Error) + u, _ := url.Parse(req.HTTPRequest.URL.String()) + assert.NotContains(t, u.Host, "bucket") + assert.Contains(t, u.Path, "bucket") +}