Merge pull request #891 from harshavardhana/server-signature-v4

Enforce signature v4 tests all the time, server defaults to only auth…
This commit is contained in:
Harshavardhana 2015-10-07 11:08:31 -07:00
commit c2fdccade4
11 changed files with 356 additions and 1186 deletions

View File

@ -49,6 +49,12 @@ var (
Usage: "Limit for total concurrent requests: [DEFAULT: 16].",
}
anonymousFlag = cli.BoolFlag{
Name: "anonymous",
Hide: true,
Usage: "Make server run in anonymous mode where all client connections are accepted.",
}
certFlag = cli.StringFlag{
Name: "cert",
Usage: "Provide your domain certificate.",

View File

@ -32,6 +32,7 @@ type minioConfig struct {
Address string
ControllerAddress string
RPCAddress string
Anonymous bool
TLS bool
CertFile string
KeyFile string
@ -40,7 +41,6 @@ type minioConfig struct {
func init() {
// Check for the environment early on and gracefuly report.
_, err := user.Current()
if err != nil {
Fatalf("Unable to obtain user's home directory. \nError: %s\n", err)
@ -100,6 +100,7 @@ func registerApp() *cli.App {
registerFlag(addressControllerFlag)
registerFlag(addressServerRPCFlag)
registerFlag(ratelimitFlag)
registerFlag(anonymousFlag)
registerFlag(certFlag)
registerFlag(keyFlag)
registerFlag(jsonFlag)

View File

@ -46,16 +46,12 @@ func (api API) isValidOp(w http.ResponseWriter, req *http.Request) bool {
}
if _, err = stripAccessKeyID(req.Header.Get("Authorization")); err != nil {
if bucketMetadata.ACL.IsPrivate() {
return true
//uncomment this when we have webcli
//writeErrorResponse(w, req, AccessDenied, req.URL.Path)
//return false
writeErrorResponse(w, req, AccessDenied, req.URL.Path)
return false
}
if bucketMetadata.ACL.IsPublicRead() && req.Method == "PUT" {
return true
//uncomment this when we have webcli
//writeErrorResponse(w, req, AccessDenied, req.URL.Path)
//return false
writeErrorResponse(w, req, AccessDenied, req.URL.Path)
return false
}
}
return true
@ -248,14 +244,16 @@ func (api API) PutBucketHandler(w http.ResponseWriter, req *http.Request) {
bucket := vars["bucket"]
var signature *signv4.Signature
if _, ok := req.Header["Authorization"]; ok {
// Init signature V4 verification
var err *probe.Error
signature, err = initSignatureV4(req)
if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, req.URL.Path)
return
if !api.Anonymous {
if _, ok := req.Header["Authorization"]; ok {
// Init signature V4 verification
var err *probe.Error
signature, err = initSignatureV4(req)
if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, req.URL.Path)
return
}
}
}
@ -305,6 +303,16 @@ func (api API) PostPolicyBucketHandler(w http.ResponseWriter, req *http.Request)
<-op.ProceedCh
}
// if body of request is non-nil then check for validity of Content-Length
if req.Body != nil {
/// if Content-Length missing, deny the request
size := req.Header.Get("Content-Length")
if size == "" {
writeErrorResponse(w, req, MissingContentLength, req.URL.Path)
return
}
}
// Here the parameter is the size of the form data that should
// be loaded in memory, the remaining being put in temporary
// files

View File

@ -1,109 +0,0 @@
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
"time"
)
type logHandler struct {
handler http.Handler
logger chan<- []byte
}
// logMessage is a serializable json log message
type logMessage struct {
StartTime time.Time
Duration time.Duration
StatusMessage string // human readable http status message
// HTTP detailed message
HTTP struct {
ResponseHeaders http.Header
Request *http.Request
}
}
// logWriter is used to capture status for log messages
type logWriter struct {
responseWriter http.ResponseWriter
logMessage *logMessage
}
// WriteHeader writes headers and stores status in LogMessage
func (w *logWriter) WriteHeader(status int) {
w.logMessage.StatusMessage = http.StatusText(status)
w.responseWriter.WriteHeader(status)
}
// Header Dummy wrapper for LogWriter
func (w *logWriter) Header() http.Header {
return w.responseWriter.Header()
}
// Write Dummy wrapper for LogWriter
func (w *logWriter) Write(data []byte) (int, error) {
return w.responseWriter.Write(data)
}
func (h *logHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
logMessage := &logMessage{
StartTime: time.Now().UTC(),
}
logWriter := &logWriter{responseWriter: w, logMessage: logMessage}
h.handler.ServeHTTP(logWriter, req)
h.logger <- getLogMessage(logMessage, w, req)
}
func getLogMessage(logMessage *logMessage, w http.ResponseWriter, req *http.Request) []byte {
// store lower level details
logMessage.HTTP.ResponseHeaders = w.Header()
logMessage.HTTP.Request = req
logMessage.Duration = time.Now().UTC().Sub(logMessage.StartTime)
js, _ := json.Marshal(logMessage)
js = append(js, byte('\n')) // append a new line
return js
}
// LoggingHandler logs requests
func LoggingHandler(h http.Handler) http.Handler {
logger, _ := fileLogger("access.log")
return &logHandler{handler: h, logger: logger}
}
// fileLogger returns a channel that is used to write to the logger
func fileLogger(filename string) (chan<- []byte, error) {
ch := make(chan []byte)
file, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
return nil, err
}
go func() {
for message := range ch {
if _, err := io.Copy(file, bytes.NewBuffer(message)); err != nil {
// log.Errorln(err)
}
}
}()
return ch, nil
}

View File

@ -186,14 +186,16 @@ func (api API) PutObjectHandler(w http.ResponseWriter, req *http.Request) {
}
var signature *signv4.Signature
if _, ok := req.Header["Authorization"]; ok {
// Init signature V4 verification
var err *probe.Error
signature, err = initSignatureV4(req)
if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, req.URL.Path)
return
if !api.Anonymous {
if _, ok := req.Header["Authorization"]; ok {
// Init signature V4 verification
var err *probe.Error
signature, err = initSignatureV4(req)
if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, req.URL.Path)
return
}
}
}
@ -338,14 +340,16 @@ func (api API) PutObjectPartHandler(w http.ResponseWriter, req *http.Request) {
}
var signature *signv4.Signature
if _, ok := req.Header["Authorization"]; ok {
// Init signature V4 verification
var err *probe.Error
signature, err = initSignatureV4(req)
if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, req.URL.Path)
return
if !api.Anonymous {
if _, ok := req.Header["Authorization"]; ok {
// Init signature V4 verification
var err *probe.Error
signature, err = initSignatureV4(req)
if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, req.URL.Path)
return
}
}
}
@ -485,16 +489,19 @@ func (api API) CompleteMultipartUploadHandler(w http.ResponseWriter, req *http.R
objectResourcesMetadata := getObjectResources(req.URL.Query())
var signature *signv4.Signature
if _, ok := req.Header["Authorization"]; ok {
// Init signature V4 verification
var err *probe.Error
signature, err = initSignatureV4(req)
if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, req.URL.Path)
return
if !api.Anonymous {
if _, ok := req.Header["Authorization"]; ok {
// Init signature V4 verification
var err *probe.Error
signature, err = initSignatureV4(req)
if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, req.URL.Path)
return
}
}
}
metadata, err := api.Donut.CompleteMultipartUpload(bucket, object, objectResourcesMetadata.UploadID, req.Body, signature)
if err != nil {
errorIf(err.Trace(), "CompleteMultipartUpload failed.", nil)

View File

@ -110,6 +110,7 @@ func (s signatureHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
writeErrorResponse(w, r, SignatureDoesNotMatch, r.URL.Path)
return
}
s.handler.ServeHTTP(w, r)
}
s.handler.ServeHTTP(w, r)
writeErrorResponse(w, r, AccessDenied, r.URL.Path)
}

View File

@ -130,8 +130,8 @@ func startTM(api API) {
// startServer starts an s3 compatible cloud storage server
func startServer(conf minioConfig) *probe.Error {
minioAPI := getNewAPI()
apiHandler := getAPIHandler(minioAPI)
minioAPI := getNewAPI(conf.Anonymous)
apiHandler := getAPIHandler(conf.Anonymous, minioAPI)
apiServer, err := configureAPIServer(conf, apiHandler)
if err != nil {
return err.Trace()
@ -156,6 +156,7 @@ func getServerConfig(c *cli.Context) minioConfig {
return minioConfig{
Address: c.GlobalString("address"),
RPCAddress: c.GlobalString("address-server-rpc"),
Anonymous: c.GlobalBool("anonymous"),
TLS: tls,
CertFile: certFile,
KeyFile: keyFile,

View File

@ -64,31 +64,33 @@ type APIOperation struct {
// API container for API and also carries OP (operation) channel
type API struct {
OP chan APIOperation
Donut donut.Interface
OP chan APIOperation
Donut donut.Interface
Anonymous bool // do not checking for incoming signatures, allow all requests
}
// getNewAPI instantiate a new minio API
func getNewAPI() API {
func getNewAPI(anonymous bool) API {
// ignore errors for now
d, err := donut.New()
fatalIf(err.Trace(), "Instantiating donut failed.", nil)
return API{
OP: make(chan APIOperation),
Donut: d,
OP: make(chan APIOperation),
Donut: d,
Anonymous: anonymous,
}
}
// getAPIHandler api handler
func getAPIHandler(api API) http.Handler {
func getAPIHandler(anonymous bool, api API) http.Handler {
var mwHandlers = []MiddlewareHandler{
TimeValidityHandler,
IgnoreResourcesHandler,
SignatureHandler,
// api.LoggingHandler, // Disabled logging until we bring in external logging support
CorsHandler,
}
if !anonymous {
mwHandlers = append(mwHandlers, SignatureHandler)
}
mux := router.NewRouter()
registerAPI(mux, api)
apiHandler := registerCustomMiddleware(mux, mwHandlers...)

View File

@ -1,896 +0,0 @@
/*
* Minio Cloud Storage, (C) 2014 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"encoding/xml"
"net/http"
"net/http/httptest"
"github.com/minio/minio/pkg/donut"
. "gopkg.in/check.v1"
)
type MyAPIDonutSuite struct {
root string
}
var _ = Suite(&MyAPIDonutSuite{})
var testAPIDonutServer *httptest.Server
// create a dummy TestNodeDiskMap
func createTestNodeDiskMap(p string) map[string][]string {
nodes := make(map[string][]string)
nodes["localhost"] = make([]string, 16)
for i := 0; i < len(nodes["localhost"]); i++ {
diskPath := filepath.Join(p, strconv.Itoa(i))
if _, err := os.Stat(diskPath); err != nil {
if os.IsNotExist(err) {
os.MkdirAll(diskPath, 0700)
}
}
nodes["localhost"][i] = diskPath
}
return nodes
}
func (s *MyAPIDonutSuite) SetUpSuite(c *C) {
root, err := ioutil.TempDir(os.TempDir(), "api-")
c.Assert(err, IsNil)
s.root = root
conf := new(donut.Config)
conf.Version = "0.0.1"
conf.DonutName = "test"
conf.NodeDiskMap = createTestNodeDiskMap(root)
conf.MaxSize = 100000
donut.SetDonutConfigPath(filepath.Join(root, "donut.json"))
perr := donut.SaveConfig(conf)
c.Assert(perr, IsNil)
minioAPI := getNewAPI()
httpHandler := getAPIHandler(minioAPI)
go startTM(minioAPI)
testAPIDonutServer = httptest.NewServer(httpHandler)
}
func (s *MyAPIDonutSuite) TearDownSuite(c *C) {
os.RemoveAll(s.root)
testAPIDonutServer.Close()
}
func (s *MyAPIDonutSuite) TestDeleteBucket(c *C) {
request, err := http.NewRequest("DELETE", testAPIDonutServer.URL+"/mybucket", nil)
c.Assert(err, IsNil)
client := &http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusMethodNotAllowed)
}
func (s *MyAPIDonutSuite) TestDeleteObject(c *C) {
request, err := http.NewRequest("DELETE", testAPIDonutServer.URL+"/mybucket/myobject", nil)
c.Assert(err, IsNil)
client := &http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusMethodNotAllowed)
}
func (s *MyAPIDonutSuite) TestNonExistantBucket(c *C) {
request, err := http.NewRequest("HEAD", testAPIDonutServer.URL+"/nonexistantbucket", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
}
func (s *MyAPIDonutSuite) TestEmptyObject(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/emptyobject", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/emptyobject/object", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/emptyobject/object", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
var buffer bytes.Buffer
responseBody, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(true, Equals, bytes.Equal(responseBody, buffer.Bytes()))
}
func (s *MyAPIDonutSuite) TestBucket(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/bucket", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutServer.URL+"/bucket", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
}
func (s *MyAPIDonutSuite) TestObject(c *C) {
buffer := bytes.NewBufferString("hello world")
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/testobject", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/testobject/object", buffer)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/testobject/object", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
responseBody, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(responseBody, DeepEquals, []byte("hello world"))
}
func (s *MyAPIDonutSuite) TestMultipleObjects(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/multipleobjects", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/multipleobjects/object", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
//// test object 1
// get object
buffer1 := bytes.NewBufferString("hello one")
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/multipleobjects/object1", buffer1)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/multipleobjects/object1", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
// verify response data
responseBody, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello one")))
buffer2 := bytes.NewBufferString("hello two")
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/multipleobjects/object2", buffer2)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/multipleobjects/object2", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
// verify response data
responseBody, err = ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello two")))
buffer3 := bytes.NewBufferString("hello three")
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/multipleobjects/object3", buffer3)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/multipleobjects/object3", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
// verify object
responseBody, err = ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello three")))
}
func (s *MyAPIDonutSuite) TestNotImplemented(c *C) {
request, err := http.NewRequest("GET", testAPIDonutServer.URL+"/bucket/object?policy", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusNotImplemented)
}
func (s *MyAPIDonutSuite) TestHeader(c *C) {
request, err := http.NewRequest("GET", testAPIDonutServer.URL+"/bucket/object", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
}
func (s *MyAPIDonutSuite) TestPutBucket(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/put-bucket", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
}
func (s *MyAPIDonutSuite) TestPutObject(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/put-object", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/put-object/object", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
}
func (s *MyAPIDonutSuite) TestListBuckets(c *C) {
request, err := http.NewRequest("GET", testAPIDonutServer.URL+"/", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
var results ListBucketsResponse
decoder := xml.NewDecoder(response.Body)
err = decoder.Decode(&results)
c.Assert(err, IsNil)
}
func (s *MyAPIDonutSuite) TestNotBeAbleToCreateObjectInNonexistantBucket(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/innonexistantbucket/object", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
}
func (s *MyAPIDonutSuite) TestHeadOnObject(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/headonobject", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/headonobject/object1", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutServer.URL+"/headonobject/object1", nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
}
func (s *MyAPIDonutSuite) TestHeadOnBucket(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/headonbucket", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutServer.URL+"/headonbucket", nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
}
/*
func (s *MyAPIDonutSuite) TestDateFormat(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/dateformat", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
// set an invalid date
request.Header.Set("Date", "asfasdfadf")
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "RequestTimeTooSkewed",
"The difference between the request time and the server's time is too large.", http.StatusForbidden)
request.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
response, err = client.Do(request)
c.Assert(response.StatusCode, Equals, http.StatusOK)
}
*/
func (s *MyAPIDonutSuite) TestXMLNameNotInBucketListJson(c *C) {
request, err := http.NewRequest("GET", testAPIDonutServer.URL+"/", nil)
c.Assert(err, IsNil)
request.Header.Add("Accept", "application/json")
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
byteResults, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(byteResults), "XML"), Equals, false)
}
func (s *MyAPIDonutSuite) TestXMLNameNotInObjectListJson(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/xmlnamenotinobjectlistjson", nil)
c.Assert(err, IsNil)
request.Header.Add("Accept", "application/json")
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/xmlnamenotinobjectlistjson", nil)
c.Assert(err, IsNil)
request.Header.Add("Accept", "application/json")
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
byteResults, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(byteResults), "XML"), Equals, false)
}
func (s *MyAPIDonutSuite) TestContentTypePersists(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/contenttype-persists", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/contenttype-persists/one", bytes.NewBufferString("hello world"))
delete(request.Header, "Content-Type")
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutServer.URL+"/contenttype-persists/one", nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/contenttype-persists/one", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/contenttype-persists/two", bytes.NewBufferString("hello world"))
delete(request.Header, "Content-Type")
request.Header.Add("Content-Type", "application/json")
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutServer.URL+"/contenttype-persists/two", nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/contenttype-persists/two", nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
}
func (s *MyAPIDonutSuite) TestPartialContent(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/partial-content", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/partial-content/bar", bytes.NewBufferString("Hello World"))
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
// prepare request
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/partial-content/bar", nil)
c.Assert(err, IsNil)
request.Header.Add("Accept", "application/json")
request.Header.Add("Range", "bytes=6-7")
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusPartialContent)
partialObject, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(string(partialObject), Equals, "Wo")
}
func (s *MyAPIDonutSuite) TestListObjectsHandlerErrors(c *C) {
request, err := http.NewRequest("GET", testAPIDonutServer.URL+"/objecthandlererrors-.", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/objecthandlererrors", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/objecthandlererrors", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/objecthandlererrors?max-keys=-2", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "InvalidArgument", "Argument maxKeys must be an integer between 0 and 2147483647.", http.StatusBadRequest)
}
func (s *MyAPIDonutSuite) TestPutBucketErrors(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/putbucket-.", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/putbucket", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/putbucket", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "BucketAlreadyExists", "The requested bucket name is not available.", http.StatusConflict)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/putbucket?acl", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "unknown")
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "NotImplemented", "A header you provided implies functionality that is not implemented.", http.StatusNotImplemented)
}
func (s *MyAPIDonutSuite) TestGetObjectErrors(c *C) {
request, err := http.NewRequest("GET", testAPIDonutServer.URL+"/getobjecterrors", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/getobjecterrors", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/getobjecterrors/bar", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/getobjecterrors-./bar", nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
}
func (s *MyAPIDonutSuite) TestGetObjectRangeErrors(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/getobjectrangeerrors", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/getobjectrangeerrors/bar", bytes.NewBufferString("Hello World"))
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/getobjectrangeerrors/bar", nil)
request.Header.Add("Range", "bytes=7-6")
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "InvalidRange", "The requested range cannot be satisfied.", http.StatusRequestedRangeNotSatisfiable)
}
func (s *MyAPIDonutSuite) TestObjectMultipartAbort(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/objectmultipartabort", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, 200)
request, err = http.NewRequest("POST", testAPIDonutServer.URL+"/objectmultipartabort/object?uploads", bytes.NewBufferString(""))
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(response.StatusCode, Equals, http.StatusOK)
decoder := xml.NewDecoder(response.Body)
newResponse := &InitiateMultipartUploadResponse{}
err = decoder.Decode(newResponse)
c.Assert(err, IsNil)
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
uploadID := newResponse.UploadID
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
response1, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response1.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
response2, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response2.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("DELETE", testAPIDonutServer.URL+"/objectmultipartabort/object?uploadId="+uploadID, nil)
c.Assert(err, IsNil)
response3, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response3.StatusCode, Equals, http.StatusNoContent)
}
func (s *MyAPIDonutSuite) TestBucketMultipartList(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/bucketmultipartlist", bytes.NewBufferString(""))
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, 200)
request, err = http.NewRequest("POST", testAPIDonutServer.URL+"/bucketmultipartlist/object?uploads", bytes.NewBufferString(""))
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(response.StatusCode, Equals, http.StatusOK)
decoder := xml.NewDecoder(response.Body)
newResponse := &InitiateMultipartUploadResponse{}
err = decoder.Decode(newResponse)
c.Assert(err, IsNil)
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
uploadID := newResponse.UploadID
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
response1, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response1.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
response2, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response2.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/bucketmultipartlist?uploads", nil)
c.Assert(err, IsNil)
response3, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response3.StatusCode, Equals, http.StatusOK)
decoder = xml.NewDecoder(response3.Body)
newResponse3 := &ListMultipartUploadsResponse{}
err = decoder.Decode(newResponse3)
c.Assert(err, IsNil)
c.Assert(newResponse3.Bucket, Equals, "bucketmultipartlist")
}
func (s *MyAPIDonutSuite) TestObjectMultipartList(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/objectmultipartlist", bytes.NewBufferString(""))
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, 200)
request, err = http.NewRequest("POST", testAPIDonutServer.URL+"/objectmultipartlist/object?uploads", bytes.NewBufferString(""))
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(response.StatusCode, Equals, http.StatusOK)
decoder := xml.NewDecoder(response.Body)
newResponse := &InitiateMultipartUploadResponse{}
err = decoder.Decode(newResponse)
c.Assert(err, IsNil)
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
uploadID := newResponse.UploadID
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
response1, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response1.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
response2, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response2.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/objectmultipartlist/object?uploadId="+uploadID, nil)
c.Assert(err, IsNil)
response3, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response3.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutServer.URL+"/objectmultipartlist/object?max-parts=-2&uploadId="+uploadID, nil)
c.Assert(err, IsNil)
response4, err := client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response4, "InvalidArgument", "Argument maxParts must be an integer between 1 and 10000.", http.StatusBadRequest)
}
func (s *MyAPIDonutSuite) TestObjectMultipart(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutServer.URL+"/objectmultiparts", nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, 200)
request, err = http.NewRequest("POST", testAPIDonutServer.URL+"/objectmultiparts/object?uploads", nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
decoder := xml.NewDecoder(response.Body)
newResponse := &InitiateMultipartUploadResponse{}
err = decoder.Decode(newResponse)
c.Assert(err, IsNil)
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
uploadID := newResponse.UploadID
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
client = http.Client{}
response1, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response1.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
c.Assert(err, IsNil)
client = http.Client{}
response2, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response2.StatusCode, Equals, http.StatusOK)
// complete multipart upload
completeUploads := &donut.CompleteMultipartUpload{
Part: []donut.CompletePart{
{
PartNumber: 1,
ETag: response1.Header.Get("ETag"),
},
{
PartNumber: 2,
ETag: response2.Header.Get("ETag"),
},
},
}
var completeBuffer bytes.Buffer
encoder := xml.NewEncoder(&completeBuffer)
encoder.Encode(completeUploads)
request, err = http.NewRequest("POST", testAPIDonutServer.URL+"/objectmultiparts/object?uploadId="+uploadID, &completeBuffer)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
}

View File

@ -18,11 +18,15 @@ package main
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
"time"
"encoding/hex"
"encoding/xml"
"net/http"
"net/http/httptest"
@ -32,7 +36,11 @@ import (
)
type MyAPIDonutCacheSuite struct {
root string
root string
req *http.Request
body io.ReadSeeker
accessKeyID string
secretAccessKey string
}
var _ = Suite(&MyAPIDonutCacheSuite{})
@ -51,10 +59,29 @@ func (s *MyAPIDonutCacheSuite) SetUpSuite(c *C) {
perr := donut.SaveConfig(conf)
c.Assert(perr, IsNil)
minioAPI := getNewAPI()
apiHandler := getAPIHandler(minioAPI)
accessKeyID, perr := generateAccessKeyID()
c.Assert(perr, IsNil)
secretAccessKey, perr := generateSecretAccessKey()
c.Assert(perr, IsNil)
authConf := &AuthConfig{}
authConf.Users = make(map[string]*AuthUser)
authConf.Users[string(accessKeyID)] = &AuthUser{
Name: "testuser",
AccessKeyID: string(accessKeyID),
SecretAccessKey: string(secretAccessKey),
}
s.accessKeyID = string(accessKeyID)
s.secretAccessKey = string(secretAccessKey)
SetAuthConfigPath(root)
perr = SaveConfig(authConf)
c.Assert(perr, IsNil)
minioAPI := getNewAPI(false)
httpHandler := getAPIHandler(false, minioAPI)
go startTM(minioAPI)
testAPIDonutCacheServer = httptest.NewServer(apiHandler)
testAPIDonutCacheServer = httptest.NewServer(httpHandler)
}
func (s *MyAPIDonutCacheSuite) TearDownSuite(c *C) {
@ -62,8 +89,130 @@ func (s *MyAPIDonutCacheSuite) TearDownSuite(c *C) {
testAPIDonutCacheServer.Close()
}
func (s *MyAPIDonutCacheSuite) newRequest(method, urlStr string, contentLength int64, body io.ReadSeeker) (*http.Request, error) {
t := time.Now().UTC()
req, err := http.NewRequest(method, urlStr, nil)
if err != nil {
return nil, err
}
req.Header.Set("x-amz-date", t.Format(iso8601Format))
if method == "" {
method = "POST"
}
// add Content-Length
req.ContentLength = contentLength
// add body
switch {
case body == nil:
req.Body = nil
default:
req.Body = ioutil.NopCloser(body)
}
// save for subsequent use
hash := func() string {
switch {
case body == nil:
return hex.EncodeToString(sum256([]byte{}))
default:
sum256Bytes, _ := sum256Reader(body)
return hex.EncodeToString(sum256Bytes)
}
}
hashedPayload := hash()
req.Header.Set("x-amz-content-sha256", hashedPayload)
var headers []string
vals := make(map[string][]string)
for k, vv := range req.Header {
if _, ok := ignoredHeaders[http.CanonicalHeaderKey(k)]; ok {
continue // ignored header
}
headers = append(headers, strings.ToLower(k))
vals[strings.ToLower(k)] = vv
}
headers = append(headers, "host")
sort.Strings(headers)
var canonicalHeaders bytes.Buffer
for _, k := range headers {
canonicalHeaders.WriteString(k)
canonicalHeaders.WriteByte(':')
switch {
case k == "host":
canonicalHeaders.WriteString(req.URL.Host)
fallthrough
default:
for idx, v := range vals[k] {
if idx > 0 {
canonicalHeaders.WriteByte(',')
}
canonicalHeaders.WriteString(v)
}
canonicalHeaders.WriteByte('\n')
}
}
signedHeaders := strings.Join(headers, ";")
req.URL.RawQuery = strings.Replace(req.URL.Query().Encode(), "+", "%20", -1)
encodedPath, _ := urlEncodeName(req.URL.Path)
// convert any space strings back to "+"
encodedPath = strings.Replace(encodedPath, "+", "%20", -1)
//
// canonicalRequest =
// <HTTPMethod>\n
// <CanonicalURI>\n
// <CanonicalQueryString>\n
// <CanonicalHeaders>\n
// <SignedHeaders>\n
// <HashedPayload>
//
canonicalRequest := strings.Join([]string{
req.Method,
encodedPath,
req.URL.RawQuery,
canonicalHeaders.String(),
signedHeaders,
hashedPayload,
}, "\n")
scope := strings.Join([]string{
t.Format(yyyymmdd),
"milkyway",
"s3",
"aws4_request",
}, "/")
stringToSign := authHeaderPrefix + "\n" + t.Format(iso8601Format) + "\n"
stringToSign = stringToSign + scope + "\n"
stringToSign = stringToSign + hex.EncodeToString(sum256([]byte(canonicalRequest)))
date := sumHMAC([]byte("AWS4"+s.secretAccessKey), []byte(t.Format(yyyymmdd)))
region := sumHMAC(date, []byte("milkyway"))
service := sumHMAC(region, []byte("s3"))
signingKey := sumHMAC(service, []byte("aws4_request"))
signature := hex.EncodeToString(sumHMAC(signingKey, []byte(stringToSign)))
// final Authorization header
parts := []string{
authHeaderPrefix + " Credential=" + s.accessKeyID + "/" + scope,
"SignedHeaders=" + signedHeaders,
"Signature=" + signature,
}
auth := strings.Join(parts, ", ")
req.Header.Set("Authorization", auth)
return req, nil
}
func (s *MyAPIDonutCacheSuite) TestDeleteBucket(c *C) {
request, err := http.NewRequest("DELETE", testAPIDonutCacheServer.URL+"/mybucket", nil)
request, err := s.newRequest("DELETE", testAPIDonutCacheServer.URL+"/mybucket", 0, nil)
c.Assert(err, IsNil)
client := &http.Client{}
@ -73,7 +222,7 @@ func (s *MyAPIDonutCacheSuite) TestDeleteBucket(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestDeleteObject(c *C) {
request, err := http.NewRequest("DELETE", testAPIDonutCacheServer.URL+"/mybucket/myobject", nil)
request, err := s.newRequest("DELETE", testAPIDonutCacheServer.URL+"/mybucket/myobject", 0, nil)
c.Assert(err, IsNil)
client := &http.Client{}
response, err := client.Do(request)
@ -82,7 +231,7 @@ func (s *MyAPIDonutCacheSuite) TestDeleteObject(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestNonExistantBucket(c *C) {
request, err := http.NewRequest("HEAD", testAPIDonutCacheServer.URL+"/nonexistantbucket", nil)
request, err := s.newRequest("HEAD", testAPIDonutCacheServer.URL+"/nonexistantbucket", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -92,7 +241,7 @@ func (s *MyAPIDonutCacheSuite) TestNonExistantBucket(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestEmptyObject(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/emptyobject", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/emptyobject", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -100,7 +249,7 @@ func (s *MyAPIDonutCacheSuite) TestEmptyObject(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/emptyobject/object", nil)
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/emptyobject/object", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -108,7 +257,7 @@ func (s *MyAPIDonutCacheSuite) TestEmptyObject(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/emptyobject/object", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/emptyobject/object", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -123,7 +272,7 @@ func (s *MyAPIDonutCacheSuite) TestEmptyObject(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestBucket(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/bucket", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/bucket", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -131,7 +280,7 @@ func (s *MyAPIDonutCacheSuite) TestBucket(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutCacheServer.URL+"/bucket", nil)
request, err = s.newRequest("HEAD", testAPIDonutCacheServer.URL+"/bucket", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -141,8 +290,8 @@ func (s *MyAPIDonutCacheSuite) TestBucket(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestObject(c *C) {
buffer := bytes.NewBufferString("hello world")
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/testobject", nil)
buffer := bytes.NewReader([]byte("hello world"))
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/testobject", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -150,7 +299,7 @@ func (s *MyAPIDonutCacheSuite) TestObject(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/testobject/object", buffer)
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/testobject/object", int64(buffer.Len()), buffer)
c.Assert(err, IsNil)
client = http.Client{}
@ -158,7 +307,7 @@ func (s *MyAPIDonutCacheSuite) TestObject(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/testobject/object", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/testobject/object", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -173,7 +322,7 @@ func (s *MyAPIDonutCacheSuite) TestObject(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestMultipleObjects(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/multipleobjects", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/multipleobjects", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -181,7 +330,7 @@ func (s *MyAPIDonutCacheSuite) TestMultipleObjects(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/multipleobjects/object", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/multipleobjects/object", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -192,8 +341,8 @@ func (s *MyAPIDonutCacheSuite) TestMultipleObjects(c *C) {
//// test object 1
// get object
buffer1 := bytes.NewBufferString("hello one")
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/multipleobjects/object1", buffer1)
buffer1 := bytes.NewReader([]byte("hello one"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/multipleobjects/object1", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
client = http.Client{}
@ -201,7 +350,7 @@ func (s *MyAPIDonutCacheSuite) TestMultipleObjects(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/multipleobjects/object1", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/multipleobjects/object1", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -214,8 +363,8 @@ func (s *MyAPIDonutCacheSuite) TestMultipleObjects(c *C) {
c.Assert(err, IsNil)
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello one")))
buffer2 := bytes.NewBufferString("hello two")
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/multipleobjects/object2", buffer2)
buffer2 := bytes.NewReader([]byte("hello two"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/multipleobjects/object2", int64(buffer2.Len()), buffer2)
c.Assert(err, IsNil)
client = http.Client{}
@ -223,7 +372,7 @@ func (s *MyAPIDonutCacheSuite) TestMultipleObjects(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/multipleobjects/object2", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/multipleobjects/object2", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -236,8 +385,8 @@ func (s *MyAPIDonutCacheSuite) TestMultipleObjects(c *C) {
c.Assert(err, IsNil)
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello two")))
buffer3 := bytes.NewBufferString("hello three")
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/multipleobjects/object3", buffer3)
buffer3 := bytes.NewReader([]byte("hello three"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/multipleobjects/object3", int64(buffer3.Len()), buffer3)
c.Assert(err, IsNil)
client = http.Client{}
@ -245,7 +394,7 @@ func (s *MyAPIDonutCacheSuite) TestMultipleObjects(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/multipleobjects/object3", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/multipleobjects/object3", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -260,7 +409,7 @@ func (s *MyAPIDonutCacheSuite) TestMultipleObjects(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestNotImplemented(c *C) {
request, err := http.NewRequest("GET", testAPIDonutCacheServer.URL+"/bucket/object?policy", nil)
request, err := s.newRequest("GET", testAPIDonutCacheServer.URL+"/bucket/object?policy", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -271,7 +420,7 @@ func (s *MyAPIDonutCacheSuite) TestNotImplemented(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestHeader(c *C) {
request, err := http.NewRequest("GET", testAPIDonutCacheServer.URL+"/bucket/object", nil)
request, err := s.newRequest("GET", testAPIDonutCacheServer.URL+"/bucket/object", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -282,7 +431,7 @@ func (s *MyAPIDonutCacheSuite) TestHeader(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestPutBucket(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/put-bucket", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/put-bucket", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
@ -293,7 +442,7 @@ func (s *MyAPIDonutCacheSuite) TestPutBucket(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestPutObject(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/put-object", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/put-object", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
@ -302,7 +451,8 @@ func (s *MyAPIDonutCacheSuite) TestPutObject(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/put-object/object", bytes.NewBufferString("hello world"))
buffer1 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/put-object/object", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
response, err = client.Do(request)
@ -311,7 +461,7 @@ func (s *MyAPIDonutCacheSuite) TestPutObject(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestListBuckets(c *C) {
request, err := http.NewRequest("GET", testAPIDonutCacheServer.URL+"/", nil)
request, err := s.newRequest("GET", testAPIDonutCacheServer.URL+"/", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -326,7 +476,8 @@ func (s *MyAPIDonutCacheSuite) TestListBuckets(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestNotBeAbleToCreateObjectInNonexistantBucket(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/innonexistantbucket/object", bytes.NewBufferString("hello world"))
buffer1 := bytes.NewReader([]byte("hello world"))
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/innonexistantbucket/object", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
client := http.Client{}
@ -336,7 +487,7 @@ func (s *MyAPIDonutCacheSuite) TestNotBeAbleToCreateObjectInNonexistantBucket(c
}
func (s *MyAPIDonutCacheSuite) TestHeadOnObject(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/headonobject", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/headonobject", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
@ -345,14 +496,15 @@ func (s *MyAPIDonutCacheSuite) TestHeadOnObject(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/headonobject/object1", bytes.NewBufferString("hello world"))
buffer1 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/headonobject/object1", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutCacheServer.URL+"/headonobject/object1", nil)
request, err = s.newRequest("HEAD", testAPIDonutCacheServer.URL+"/headonobject/object1", 0, nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
@ -361,7 +513,7 @@ func (s *MyAPIDonutCacheSuite) TestHeadOnObject(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestHeadOnBucket(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/headonbucket", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/headonbucket", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
@ -370,7 +522,7 @@ func (s *MyAPIDonutCacheSuite) TestHeadOnBucket(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutCacheServer.URL+"/headonbucket", nil)
request, err = s.newRequest("HEAD", testAPIDonutCacheServer.URL+"/headonbucket", 0, nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
@ -378,29 +530,8 @@ func (s *MyAPIDonutCacheSuite) TestHeadOnBucket(c *C) {
c.Assert(response.StatusCode, Equals, http.StatusOK)
}
/* Enable when we have full working signature v4
func (s *MyAPIDonutCacheSuite) TestDateFormat(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/dateformat", nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
// set an invalid date
request.Header.Set("Date", "asfasdfadf")
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "RequestTimeTooSkewed",
"The difference between the request time and the server's time is too large.", http.StatusForbidden)
request.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
response, err = client.Do(request)
c.Assert(response.StatusCode, Equals, http.StatusOK)
}
*/
func (s *MyAPIDonutCacheSuite) TestXMLNameNotInBucketListJson(c *C) {
request, err := http.NewRequest("GET", testAPIDonutCacheServer.URL+"/", nil)
request, err := s.newRequest("GET", testAPIDonutCacheServer.URL+"/", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("Accept", "application/json")
@ -415,7 +546,7 @@ func (s *MyAPIDonutCacheSuite) TestXMLNameNotInBucketListJson(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestXMLNameNotInObjectListJson(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/xmlnamenotinobjectlistjson", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/xmlnamenotinobjectlistjson", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("Accept", "application/json")
@ -424,7 +555,7 @@ func (s *MyAPIDonutCacheSuite) TestXMLNameNotInObjectListJson(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/xmlnamenotinobjectlistjson", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/xmlnamenotinobjectlistjson", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("Accept", "application/json")
@ -439,7 +570,7 @@ func (s *MyAPIDonutCacheSuite) TestXMLNameNotInObjectListJson(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestContentTypePersists(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/contenttype-persists", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/contenttype-persists", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -447,7 +578,8 @@ func (s *MyAPIDonutCacheSuite) TestContentTypePersists(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/contenttype-persists/one", bytes.NewBufferString("hello world"))
buffer1 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/contenttype-persists/one", int64(buffer1.Len()), buffer1)
delete(request.Header, "Content-Type")
c.Assert(err, IsNil)
@ -456,14 +588,14 @@ func (s *MyAPIDonutCacheSuite) TestContentTypePersists(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutCacheServer.URL+"/contenttype-persists/one", nil)
request, err = s.newRequest("HEAD", testAPIDonutCacheServer.URL+"/contenttype-persists/one", 0, nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/contenttype-persists/one", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/contenttype-persists/one", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -472,7 +604,8 @@ func (s *MyAPIDonutCacheSuite) TestContentTypePersists(c *C) {
c.Assert(response.StatusCode, Equals, http.StatusOK)
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/contenttype-persists/two", bytes.NewBufferString("hello world"))
buffer2 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/contenttype-persists/two", int64(buffer2.Len()), buffer2)
delete(request.Header, "Content-Type")
request.Header.Add("Content-Type", "application/json")
c.Assert(err, IsNil)
@ -481,14 +614,14 @@ func (s *MyAPIDonutCacheSuite) TestContentTypePersists(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("HEAD", testAPIDonutCacheServer.URL+"/contenttype-persists/two", nil)
request, err = s.newRequest("HEAD", testAPIDonutCacheServer.URL+"/contenttype-persists/two", 0, nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/contenttype-persists/two", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/contenttype-persists/two", 0, nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
@ -497,7 +630,7 @@ func (s *MyAPIDonutCacheSuite) TestContentTypePersists(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestPartialContent(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/partial-content", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/partial-content", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -505,7 +638,8 @@ func (s *MyAPIDonutCacheSuite) TestPartialContent(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/partial-content/bar", bytes.NewBufferString("Hello World"))
buffer1 := bytes.NewReader([]byte("Hello World"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/partial-content/bar", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
client = http.Client{}
@ -514,7 +648,7 @@ func (s *MyAPIDonutCacheSuite) TestPartialContent(c *C) {
c.Assert(response.StatusCode, Equals, http.StatusOK)
// prepare request
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/partial-content/bar", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/partial-content/bar", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("Accept", "application/json")
request.Header.Add("Range", "bytes=6-7")
@ -530,7 +664,7 @@ func (s *MyAPIDonutCacheSuite) TestPartialContent(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestListObjectsHandlerErrors(c *C) {
request, err := http.NewRequest("GET", testAPIDonutCacheServer.URL+"/objecthandlererrors-.", nil)
request, err := s.newRequest("GET", testAPIDonutCacheServer.URL+"/objecthandlererrors-.", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -538,7 +672,7 @@ func (s *MyAPIDonutCacheSuite) TestListObjectsHandlerErrors(c *C) {
c.Assert(err, IsNil)
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/objecthandlererrors", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/objecthandlererrors", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -546,7 +680,7 @@ func (s *MyAPIDonutCacheSuite) TestListObjectsHandlerErrors(c *C) {
c.Assert(err, IsNil)
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objecthandlererrors", nil)
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objecthandlererrors", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
@ -555,7 +689,7 @@ func (s *MyAPIDonutCacheSuite) TestListObjectsHandlerErrors(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/objecthandlererrors?max-keys=-2", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/objecthandlererrors?max-keys=-2", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
@ -564,7 +698,7 @@ func (s *MyAPIDonutCacheSuite) TestListObjectsHandlerErrors(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestPutBucketErrors(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/putbucket-.", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/putbucket-.", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
@ -573,7 +707,7 @@ func (s *MyAPIDonutCacheSuite) TestPutBucketErrors(c *C) {
c.Assert(err, IsNil)
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/putbucket", nil)
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/putbucket", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
@ -582,7 +716,7 @@ func (s *MyAPIDonutCacheSuite) TestPutBucketErrors(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/putbucket", nil)
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/putbucket", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
@ -590,7 +724,7 @@ func (s *MyAPIDonutCacheSuite) TestPutBucketErrors(c *C) {
c.Assert(err, IsNil)
verifyError(c, response, "BucketAlreadyExists", "The requested bucket name is not available.", http.StatusConflict)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/putbucket?acl", nil)
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/putbucket?acl", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "unknown")
@ -600,7 +734,7 @@ func (s *MyAPIDonutCacheSuite) TestPutBucketErrors(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestGetObjectErrors(c *C) {
request, err := http.NewRequest("GET", testAPIDonutCacheServer.URL+"/getobjecterrors", nil)
request, err := s.newRequest("GET", testAPIDonutCacheServer.URL+"/getobjecterrors", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -608,7 +742,7 @@ func (s *MyAPIDonutCacheSuite) TestGetObjectErrors(c *C) {
c.Assert(err, IsNil)
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/getobjecterrors", nil)
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/getobjecterrors", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -616,7 +750,7 @@ func (s *MyAPIDonutCacheSuite) TestGetObjectErrors(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/getobjecterrors/bar", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/getobjecterrors/bar", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -624,7 +758,7 @@ func (s *MyAPIDonutCacheSuite) TestGetObjectErrors(c *C) {
c.Assert(err, IsNil)
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/getobjecterrors-./bar", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/getobjecterrors-./bar", 0, nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
@ -634,7 +768,7 @@ func (s *MyAPIDonutCacheSuite) TestGetObjectErrors(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestGetObjectRangeErrors(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/getobjectrangeerrors", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/getobjectrangeerrors", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -642,7 +776,8 @@ func (s *MyAPIDonutCacheSuite) TestGetObjectRangeErrors(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/getobjectrangeerrors/bar", bytes.NewBufferString("Hello World"))
buffer1 := bytes.NewReader([]byte("Hello World"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/getobjectrangeerrors/bar", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
client = http.Client{}
@ -650,7 +785,7 @@ func (s *MyAPIDonutCacheSuite) TestGetObjectRangeErrors(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/getobjectrangeerrors/bar", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/getobjectrangeerrors/bar", 0, nil)
request.Header.Add("Range", "bytes=7-6")
c.Assert(err, IsNil)
@ -661,7 +796,7 @@ func (s *MyAPIDonutCacheSuite) TestGetObjectRangeErrors(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestObjectMultipartAbort(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartabort", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartabort", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -669,7 +804,7 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipartAbort(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, 200)
request, err = http.NewRequest("POST", testAPIDonutCacheServer.URL+"/objectmultipartabort/object?uploads", bytes.NewBufferString(""))
request, err = s.newRequest("POST", testAPIDonutCacheServer.URL+"/objectmultipartabort/object?uploads", 0, nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
@ -683,21 +818,23 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipartAbort(c *C) {
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
uploadID := newResponse.UploadID
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
buffer1 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=1", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
response1, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response1.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
buffer2 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=2", int64(buffer2.Len()), buffer2)
c.Assert(err, IsNil)
response2, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response2.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("DELETE", testAPIDonutCacheServer.URL+"/objectmultipartabort/object?uploadId="+uploadID, nil)
request, err = s.newRequest("DELETE", testAPIDonutCacheServer.URL+"/objectmultipartabort/object?uploadId="+uploadID, 0, nil)
c.Assert(err, IsNil)
response3, err := client.Do(request)
@ -706,7 +843,7 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipartAbort(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestBucketMultipartList(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/bucketmultipartlist", bytes.NewBufferString(""))
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/bucketmultipartlist", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -714,7 +851,7 @@ func (s *MyAPIDonutCacheSuite) TestBucketMultipartList(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, 200)
request, err = http.NewRequest("POST", testAPIDonutCacheServer.URL+"/bucketmultipartlist/object?uploads", bytes.NewBufferString(""))
request, err = s.newRequest("POST", testAPIDonutCacheServer.URL+"/bucketmultipartlist/object?uploads", 0, nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
@ -728,21 +865,23 @@ func (s *MyAPIDonutCacheSuite) TestBucketMultipartList(c *C) {
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
uploadID := newResponse.UploadID
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
buffer1 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=1", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
response1, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response1.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
buffer2 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=2", int64(buffer2.Len()), buffer2)
c.Assert(err, IsNil)
response2, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response2.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/bucketmultipartlist?uploads", nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/bucketmultipartlist?uploads", 0, nil)
c.Assert(err, IsNil)
response3, err := client.Do(request)
@ -757,7 +896,7 @@ func (s *MyAPIDonutCacheSuite) TestBucketMultipartList(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestObjectMultipartList(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartlist", bytes.NewBufferString(""))
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartlist", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -765,7 +904,7 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipartList(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, 200)
request, err = http.NewRequest("POST", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?uploads", bytes.NewBufferString(""))
request, err = s.newRequest("POST", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?uploads", 0, nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
@ -779,28 +918,30 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipartList(c *C) {
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
uploadID := newResponse.UploadID
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
buffer1 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=1", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
response1, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response1.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
buffer2 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=2", int64(buffer2.Len()), buffer2)
c.Assert(err, IsNil)
response2, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response2.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?uploadId="+uploadID, nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?uploadId="+uploadID, 0, nil)
c.Assert(err, IsNil)
response3, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response3.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?max-parts=-2&uploadId="+uploadID, nil)
request, err = s.newRequest("GET", testAPIDonutCacheServer.URL+"/objectmultipartlist/object?max-parts=-2&uploadId="+uploadID, 0, nil)
c.Assert(err, IsNil)
response4, err := client.Do(request)
@ -809,7 +950,7 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipartList(c *C) {
}
func (s *MyAPIDonutCacheSuite) TestObjectMultipart(c *C) {
request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultiparts", nil)
request, err := s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultiparts", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
@ -817,7 +958,7 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipart(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, 200)
request, err = http.NewRequest("POST", testAPIDonutCacheServer.URL+"/objectmultiparts/object?uploads", nil)
request, err = s.newRequest("POST", testAPIDonutCacheServer.URL+"/objectmultiparts/object?uploads", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
@ -833,7 +974,8 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipart(c *C) {
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
uploadID := newResponse.UploadID
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
buffer1 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=1", int64(buffer1.Len()), buffer1)
c.Assert(err, IsNil)
client = http.Client{}
@ -841,7 +983,8 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipart(c *C) {
c.Assert(err, IsNil)
c.Assert(response1.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
buffer2 := bytes.NewReader([]byte("hello world"))
request, err = s.newRequest("PUT", testAPIDonutCacheServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=2", int64(buffer2.Len()), buffer2)
c.Assert(err, IsNil)
client = http.Client{}
@ -863,26 +1006,15 @@ func (s *MyAPIDonutCacheSuite) TestObjectMultipart(c *C) {
},
}
var completeBuffer bytes.Buffer
encoder := xml.NewEncoder(&completeBuffer)
encoder.Encode(completeUploads)
completeBytes, err := xml.Marshal(completeUploads)
c.Assert(err, IsNil)
request, err = http.NewRequest("POST", testAPIDonutCacheServer.URL+"/objectmultiparts/object?uploadId="+uploadID, &completeBuffer)
request, err = s.newRequest("POST", testAPIDonutCacheServer.URL+"/objectmultiparts/object?uploadId="+uploadID, int64(len(completeBytes)), bytes.NewReader(completeBytes))
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/objectmultiparts/object", nil)
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
object, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(string(object), Equals, ("hello worldhello world"))
}
func verifyError(c *C, response *http.Response, code, description string, statusCode int) {

View File

@ -27,6 +27,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"time"
"unicode/utf8"
@ -52,6 +53,22 @@ var _ = Suite(&MyAPISignatureV4Suite{})
var testSignatureV4Server *httptest.Server
// create a dummy TestNodeDiskMap
func createTestNodeDiskMap(p string) map[string][]string {
nodes := make(map[string][]string)
nodes["localhost"] = make([]string, 16)
for i := 0; i < len(nodes["localhost"]); i++ {
diskPath := filepath.Join(p, strconv.Itoa(i))
if _, err := os.Stat(diskPath); err != nil {
if os.IsNotExist(err) {
os.MkdirAll(diskPath, 0700)
}
}
nodes["localhost"][i] = diskPath
}
return nodes
}
func (s *MyAPISignatureV4Suite) SetUpSuite(c *C) {
root, err := ioutil.TempDir(os.TempDir(), "api-")
c.Assert(err, IsNil)
@ -85,8 +102,8 @@ func (s *MyAPISignatureV4Suite) SetUpSuite(c *C) {
perr = SaveConfig(authConf)
c.Assert(perr, IsNil)
minioAPI := getNewAPI()
httpHandler := getAPIHandler(minioAPI)
minioAPI := getNewAPI(false)
httpHandler := getAPIHandler(false, minioAPI)
go startTM(minioAPI)
testSignatureV4Server = httptest.NewServer(httpHandler)
}
@ -330,7 +347,7 @@ func (s *MyAPISignatureV4Suite) newRequest(method, urlStr string, contentLength
}
func (s *MyAPISignatureV4Suite) TestDeleteBucket(c *C) {
request, err := http.NewRequest("DELETE", testSignatureV4Server.URL+"/mybucket", nil)
request, err := s.newRequest("DELETE", testSignatureV4Server.URL+"/mybucket", 0, nil)
c.Assert(err, IsNil)
client := &http.Client{}
@ -340,7 +357,7 @@ func (s *MyAPISignatureV4Suite) TestDeleteBucket(c *C) {
}
func (s *MyAPISignatureV4Suite) TestDeleteObject(c *C) {
request, err := http.NewRequest("DELETE", testSignatureV4Server.URL+"/mybucket/myobject", nil)
request, err := s.newRequest("DELETE", testSignatureV4Server.URL+"/mybucket/myobject", 0, nil)
c.Assert(err, IsNil)
client := &http.Client{}
response, err := client.Do(request)
@ -807,7 +824,7 @@ func (s *MyAPISignatureV4Suite) TestListObjectsHandlerErrors(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testSignatureV4Server.URL+"/objecthandlererrors?max-keys=-2", nil)
request, err = s.newRequest("GET", testSignatureV4Server.URL+"/objecthandlererrors?max-keys=-2", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
@ -1059,7 +1076,7 @@ func (s *MyAPISignatureV4Suite) TestObjectMultipartList(c *C) {
c.Assert(err, IsNil)
c.Assert(response3.StatusCode, Equals, http.StatusOK)
request, err = http.NewRequest("GET", testSignatureV4Server.URL+"/objectmultipartlist/object?max-parts=-2&uploadId="+uploadID, nil)
request, err = s.newRequest("GET", testSignatureV4Server.URL+"/objectmultipartlist/object?max-parts=-2&uploadId="+uploadID, 0, nil)
c.Assert(err, IsNil)
response4, err := client.Do(request)