Skip to content

Commit

Permalink
Fix bucket name handling in signature V2 (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
krisis authored and deekoder committed Aug 4, 2017
1 parent 795cbb6 commit 1a09415
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pkg/s3signer/request-signature-v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ const (
func encodeURL2Path(u *url.URL) (path string) {
// Encode URL path.
if isS3, _ := filepath.Match("*.s3*.amazonaws.com", u.Host); isS3 {
hostSplits := strings.SplitN(u.Host, ".", 4)
// First element is the bucket name.
bucketName := hostSplits[0]
bucketName := u.Host[:strings.LastIndex(u.Host, ".s3")]
path = "/" + bucketName
path += u.Path
path = s3utils.EncodePath(path)
Expand Down
7 changes: 7 additions & 0 deletions pkg/s3signer/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,35 @@ import (
// Tests url encoding.
func TestEncodeURL2Path(t *testing.T) {
type urlStrings struct {
bucketName string
objName string
encodedObjName string
}

bucketName := "bucketName"
want := []urlStrings{
{
bucketName: "bucketName",
objName: "本語",
encodedObjName: "%E6%9C%AC%E8%AA%9E",
},
{
bucketName: "bucketName",
objName: "本語.1",
encodedObjName: "%E6%9C%AC%E8%AA%9E.1",
},
{
objName: ">123>3123123",
bucketName: "bucketName",
encodedObjName: "%3E123%3E3123123",
},
{
bucketName: "bucketName",
objName: "test 1 2.txt",
encodedObjName: "test%201%202.txt",
},
{
bucketName: "test.bucketName",
objName: "test++ 1.txt",
encodedObjName: "test%2B%2B%201.txt",
},
Expand All @@ -63,4 +69,5 @@ func TestEncodeURL2Path(t *testing.T) {
t.Fatal("Error")
}
}

}

0 comments on commit 1a09415

Please sign in to comment.