From 2c7b30e5e15915e59d74462df6f0e062ca444b01 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 1 May 2015 12:17:27 -0700 Subject: [PATCH] Even mux vars don't help, handle it by looking at req.URL.Path --- pkg/api/api_signature.go | 21 ++++++++++++++++++--- pkg/api/api_test.go | 5 +++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pkg/api/api_signature.go b/pkg/api/api_signature.go index e1f4cd235..380c9b95f 100644 --- a/pkg/api/api_signature.go +++ b/pkg/api/api_signature.go @@ -30,7 +30,6 @@ import ( "strings" "time" - "github.com/gorilla/mux" "github.com/minio-io/minio/pkg/api/config" ) @@ -169,14 +168,30 @@ var subResList = []string{ "website", } +func url2BucketAndObject(url string) (string, string) { + var bucketName, objectName string + splits := strings.SplitN(url, "/", 3) + switch len(splits) { + case 0, 1: + bucketName = "" + objectName = "" + case 2: + bucketName = splits[1] + objectName = "" + case 3: + bucketName = splits[1] + objectName = splits[2] + } + return bucketName, objectName +} + // From the Amazon docs: // // CanonicalizedResource = [ "/" + Bucket ] + // + // [ sub-resource, if present. For example "?acl", "?location", "?logging", or "?torrent"]; func writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request) { - vars := mux.Vars(req) - bucket := vars["bucket"] + bucket, _ := url2BucketAndObject(req.URL.Path) if bucket != "" { buf.WriteByte('/') buf.WriteString(bucket) diff --git a/pkg/api/api_test.go b/pkg/api/api_test.go index 649ecee65..cafc19a4d 100644 --- a/pkg/api/api_test.go +++ b/pkg/api/api_test.go @@ -113,17 +113,18 @@ func (s *MySuite) TearDownTest(c *C) { } func setAuthHeader(req *http.Request) { + if date := req.Header.Get("Date"); date == "" { + req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat)) + } hm := hmac.New(sha1.New, []byte("H+AVh8q5G7hEH2r3WxFP135+Q19Aw8yXWel8IGh/HrEjZyTNx/n4Xw==")) ss := getStringToSign(req) io.WriteString(hm, ss) - authHeader := new(bytes.Buffer) fmt.Fprintf(authHeader, "AWS %s:", "AC5NH40NQLTL4D2W92PM") encoder := base64.NewEncoder(base64.StdEncoding, authHeader) encoder.Write(hm.Sum(nil)) encoder.Close() req.Header.Set("Authorization", authHeader.String()) - req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat)) } func (s *MySuite) TestNonExistantBucket(c *C) {