Skip to content

Commit

Permalink
service/s3: GetBucketLocation should use path style for cross region …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jasdel committed Sep 16, 2015
1 parent df31ba5 commit ffc9803
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions service/s3/host_style_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
18 changes: 17 additions & 1 deletion service/s3/host_style_bucket_test.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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")
}

0 comments on commit ffc9803

Please sign in to comment.