diff --git a/cmd/server_test.go b/cmd/server_test.go index 67bb54aa2..b62d21cba 100644 --- a/cmd/server_test.go +++ b/cmd/server_test.go @@ -42,13 +42,17 @@ type TestSuiteCommon struct { endPoint string accessKey string secretKey string + signer signerType } // Init and run test on FS backend. -var _ = Suite(&TestSuiteCommon{serverType: "FS"}) +var _ = Suite(&TestSuiteCommon{serverType: "FS", signer: signerV4}) + +// Init and run test on FS backend with AWS signature v2. +var _ = Suite(&TestSuiteCommon{serverType: "FS", signer: signerV2}) // Init and run test on XL backend. -var _ = Suite(&TestSuiteCommon{serverType: "XL"}) +var _ = Suite(&TestSuiteCommon{serverType: "XL", signer: signerV4}) // Setting up the test suite. // Starting the Test server with temporary FS backend. @@ -81,8 +85,8 @@ func (s *TestSuiteCommon) TestBucketSQSNotification(c *C) { // generate a random bucket Name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -93,8 +97,8 @@ func (s *TestSuiteCommon) TestBucketSQSNotification(c *C) { // assert the http response status code. c.Assert(response.StatusCode, Equals, http.StatusOK) - request, err = newTestSignedRequestV4("PUT", getPutNotificationURL(s.endPoint, bucketName), - int64(len(bucketNotificationBuf)), bytes.NewReader([]byte(bucketNotificationBuf)), s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutNotificationURL(s.endPoint, bucketName), + int64(len(bucketNotificationBuf)), bytes.NewReader([]byte(bucketNotificationBuf)), s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -116,8 +120,8 @@ func (s *TestSuiteCommon) TestBucketPolicy(c *C) { // create the policy statement string with the randomly generated bucket name. bucketPolicyStr := fmt.Sprintf(bucketPolicyBuf, bucketName, bucketName) // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -128,8 +132,8 @@ func (s *TestSuiteCommon) TestBucketPolicy(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) /// Put a new bucket policy. - request, err = newTestSignedRequestV4("PUT", getPutPolicyURL(s.endPoint, bucketName), - int64(len(bucketPolicyStr)), bytes.NewReader([]byte(bucketPolicyStr)), s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutPolicyURL(s.endPoint, bucketName), + int64(len(bucketPolicyStr)), bytes.NewReader([]byte(bucketPolicyStr)), s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -139,8 +143,8 @@ func (s *TestSuiteCommon) TestBucketPolicy(c *C) { c.Assert(response.StatusCode, Equals, http.StatusNoContent) // Fetch the uploaded policy. - request, err = newTestSignedRequestV4("GET", getGetPolicyURL(s.endPoint, bucketName), 0, nil, - s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetPolicyURL(s.endPoint, bucketName), 0, nil, + s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -154,8 +158,8 @@ func (s *TestSuiteCommon) TestBucketPolicy(c *C) { c.Assert(bytes.Equal([]byte(bucketPolicyStr), bucketPolicyReadBuf), Equals, true) // Delete policy. - request, err = newTestSignedRequestV4("DELETE", getDeletePolicyURL(s.endPoint, bucketName), 0, nil, - s.accessKey, s.secretKey) + request, err = newTestSignedRequest("DELETE", getDeletePolicyURL(s.endPoint, bucketName), 0, nil, + s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -164,8 +168,8 @@ func (s *TestSuiteCommon) TestBucketPolicy(c *C) { c.Assert(response.StatusCode, Equals, http.StatusNoContent) // Verify if the policy was indeed deleted. - request, err = newTestSignedRequestV4("GET", getGetPolicyURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetPolicyURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -179,8 +183,8 @@ func (s *TestSuiteCommon) TestDeleteBucket(c *C) { bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -190,8 +194,8 @@ func (s *TestSuiteCommon) TestDeleteBucket(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // construct request to delete the bucket. - request, err = newTestSignedRequestV4("DELETE", getDeleteBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("DELETE", getDeleteBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -207,8 +211,8 @@ func (s *TestSuiteCommon) TestDeleteBucketNotEmpty(c *C) { bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -221,8 +225,8 @@ func (s *TestSuiteCommon) TestDeleteBucketNotEmpty(c *C) { // generate http request for an object upload. // "test-object" is the object name. objectName := "test-object" - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -235,8 +239,8 @@ func (s *TestSuiteCommon) TestDeleteBucketNotEmpty(c *C) { // constructing http request to delete the bucket. // making an attempt to delete an non-empty bucket. // expected to fail. - request, err = newTestSignedRequestV4("DELETE", getDeleteBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("DELETE", getDeleteBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -250,8 +254,8 @@ func (s *TestSuiteCommon) TestListenBucketNotificationHandler(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - req, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + req, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -267,9 +271,9 @@ func (s *TestSuiteCommon) TestListenBucketNotificationHandler(c *C) { validEvents := []string{"s3:ObjectCreated:*", "s3:ObjectRemoved:*"} invalidEvents := []string{"invalidEvent"} - req, err = newTestSignedRequestV4("GET", + req, err = newTestSignedRequest("GET", getListenBucketNotificationURL(s.endPoint, invalidBucket, []string{}, []string{}, []string{}), - 0, nil, s.accessKey, s.secretKey) + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -278,9 +282,9 @@ func (s *TestSuiteCommon) TestListenBucketNotificationHandler(c *C) { c.Assert(err, IsNil) verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest) - req, err = newTestSignedRequestV4("GET", + req, err = newTestSignedRequest("GET", getListenBucketNotificationURL(s.endPoint, bucketName, []string{}, []string{}, invalidEvents), - 0, nil, s.accessKey, s.secretKey) + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -289,9 +293,9 @@ func (s *TestSuiteCommon) TestListenBucketNotificationHandler(c *C) { c.Assert(err, IsNil) verifyError(c, response, "InvalidArgument", "A specified event is not supported for notifications.", http.StatusBadRequest) - req, err = newTestSignedRequestV4("GET", + req, err = newTestSignedRequest("GET", getListenBucketNotificationURL(s.endPoint, bucketName, []string{tooBigPrefix}, []string{}, validEvents), - 0, nil, s.accessKey, s.secretKey) + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -300,9 +304,9 @@ func (s *TestSuiteCommon) TestListenBucketNotificationHandler(c *C) { c.Assert(err, IsNil) verifyError(c, response, "InvalidArgument", "Size of filter rule value cannot exceed 1024 bytes in UTF-8 representation", http.StatusBadRequest) - req, err = newTestSignedRequestV4("GET", + req, err = newTestSignedRequest("GET", getListenBucketNotificationURL(s.endPoint, bucketName, []string{}, []string{}, validEvents), - 0, nil, s.accessKey, s.secretKey) + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) req.Header.Set("x-amz-content-sha256", "somethingElse") @@ -310,13 +314,15 @@ func (s *TestSuiteCommon) TestListenBucketNotificationHandler(c *C) { // execute the request. response, err = client.Do(req) c.Assert(err, IsNil) - verifyError(c, response, "XAmzContentSHA256Mismatch", "The provided 'x-amz-content-sha256' header does not match what was computed.", http.StatusBadRequest) + if s.signer == signerV4 { + verifyError(c, response, "XAmzContentSHA256Mismatch", "The provided 'x-amz-content-sha256' header does not match what was computed.", http.StatusBadRequest) + } // Change global value from 5 second to 100millisecond. globalSNSConnAlive = 100 * time.Millisecond - req, err = newTestSignedRequestV4("GET", + req, err = newTestSignedRequest("GET", getListenBucketNotificationURL(s.endPoint, bucketName, - []string{}, []string{}, validEvents), 0, nil, s.accessKey, s.secretKey) + []string{}, []string{}, validEvents), 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} // execute the request. @@ -326,9 +332,9 @@ func (s *TestSuiteCommon) TestListenBucketNotificationHandler(c *C) { // FIXME: uncomment this in future when we have a code to read notifications from. // go func() { // buf := bytes.NewReader(tooByte) - // rreq, rerr := newTestSignedRequestV4("GET", + // rreq, rerr := newTestSignedRequest("GET", // getPutObjectURL(s.endPoint, bucketName, "myobject/1"), - // int64(buf.Len()), buf, s.accessKey, s.secretKey) + // int64(buf.Len()), buf, s.accessKey, s.secretKey, s.signer) // c.Assert(rerr, IsNil) // client = http.Client{} // // execute the request. @@ -344,8 +350,8 @@ func (s *TestSuiteCommon) TestDeleteMultipleObjects(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -363,8 +369,8 @@ func (s *TestSuiteCommon) TestDeleteMultipleObjects(c *C) { // Obtain http request to upload object. // object Name contains a prefix. objName := fmt.Sprintf("%d/%s", i, objectName) - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -383,8 +389,8 @@ func (s *TestSuiteCommon) TestDeleteMultipleObjects(c *C) { c.Assert(err, IsNil) // Delete list of objects. - request, err = newTestSignedRequestV4("POST", getMultiDeleteObjectURL(s.endPoint, bucketName), - int64(len(deleteReqBytes)), bytes.NewReader(deleteReqBytes), s.accessKey, s.secretKey) + request, err = newTestSignedRequest("POST", getMultiDeleteObjectURL(s.endPoint, bucketName), + int64(len(deleteReqBytes)), bytes.NewReader(deleteReqBytes), s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} response, err = client.Do(request) @@ -404,8 +410,8 @@ func (s *TestSuiteCommon) TestDeleteMultipleObjects(c *C) { // Attempt second time results should be same, NoSuchKey for objects not found // shouldn't be set. - request, err = newTestSignedRequestV4("POST", getMultiDeleteObjectURL(s.endPoint, bucketName), - int64(len(deleteReqBytes)), bytes.NewReader(deleteReqBytes), s.accessKey, s.secretKey) + request, err = newTestSignedRequest("POST", getMultiDeleteObjectURL(s.endPoint, bucketName), + int64(len(deleteReqBytes)), bytes.NewReader(deleteReqBytes), s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} response, err = client.Do(request) @@ -428,8 +434,8 @@ func (s *TestSuiteCommon) TestDeleteObject(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -442,8 +448,8 @@ func (s *TestSuiteCommon) TestDeleteObject(c *C) { objectName := "prefix/myobject" // obtain http request to upload object. // object Name contains a prefix. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -455,8 +461,8 @@ func (s *TestSuiteCommon) TestDeleteObject(c *C) { // object name was "prefix/myobject", an attempt to delelte "prefix" // Should not delete "prefix/myobject" - request, err = newTestSignedRequestV4("DELETE", getDeleteObjectURL(s.endPoint, bucketName, "prefix"), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("DELETE", getDeleteObjectURL(s.endPoint, bucketName, "prefix"), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} response, err = client.Do(request) @@ -465,8 +471,8 @@ func (s *TestSuiteCommon) TestDeleteObject(c *C) { // create http request to HEAD on the object. // this helps to validate the existence of the bucket. - request, err = newTestSignedRequestV4("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -476,8 +482,8 @@ func (s *TestSuiteCommon) TestDeleteObject(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // create HTTP request to delete the object. - request, err = newTestSignedRequestV4("DELETE", getDeleteObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("DELETE", getDeleteObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} // execute the http request. @@ -487,8 +493,8 @@ func (s *TestSuiteCommon) TestDeleteObject(c *C) { c.Assert(response.StatusCode, Equals, http.StatusNoContent) // Delete of non-existent data should return success. - request, err = newTestSignedRequestV4("DELETE", getDeleteObjectURL(s.endPoint, bucketName, "prefix/myobject1"), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("DELETE", getDeleteObjectURL(s.endPoint, bucketName, "prefix/myobject1"), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} // execute the http request. @@ -504,8 +510,8 @@ func (s *TestSuiteCommon) TestNonExistentBucket(c *C) { bucketName := getRandomBucketName() // create request to HEAD on the bucket. // HEAD on an bucket helps validate the existence of the bucket. - request, err := newTestSignedRequestV4("HEAD", getHEADBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("HEAD", getHEADBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -521,8 +527,8 @@ func (s *TestSuiteCommon) TestEmptyObject(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -534,8 +540,8 @@ func (s *TestSuiteCommon) TestEmptyObject(c *C) { objectName := "test-object" // construct http request for uploading the object. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -546,8 +552,8 @@ func (s *TestSuiteCommon) TestEmptyObject(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // make HTTP request to fetch the object. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -569,8 +575,8 @@ func (s *TestSuiteCommon) TestBucket(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -578,8 +584,8 @@ func (s *TestSuiteCommon) TestBucket(c *C) { c.Assert(err, IsNil) c.Assert(response.StatusCode, Equals, http.StatusOK) - request, err = newTestSignedRequestV4("HEAD", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("HEAD", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -594,8 +600,8 @@ func (s *TestSuiteCommon) TestObjectGetAnonymous(c *C) { bucketName := getRandomBucketName() buffer := bytes.NewReader([]byte("hello world")) // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -607,8 +613,8 @@ func (s *TestSuiteCommon) TestObjectGetAnonymous(c *C) { objectName := "testObject" // create HTTP request to upload the object. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer.Len()), buffer, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer.Len()), buffer, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -637,8 +643,8 @@ func (s *TestSuiteCommon) TestObjectGet(c *C) { bucketName := getRandomBucketName() buffer := bytes.NewReader([]byte("hello world")) // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -650,8 +656,8 @@ func (s *TestSuiteCommon) TestObjectGet(c *C) { objectName := "testObject" // create HTTP request to upload the object. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer.Len()), buffer, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer.Len()), buffer, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -668,8 +674,8 @@ func (s *TestSuiteCommon) TestObjectGet(c *C) { defer wg.Done() // HTTP request to create the bucket. // create HTTP request to fetch the object. - getRequest, err := newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + getRequest, err := newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) reqClient := http.Client{} @@ -696,8 +702,8 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -709,8 +715,8 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *C) { // constructing HTTP request to fetch a non-existent object. // expected to fail, error response asserted for expected error values later. objectName := "testObject" - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -724,8 +730,8 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *C) { // content for the object to be uploaded. buffer1 := bytes.NewReader([]byte("hello one")) // create HTTP request for the object upload. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -736,8 +742,8 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // create HTTP request to fetch the object which was uploaded above. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -756,8 +762,8 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *C) { // data for new object to be uploaded. buffer2 := bytes.NewReader([]byte("hello two")) objectName = "testObject2" - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -767,8 +773,8 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *C) { // assert the response status code for expected value 200 OK. c.Assert(response.StatusCode, Equals, http.StatusOK) // fetch the object which was uploaded above. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -786,8 +792,8 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *C) { // data for new object to be uploaded. buffer3 := bytes.NewReader([]byte("hello three")) objectName = "testObject3" - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer3.Len()), buffer3, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer3.Len()), buffer3, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -798,8 +804,8 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // fetch the object which was uploaded above. - request, err = newTestSignedRequestV4("GET", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getPutObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -817,8 +823,8 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *C) { func (s *TestSuiteCommon) TestNotImplemented(c *C) { // Generate a random bucket name. bucketName := getRandomBucketName() - request, err := newTestSignedRequestV4("GET", s.endPoint+"/"+bucketName+"/object?policy", - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("GET", s.endPoint+"/"+bucketName+"/object?policy", + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -832,8 +838,8 @@ func (s *TestSuiteCommon) TestHeader(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // obtain HTTP request to fetch an object from non-existent bucket/object. - request, err := newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, "testObject"), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, "testObject"), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -856,8 +862,8 @@ func (s *TestSuiteCommon) TestPutBucket(c *C) { go func() { defer wg.Done() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -873,8 +879,8 @@ func (s *TestSuiteCommon) TestPutBucket(c *C) { bucketName = getRandomBucketName() //Block 2: testing for correctness of the functionality // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -894,8 +900,8 @@ func (s *TestSuiteCommon) TestCopyObject(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -908,9 +914,13 @@ func (s *TestSuiteCommon) TestCopyObject(c *C) { buffer1 := bytes.NewReader([]byte("hello world")) objectName := "testObject" // create HTTP request for object upload. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) request.Header.Set("Content-Type", "application/json") + if s.signer == signerV2 { + c.Assert(err, IsNil) + err = signRequestV2(request, s.accessKey, s.secretKey) + } c.Assert(err, IsNil) // execute the HTTP request for object upload. response, err = client.Do(request) @@ -924,7 +934,11 @@ func (s *TestSuiteCommon) TestCopyObject(c *C) { c.Assert(err, IsNil) // setting the "X-Amz-Copy-Source" to allow copying the content of previously uploaded object. request.Header.Set("X-Amz-Copy-Source", url.QueryEscape("/"+bucketName+"/"+objectName)) - err = signRequestV4(request, s.accessKey, s.secretKey) + if s.signer == signerV4 { + err = signRequestV4(request, s.accessKey, s.secretKey) + } else { + err = signRequestV2(request, s.accessKey, s.secretKey) + } c.Assert(err, IsNil) // execute the HTTP request. // the content is expected to have the content of previous disk. @@ -933,8 +947,8 @@ func (s *TestSuiteCommon) TestCopyObject(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // creating HTTP request to fetch the previously uploaded object. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName2), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName2), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // executing the HTTP request. response, err = client.Do(request) @@ -953,8 +967,8 @@ func (s *TestSuiteCommon) TestPutObject(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -967,8 +981,8 @@ func (s *TestSuiteCommon) TestPutObject(c *C) { buffer1 := bytes.NewReader([]byte("hello world")) objectName := "testObject" // creating HTTP request for object upload. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request for object upload. response, err = client.Do(request) @@ -976,8 +990,8 @@ func (s *TestSuiteCommon) TestPutObject(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // fetch the object back and verify its contents. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request to fetch the object. response, err = client.Do(request) @@ -999,8 +1013,8 @@ func (s *TestSuiteCommon) TestPutObject(c *C) { // Its success verifies the format of the response. func (s *TestSuiteCommon) TestListBuckets(c *C) { // create HTTP request for listing buckets. - request, err := newTestSignedRequestV4("GET", getListBucketURL(s.endPoint), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("GET", getListBucketURL(s.endPoint), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1022,8 +1036,8 @@ func (s *TestSuiteCommon) TestValidateSignature(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1038,7 +1052,7 @@ func (s *TestSuiteCommon) TestValidateSignature(c *C) { // Create new HTTP request with incorrect secretKey to generate an incorrect signature. secretKey := s.secretKey + "a" - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objName), 0, nil, s.accessKey, secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objName), 0, nil, s.accessKey, secretKey, s.signer) c.Assert(err, IsNil) response, err = client.Do(request) c.Assert(err, IsNil) @@ -1050,8 +1064,8 @@ func (s *TestSuiteCommon) TestSHA256Mismatch(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1065,15 +1079,19 @@ func (s *TestSuiteCommon) TestSHA256Mismatch(c *C) { // Body is on purpose set to nil so that we get payload generated for empty bytes. // Create new HTTP request with incorrect secretKey to generate an incorrect signature. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objName), 0, nil, s.accessKey, s.secretKey) - c.Assert(request.Header.Get("x-amz-content-sha256"), Equals, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objName), 0, nil, s.accessKey, s.secretKey, s.signer) + if s.signer == signerV4 { + c.Assert(request.Header.Get("x-amz-content-sha256"), Equals, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") + } // Set the body to generate signature mismatch. request.Body = ioutil.NopCloser(bytes.NewReader([]byte("Hello, World"))) c.Assert(err, IsNil) // execute the HTTP request. response, err = client.Do(request) c.Assert(err, IsNil) - verifyError(c, response, "XAmzContentSHA256Mismatch", "The provided 'x-amz-content-sha256' header does not match what was computed.", http.StatusBadRequest) + if s.signer == signerV4 { + verifyError(c, response, "XAmzContentSHA256Mismatch", "The provided 'x-amz-content-sha256' header does not match what was computed.", http.StatusBadRequest) + } } // TestNotBeAbleToCreateObjectInNonexistentBucket - Validates the error response @@ -1082,8 +1100,8 @@ func (s *TestSuiteCommon) TestPutObjectLongName(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1096,8 +1114,8 @@ func (s *TestSuiteCommon) TestPutObjectLongName(c *C) { // make long object name. longObjName := fmt.Sprintf("%0255d/%0255d/%0255d", 1, 1, 1) // create new HTTP request to insert the object. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, longObjName), - int64(buffer.Len()), buffer, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, longObjName), + int64(buffer.Len()), buffer, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request. response, err = client.Do(request) @@ -1106,8 +1124,8 @@ func (s *TestSuiteCommon) TestPutObjectLongName(c *C) { // make long object name. longObjName = fmt.Sprintf("%0256d", 1) buffer = bytes.NewReader([]byte("hello world")) - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, longObjName), - int64(buffer.Len()), buffer, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, longObjName), + int64(buffer.Len()), buffer, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) response, err = client.Do(request) @@ -1125,8 +1143,8 @@ func (s *TestSuiteCommon) TestNotBeAbleToCreateObjectInNonexistentBucket(c *C) { // preparing for upload by generating the upload URL. objectName := "test-object" - request, err := newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1147,8 +1165,8 @@ func (s *TestSuiteCommon) TestHeadOnObjectLastModified(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1162,8 +1180,8 @@ func (s *TestSuiteCommon) TestHeadOnObjectLastModified(c *C) { // content for the object to be uploaded. buffer1 := bytes.NewReader([]byte("hello world")) // obtaining URL for uploading the object. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // executing the HTTP request to download the object. @@ -1171,8 +1189,8 @@ func (s *TestSuiteCommon) TestHeadOnObjectLastModified(c *C) { c.Assert(err, IsNil) c.Assert(response.StatusCode, Equals, http.StatusOK) // make HTTP request to obtain object info. - request, err = newTestSignedRequestV4("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request. response, err = client.Do(request) @@ -1189,8 +1207,8 @@ func (s *TestSuiteCommon) TestHeadOnObjectLastModified(c *C) { // make HTTP request to obtain object info. // But this time set the "If-Modified-Since" header to be 10 minute more than the actual // last modified time of the object. - request, err = newTestSignedRequestV4("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) request.Header.Set("If-Modified-Since", t.Add(10*time.Minute).UTC().Format(http.TimeFormat)) response, err = client.Do(request) @@ -1202,8 +1220,8 @@ func (s *TestSuiteCommon) TestHeadOnObjectLastModified(c *C) { // Again, obtain the object info. // This time setting "If-Unmodified-Since" to a time after the object is modified. // As documented above, expecting http.StatusPreconditionFailed. - request, err = newTestSignedRequestV4("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) request.Header.Set("If-Unmodified-Since", t.Add(-10*time.Minute).UTC().Format(http.TimeFormat)) response, err = client.Do(request) @@ -1217,8 +1235,8 @@ func (s *TestSuiteCommon) TestHeadOnBucket(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getHEADBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getHEADBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1227,8 +1245,8 @@ func (s *TestSuiteCommon) TestHeadOnBucket(c *C) { c.Assert(err, IsNil) c.Assert(response.StatusCode, Equals, http.StatusOK) // make HEAD request on the bucket. - request, err = newTestSignedRequestV4("HEAD", getHEADBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("HEAD", getHEADBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request. response, err = client.Do(request) @@ -1243,8 +1261,8 @@ func (s *TestSuiteCommon) TestContentTypePersists(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1258,10 +1276,14 @@ func (s *TestSuiteCommon) TestContentTypePersists(c *C) { buffer1 := bytes.NewReader([]byte("hello world")) objectName := "test-object.png" // constructing HTTP request for object upload. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) request.Header.Set("Content-Type", "image/png") + if s.signer == signerV2 { + err = signRequestV2(request, s.accessKey, s.secretKey) + c.Assert(err, IsNil) + } client = http.Client{} // execute the HTTP request for object upload. @@ -1270,8 +1292,8 @@ func (s *TestSuiteCommon) TestContentTypePersists(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // Fetching the object info using HEAD request for the object which was uploaded above. - request, err = newTestSignedRequestV4("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // Execute the HTTP request. @@ -1281,8 +1303,8 @@ func (s *TestSuiteCommon) TestContentTypePersists(c *C) { c.Assert(response.Header.Get("Content-Type"), Equals, "image/png") // Fetching the object itself and then verify the Content-Type header. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1296,11 +1318,15 @@ func (s *TestSuiteCommon) TestContentTypePersists(c *C) { // Uploading a new object with Content-Type "application/json". objectName = "test-object.json" buffer2 := bytes.NewReader([]byte("hello world")) - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // setting the request header to be application/json. request.Header.Set("Content-Type", "application/json") + if s.signer == signerV2 { + err = signRequestV2(request, s.accessKey, s.secretKey) + c.Assert(err, IsNil) + } // Execute the HTTP request to upload the object. response, err = client.Do(request) @@ -1308,8 +1334,8 @@ func (s *TestSuiteCommon) TestContentTypePersists(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // Obtain the info of the object which was uploaded above using HEAD request. - request, err = newTestSignedRequestV4("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // Execute the HTTP request. response, err = client.Do(request) @@ -1318,8 +1344,8 @@ func (s *TestSuiteCommon) TestContentTypePersists(c *C) { c.Assert(response.Header.Get("Content-Type"), Equals, "application/json") // Fetch the object and assert whether the Content-Type header persists. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // Execute the HTTP request. @@ -1335,8 +1361,8 @@ func (s *TestSuiteCommon) TestContentTypePersists(c *C) { func (s *TestSuiteCommon) TestPartialContent(c *C) { bucketName := getRandomBucketName() - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1345,8 +1371,8 @@ func (s *TestSuiteCommon) TestPartialContent(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) buffer1 := bytes.NewReader([]byte("Hello World")) - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, "bar"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, "bar"), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1355,8 +1381,8 @@ func (s *TestSuiteCommon) TestPartialContent(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // Prepare request - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, "bar"), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, "bar"), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) request.Header.Add("Range", "bytes=6-7") @@ -1376,8 +1402,8 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1387,8 +1413,8 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) buffer1 := bytes.NewReader([]byte("Hello World")) - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, "bar"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, "bar"), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1397,8 +1423,8 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // create listObjectsV1 request with valid parameters - request, err = newTestSignedRequestV4("GET", getListObjectsV1URL(s.endPoint, bucketName, "1000"), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getListObjectsV1URL(s.endPoint, bucketName, "1000"), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} // execute the HTTP request. @@ -1411,8 +1437,8 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *C) { c.Assert(strings.Contains(string(getContent), "bar"), Equals, true) // create listObjectsV2 request with valid parameters - request, err = newTestSignedRequestV4("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", ""), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", ""), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} // execute the HTTP request. @@ -1426,8 +1452,8 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *C) { c.Assert(strings.Contains(string(getContent), ""), Equals, true) // create listObjectsV2 request with valid parameters and fetch-owner activated - request, err = newTestSignedRequestV4("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", "true"), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", "true"), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} // execute the HTTP request. @@ -1449,8 +1475,8 @@ func (s *TestSuiteCommon) TestListObjectsHandlerErrors(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1460,8 +1486,8 @@ func (s *TestSuiteCommon) TestListObjectsHandlerErrors(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // create listObjectsV1 request with invalid value of max-keys parameter. max-keys is set to -2. - request, err = newTestSignedRequestV4("GET", getListObjectsV1URL(s.endPoint, bucketName, "-2"), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getListObjectsV1URL(s.endPoint, bucketName, "-2"), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} // execute the HTTP request. @@ -1471,8 +1497,8 @@ func (s *TestSuiteCommon) TestListObjectsHandlerErrors(c *C) { verifyError(c, response, "InvalidArgument", "Argument maxKeys must be an integer between 0 and 2147483647", http.StatusBadRequest) // create listObjectsV2 request with invalid value of max-keys parameter. max-keys is set to -2. - request, err = newTestSignedRequestV4("GET", getListObjectsV2URL(s.endPoint, bucketName, "-2", ""), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "-2", ""), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} // execute the HTTP request. @@ -1490,8 +1516,8 @@ func (s *TestSuiteCommon) TestPutBucketErrors(c *C) { bucketName := getRandomBucketName() // generating a HTTP request to create bucket. // using invalid bucket name. - request, err := newTestSignedRequestV4("PUT", s.endPoint+"/putbucket-.", - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", s.endPoint+"/putbucket-.", + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1500,8 +1526,8 @@ func (s *TestSuiteCommon) TestPutBucketErrors(c *C) { // expected to fail with error message "InvalidBucketName". verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest) // HTTP request to create the bucket. - request, err = newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1511,8 +1537,8 @@ func (s *TestSuiteCommon) TestPutBucketErrors(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // make HTTP request to create the same bucket again. // expected to fail with error message "BucketAlreadyOwnedByYou". - request, err = newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) response, err = client.Do(request) @@ -1522,8 +1548,8 @@ func (s *TestSuiteCommon) TestPutBucketErrors(c *C) { // request for ACL. // Since Minio server doesn't support ACL's the request is expected to fail with "NotImplemented" error message. - request, err = newTestSignedRequestV4("PUT", s.endPoint+"/"+bucketName+"?acl", - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", s.endPoint+"/"+bucketName+"?acl", + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) response, err = client.Do(request) @@ -1535,8 +1561,8 @@ func (s *TestSuiteCommon) TestGetObjectLarge10MiB(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // form HTTP reqest to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1565,8 +1591,8 @@ func (s *TestSuiteCommon) TestGetObjectLarge10MiB(c *C) { objectName := "test-big-object" // create HTTP request for object upload. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buf.Len()), buf, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1577,8 +1603,8 @@ func (s *TestSuiteCommon) TestGetObjectLarge10MiB(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // prepare HTTP requests to download the object. - request, err = newTestSignedRequestV4("GET", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getPutObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1599,8 +1625,8 @@ func (s *TestSuiteCommon) TestGetObjectLarge11MiB(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1630,8 +1656,8 @@ func (s *TestSuiteCommon) TestGetObjectLarge11MiB(c *C) { // Put object buf := bytes.NewReader(buffer.Bytes()) // create HTTP request foe object upload. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buf.Len()), buf, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1641,8 +1667,8 @@ func (s *TestSuiteCommon) TestGetObjectLarge11MiB(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // create HTTP request to download the object. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1668,8 +1694,8 @@ func (s *TestSuiteCommon) TestGetPartialObjectMisAligned(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1700,8 +1726,8 @@ func (s *TestSuiteCommon) TestGetPartialObjectMisAligned(c *C) { objectName := "test-big-file" // HTTP request to upload the object. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buf.Len()), buf, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1730,8 +1756,8 @@ func (s *TestSuiteCommon) TestGetPartialObjectMisAligned(c *C) { } for _, t := range testCases { // HTTP request to download the object. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // Get partial content based on the byte range set. request.Header.Add("Range", "bytes="+t.byteRange) @@ -1756,8 +1782,8 @@ func (s *TestSuiteCommon) TestGetPartialObjectLarge11MiB(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1788,8 +1814,8 @@ func (s *TestSuiteCommon) TestGetPartialObjectLarge11MiB(c *C) { buf := bytes.NewReader([]byte(putContent)) // HTTP request to upload the object. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buf.Len()), buf, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1799,8 +1825,8 @@ func (s *TestSuiteCommon) TestGetPartialObjectLarge11MiB(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // HTTP request to download the object. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // This range spans into first two blocks. request.Header.Add("Range", "bytes=10485750-10485769") @@ -1824,8 +1850,8 @@ func (s *TestSuiteCommon) TestGetPartialObjectLarge10MiB(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1857,8 +1883,8 @@ func (s *TestSuiteCommon) TestGetPartialObjectLarge10MiB(c *C) { objectName := "test-big-10Mb-file" // HTTP request to upload the object. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buf.Len()), buf, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1869,8 +1895,8 @@ func (s *TestSuiteCommon) TestGetPartialObjectLarge10MiB(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // HTTP request to download the object. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // Get partial content based on the byte range set. request.Header.Add("Range", "bytes=2048-2058") @@ -1895,8 +1921,8 @@ func (s *TestSuiteCommon) TestGetObjectErrors(c *C) { bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1909,8 +1935,8 @@ func (s *TestSuiteCommon) TestGetObjectErrors(c *C) { // HTTP request to download the object. // Since the specified object doesn't exist in the given bucket, // expected to fail with error message "NoSuchKey" - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1919,8 +1945,8 @@ func (s *TestSuiteCommon) TestGetObjectErrors(c *C) { verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound) // request to download an object, but an invalid bucket name is set. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, "/getobjecterrors-.", objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, "/getobjecterrors-.", objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request. @@ -1935,8 +1961,8 @@ func (s *TestSuiteCommon) TestGetObjectRangeErrors(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -1950,8 +1976,8 @@ func (s *TestSuiteCommon) TestGetObjectRangeErrors(c *C) { objectName := "test-object" // HTTP request to upload the object. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -1962,8 +1988,8 @@ func (s *TestSuiteCommon) TestGetObjectRangeErrors(c *C) { c.Assert(response.StatusCode, Equals, http.StatusOK) // HTTP request to download the object. - request, err = newTestSignedRequestV4("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) // Invalid byte range set. request.Header.Add("Range", "bytes=-0") c.Assert(err, IsNil) @@ -1981,8 +2007,8 @@ func (s *TestSuiteCommon) TestObjectMultipartAbort(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -2001,8 +2027,8 @@ func (s *TestSuiteCommon) TestObjectMultipartAbort(c *C) { // and the case where there is only one upload ID. // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV4("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request initiating the new multipart upload. @@ -2019,8 +2045,8 @@ func (s *TestSuiteCommon) TestObjectMultipartAbort(c *C) { c.Assert(len(newResponse.UploadID) > 0, Equals, true) // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV4("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request initiating the new multipart upload. @@ -2041,8 +2067,8 @@ func (s *TestSuiteCommon) TestObjectMultipartAbort(c *C) { // content for the part to be uploaded. buffer1 := bytes.NewReader([]byte("hello world")) // HTTP request for the part to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request to upload the first part. response1, err := client.Do(request) @@ -2052,16 +2078,16 @@ func (s *TestSuiteCommon) TestObjectMultipartAbort(c *C) { // content for the second part to be uploaded. buffer2 := bytes.NewReader([]byte("hello world")) // HTTP request for the second part to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), + int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request to upload the second part. response2, err := client.Do(request) c.Assert(err, IsNil) c.Assert(response2.StatusCode, Equals, http.StatusOK) // HTTP request for aborting the multipart upload. - request, err = newTestSignedRequestV4("DELETE", getAbortMultipartUploadURL(s.endPoint, bucketName, objectName, uploadID), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("DELETE", getAbortMultipartUploadURL(s.endPoint, bucketName, objectName, uploadID), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request to abort the multipart upload. response3, err := client.Do(request) @@ -2076,8 +2102,8 @@ func (s *TestSuiteCommon) TestBucketMultipartList(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), 0, - nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), 0, + nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -2088,8 +2114,8 @@ func (s *TestSuiteCommon) TestBucketMultipartList(c *C) { objectName := "test-multipart-object" // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV4("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request initiating the new multipart upload. response, err = client.Do(request) @@ -2110,8 +2136,8 @@ func (s *TestSuiteCommon) TestBucketMultipartList(c *C) { // content for the part to be uploaded. buffer1 := bytes.NewReader([]byte("hello world")) // HTTP request for the part to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request to upload the first part. response1, err := client.Do(request) @@ -2121,8 +2147,8 @@ func (s *TestSuiteCommon) TestBucketMultipartList(c *C) { // content for the second part to be uploaded. buffer2 := bytes.NewReader([]byte("hello world")) // HTTP request for the second part to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), + int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request to upload the second part. response2, err := client.Do(request) @@ -2130,8 +2156,8 @@ func (s *TestSuiteCommon) TestBucketMultipartList(c *C) { c.Assert(response2.StatusCode, Equals, http.StatusOK) // HTTP request to ListMultipart Uploads. - request, err = newTestSignedRequestV4("GET", getListMultipartURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getListMultipartURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request. response3, err := client.Do(request) @@ -2189,8 +2215,8 @@ func (s *TestSuiteCommon) TestValidateObjectMultipartUploadID(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -2201,8 +2227,8 @@ func (s *TestSuiteCommon) TestValidateObjectMultipartUploadID(c *C) { objectName := "directory1/directory2/object" // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV4("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request initiating the new multipart upload. response, err = client.Do(request) @@ -2225,8 +2251,8 @@ func (s *TestSuiteCommon) TestObjectMultipartListError(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -2237,8 +2263,8 @@ func (s *TestSuiteCommon) TestObjectMultipartListError(c *C) { objectName := "test-multipart-object" // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV4("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request initiating the new multipart upload. response, err = client.Do(request) @@ -2257,8 +2283,8 @@ func (s *TestSuiteCommon) TestObjectMultipartListError(c *C) { // content for the part to be uploaded. buffer1 := bytes.NewReader([]byte("hello world")) // HTTP request for the part to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request to upload the first part. response1, err := client.Do(request) @@ -2268,8 +2294,8 @@ func (s *TestSuiteCommon) TestObjectMultipartListError(c *C) { // content for the second part to be uploaded. buffer2 := bytes.NewReader([]byte("hello world")) // HTTP request for the second part to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), + int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request to upload the second part. @@ -2279,8 +2305,8 @@ func (s *TestSuiteCommon) TestObjectMultipartListError(c *C) { // HTTP request to ListMultipart Uploads. // max-keys is set to valid value of 1 - request, err = newTestSignedRequestV4("GET", getListMultipartURLWithParams(s.endPoint, bucketName, objectName, uploadID, "1", "", ""), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getListMultipartURLWithParams(s.endPoint, bucketName, objectName, uploadID, "1", "", ""), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request. response3, err := client.Do(request) @@ -2289,8 +2315,8 @@ func (s *TestSuiteCommon) TestObjectMultipartListError(c *C) { // HTTP request to ListMultipart Uploads. // max-keys is set to invalid value of -2. - request, err = newTestSignedRequestV4("GET", getListMultipartURLWithParams(s.endPoint, bucketName, objectName, uploadID, "-2", "", ""), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("GET", getListMultipartURLWithParams(s.endPoint, bucketName, objectName, uploadID, "-2", "", ""), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // execute the HTTP request. response4, err := client.Do(request) @@ -2306,8 +2332,8 @@ func (s *TestSuiteCommon) TestObjectValidMD5(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -2327,8 +2353,8 @@ func (s *TestSuiteCommon) TestObjectValidMD5(c *C) { buffer1 := bytes.NewReader(data) objectName := "test-1-object" // HTTP request for the object to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // set the Content-Md5 to be the hash to content. request.Header.Set("Content-Md5", base64.StdEncoding.EncodeToString(md5Sum)) @@ -2340,8 +2366,8 @@ func (s *TestSuiteCommon) TestObjectValidMD5(c *C) { objectName = "test-2-object" buffer1 = bytes.NewReader(data) // HTTP request for the object to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // set Content-Md5 to invalid value. request.Header.Set("Content-Md5", "kvLTlMrX9NpYDQlEIFlnDA==") @@ -2359,8 +2385,8 @@ func (s *TestSuiteCommon) TestObjectMultipart(c *C) { // generate a random bucket name. bucketName := getRandomBucketName() // HTTP request to create the bucket. - request, err := newTestSignedRequestV4("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) + request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client := http.Client{} @@ -2371,8 +2397,8 @@ func (s *TestSuiteCommon) TestObjectMultipart(c *C) { objectName := "test-multipart-object" // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV4("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), + 0, nil, s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) client = http.Client{} @@ -2401,8 +2427,8 @@ func (s *TestSuiteCommon) TestObjectMultipart(c *C) { buffer1 := bytes.NewReader(data) // HTTP request for the part to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), + int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, s.signer) // set the Content-Md5 header to the base64 encoding the md5Sum of the content. request.Header.Set("Content-Md5", base64.StdEncoding.EncodeToString(md5Sum)) c.Assert(err, IsNil) @@ -2424,8 +2450,8 @@ func (s *TestSuiteCommon) TestObjectMultipart(c *C) { buffer2 := bytes.NewReader(data) // HTTP request for the second part to be uploaded. - request, err = newTestSignedRequestV4("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) + request, err = newTestSignedRequest("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), + int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey, s.signer) // set the Content-Md5 header to the base64 encoding the md5Sum of the content. request.Header.Set("Content-Md5", base64.StdEncoding.EncodeToString(md5Sum)) c.Assert(err, IsNil) @@ -2453,8 +2479,8 @@ func (s *TestSuiteCommon) TestObjectMultipart(c *C) { completeBytes, err := xml.Marshal(completeUploads) c.Assert(err, IsNil) // Indicating that all parts are uploaded and initiating completeMultipartUpload. - request, err = newTestSignedRequestV4("POST", getCompleteMultipartUploadURL(s.endPoint, bucketName, objectName, uploadID), - int64(len(completeBytes)), bytes.NewReader(completeBytes), s.accessKey, s.secretKey) + request, err = newTestSignedRequest("POST", getCompleteMultipartUploadURL(s.endPoint, bucketName, objectName, uploadID), + int64(len(completeBytes)), bytes.NewReader(completeBytes), s.accessKey, s.secretKey, s.signer) c.Assert(err, IsNil) // Execute the complete multipart request. response, err = client.Do(request) diff --git a/cmd/server_v2_test.go b/cmd/server_v2_test.go deleted file mode 100644 index 2f7858aa0..000000000 --- a/cmd/server_v2_test.go +++ /dev/null @@ -1,2334 +0,0 @@ -/* - * Minio Cloud Storage, (C) 2015, 2016 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 cmd - -import ( - "bytes" - "crypto/md5" - "encoding/base64" - "encoding/hex" - "encoding/xml" - "fmt" - "io" - "io/ioutil" - "math/rand" - "net/http" - "net/url" - "strings" - "sync" - "time" - - . "gopkg.in/check.v1" -) - -// API suite container common to both FS and XL. -type TestSuiteCommonV2 struct { - serverType string - testServer TestServer - endPoint string - accessKey string - secretKey string -} - -// Init and run test on FS backend. -var _ = Suite(&TestSuiteCommonV2{serverType: "FS"}) - -// Setting up the test suite. -// Starting the Test server with temporary FS backend. -func (s *TestSuiteCommonV2) SetUpSuite(c *C) { - s.testServer = StartTestServer(c, s.serverType) - s.endPoint = s.testServer.Server.URL - s.accessKey = s.testServer.AccessKey - s.secretKey = s.testServer.SecretKey -} - -// Called implicitly by "gopkg.in/check.v1" after all tests are run. -func (s *TestSuiteCommonV2) TearDownSuite(c *C) { - s.testServer.Stop() -} - -func (s *TestSuiteCommonV2) TestAuth(c *C) { - secretID, err := genSecretAccessKey() - c.Assert(err, IsNil) - - accessID, err := genAccessKeyID() - c.Assert(err, IsNil) - - c.Assert(len(secretID), Equals, minioSecretID) - c.Assert(len(accessID), Equals, minioAccessID) -} - -func (s *TestSuiteCommonV2) TestBucketSQSNotification(c *C) { - // Sample bucket notification. - bucketNotificationBuf := `s3:ObjectCreated:Putprefiximages/1arn:minio:sqs:us-east-1:444455556666:amqp` - // generate a random bucket Name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the request. - response, err := client.Do(request) - c.Assert(err, IsNil) - - // assert the http response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - request, err = newTestSignedRequestV2("PUT", getPutNotificationURL(s.endPoint, bucketName), - int64(len(bucketNotificationBuf)), bytes.NewReader([]byte(bucketNotificationBuf)), s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - - c.Assert(err, IsNil) - verifyError(c, response, "InvalidArgument", "A specified destination ARN does not exist or is not well-formed. Verify the destination ARN.", http.StatusBadRequest) -} - -// TestBucketPolicy - Inserts the bucket policy and verifies it by fetching the policy back. -// Deletes the policy and verifies the deletion by fetching it back. -func (s *TestSuiteCommonV2) TestBucketPolicy(c *C) { - // Sample bucket policy. - bucketPolicyBuf := `{"Version":"2012-10-17","Statement":[{"Action":["s3:GetBucketLocation","s3:ListBucket"],"Effect":"Allow","Principal":{"AWS":["*"]},"Resource":["arn:aws:s3:::%s"],"Sid":""},{"Action":["s3:GetObject"],"Effect":"Allow","Principal":{"AWS":["*"]},"Resource":["arn:aws:s3:::%s/this*"],"Sid":""}]}` - - // generate a random bucket Name. - bucketName := getRandomBucketName() - // create the policy statement string with the randomly generated bucket name. - bucketPolicyStr := fmt.Sprintf(bucketPolicyBuf, bucketName, bucketName) - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the request. - response, err := client.Do(request) - c.Assert(err, IsNil) - // assert the http response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - /// Put a new bucket policy. - request, err = newTestSignedRequestV2("PUT", getPutPolicyURL(s.endPoint, bucketName), - int64(len(bucketPolicyStr)), bytes.NewReader([]byte(bucketPolicyStr)), s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to create bucket. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusNoContent) - - // Fetch the uploaded policy. - request, err = newTestSignedRequestV2("GET", getGetPolicyURL(s.endPoint, bucketName), 0, nil, - s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - bucketPolicyReadBuf, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - // Verify if downloaded policy matches with previousy uploaded. - c.Assert(bytes.Equal([]byte(bucketPolicyStr), bucketPolicyReadBuf), Equals, true) - - // Delete policy. - request, err = newTestSignedRequestV2("DELETE", getDeletePolicyURL(s.endPoint, bucketName), 0, nil, - s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusNoContent) - - // Verify if the policy was indeed deleted. - request, err = newTestSignedRequestV2("GET", getGetPolicyURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusNotFound) -} - -// TestDeleteBucket - validates DELETE bucket operation. -func (s *TestSuiteCommonV2) TestDeleteBucket(c *C) { - bucketName := getRandomBucketName() - - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - response, err := client.Do(request) - c.Assert(err, IsNil) - // assert the response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // construct request to delete the bucket. - request, err = newTestSignedRequestV2("DELETE", getDeleteBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - // Assert the response status code. - c.Assert(response.StatusCode, Equals, http.StatusNoContent) -} - -// TestDeleteBucketNotEmpty - Validates the operation during an attempt to delete a non-empty bucket. -func (s *TestSuiteCommonV2) TestDeleteBucketNotEmpty(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the request. - response, err := client.Do(request) - c.Assert(err, IsNil) - // assert the response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // generate http request for an object upload. - // "test-object" is the object name. - objectName := "test-object" - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the request to complete object upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the status code of the response. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // constructing http request to delete the bucket. - // making an attempt to delete an non-empty bucket. - // expected to fail. - request, err = newTestSignedRequestV2("DELETE", getDeleteBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusConflict) - -} - -// Test deletes multple objects and verifies server resonse. -func (s *TestSuiteCommonV2) TestDeleteMultipleObjects(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the request. - response, err := client.Do(request) - c.Assert(err, IsNil) - // assert the http response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - objectName := "prefix/myobject" - delObjReq := DeleteObjectsRequest{ - Quiet: false, - } - for i := 0; i < 10; i++ { - // Obtain http request to upload object. - // object Name contains a prefix. - objName := fmt.Sprintf("%d/%s", i, objectName) - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the http request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the status of http response. - c.Assert(response.StatusCode, Equals, http.StatusOK) - // Append all objects. - delObjReq.Objects = append(delObjReq.Objects, ObjectIdentifier{ - ObjectName: objName, - }) - } - // Marshal delete request. - deleteReqBytes, err := xml.Marshal(delObjReq) - c.Assert(err, IsNil) - - // Delete list of objects. - request, err = newTestSignedRequestV2("POST", getMultiDeleteObjectURL(s.endPoint, bucketName), - int64(len(deleteReqBytes)), bytes.NewReader(deleteReqBytes), s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - var deleteResp = DeleteObjectsResponse{} - delRespBytes, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - err = xml.Unmarshal(delRespBytes, &deleteResp) - c.Assert(err, IsNil) - for i := 0; i < 10; i++ { - // All the objects should be under deleted list (including non-existent object) - c.Assert(deleteResp.DeletedObjects[i], DeepEquals, delObjReq.Objects[i]) - } - c.Assert(len(deleteResp.Errors), Equals, 0) - - // Attempt second time results should be same, NoSuchKey for objects not found - // shouldn't be set. - request, err = newTestSignedRequestV2("POST", getMultiDeleteObjectURL(s.endPoint, bucketName), - int64(len(deleteReqBytes)), bytes.NewReader(deleteReqBytes), s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - deleteResp = DeleteObjectsResponse{} - delRespBytes, err = ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - err = xml.Unmarshal(delRespBytes, &deleteResp) - c.Assert(err, IsNil) - for i := 0; i < 10; i++ { - c.Assert(deleteResp.DeletedObjects[i], DeepEquals, delObjReq.Objects[i]) - } - c.Assert(len(deleteResp.Errors), Equals, 0) -} - -// Tests delete object responses and success. -func (s *TestSuiteCommonV2) TestDeleteObject(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the request. - response, err := client.Do(request) - c.Assert(err, IsNil) - // assert the http response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - objectName := "prefix/myobject" - // obtain http request to upload object. - // object Name contains a prefix. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the http request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the status of http response. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // object name was "prefix/myobject", an attempt to delelte "prefix" - // Should not delete "prefix/myobject" - request, err = newTestSignedRequestV2("DELETE", getDeleteObjectURL(s.endPoint, bucketName, "prefix"), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusNoContent) - - // create http request to HEAD on the object. - // this helps to validate the existence of the bucket. - request, err = newTestSignedRequestV2("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - // Assert the HTTP response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // create HTTP request to delete the object. - request, err = newTestSignedRequestV2("DELETE", getDeleteObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - // execute the http request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the http response status code. - c.Assert(response.StatusCode, Equals, http.StatusNoContent) - - // Delete of non-existent data should return success. - request, err = newTestSignedRequestV2("DELETE", getDeleteObjectURL(s.endPoint, bucketName, "prefix/myobject1"), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - // execute the http request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the http response status. - c.Assert(response.StatusCode, Equals, http.StatusNoContent) -} - -// TestNonExistentBucket - Asserts response for HEAD on non-existent bucket. -func (s *TestSuiteCommonV2) TestNonExistentBucket(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // create request to HEAD on the bucket. - // HEAD on an bucket helps validate the existence of the bucket. - request, err := newTestSignedRequestV2("HEAD", getHEADBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the http request. - response, err := client.Do(request) - c.Assert(err, IsNil) - // Assert the response. - c.Assert(response.StatusCode, Equals, http.StatusNotFound) -} - -// TestEmptyObject - Asserts the response for operation on a 0 byte object. -func (s *TestSuiteCommonV2) TestEmptyObject(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the http request. - response, err := client.Do(request) - c.Assert(err, IsNil) - // assert the http response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - objectName := "test-object" - // construct http request for uploading the object. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the upload request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the http response. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // make HTTP request to fetch the object. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the http request to fetch object. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the http response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - var buffer bytes.Buffer - // extract the body of the response. - responseBody, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - // assert the http response body content. - c.Assert(true, Equals, bytes.Equal(responseBody, buffer.Bytes())) -} - -func (s *TestSuiteCommonV2) TestBucket(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - 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 = newTestSignedRequestV2("HEAD", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) -} - -// Tests get anonymous object. -func (s *TestSuiteCommonV2) TestObjectGetAnonymous(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - buffer := bytes.NewReader([]byte("hello world")) - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the make bucket http request. - response, err := client.Do(request) - c.Assert(err, IsNil) - // assert the response http status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - objectName := "testObject" - // create HTTP request to upload the object. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer.Len()), buffer, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to upload the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the HTTP response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // initiate anonymous HTTP request to fetch the object which does not exist. We need to return AccessDenied. - response, err = http.Get(getGetObjectURL(s.endPoint, bucketName, objectName+".1")) - c.Assert(err, IsNil) - // assert the http response status code. - verifyError(c, response, "AccessDenied", "Access Denied.", http.StatusForbidden) - - // initiate anonymous HTTP request to fetch the object which does exist. We need to return AccessDenied. - response, err = http.Get(getGetObjectURL(s.endPoint, bucketName, objectName)) - c.Assert(err, IsNil) - // assert the http response status code. - verifyError(c, response, "AccessDenied", "Access Denied.", http.StatusForbidden) -} - -// TestGetObject - Tests fetching of a small object after its insertion into the bucket. -func (s *TestSuiteCommonV2) TestObjectGet(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - buffer := bytes.NewReader([]byte("hello world")) - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the make bucket http request. - response, err := client.Do(request) - c.Assert(err, IsNil) - // assert the response http status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - objectName := "testObject" - // create HTTP request to upload the object. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer.Len()), buffer, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to upload the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the HTTP response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - // concurrently reading the object, safety check for races. - var wg sync.WaitGroup - for i := 0; i < testConcurrencyLevel; i++ { - wg.Add(1) - go func() { - defer wg.Done() - // HTTP request to create the bucket. - // create HTTP request to fetch the object. - getRequest, err := newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - reqClient := http.Client{} - // execute the http request to fetch the object. - getResponse, err := reqClient.Do(getRequest) - c.Assert(err, IsNil) - defer getResponse.Body.Close() - // assert the http response status code. - c.Assert(getResponse.StatusCode, Equals, http.StatusOK) - - // extract response body content. - responseBody, err := ioutil.ReadAll(getResponse.Body) - c.Assert(err, IsNil) - // assert the HTTP response body content with the expected content. - c.Assert(responseBody, DeepEquals, []byte("hello world")) - }() - - } - wg.Wait() -} - -// TestMultipleObjects - Validates upload and fetching of multiple object into the bucket. -func (s *TestSuiteCommonV2) TestMultipleObjects(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create the bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // constructing HTTP request to fetch a non-existent object. - // expected to fail, error response asserted for expected error values later. - objectName := "testObject" - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // Asserting the error response with the expected values. - verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound) - - objectName = "testObject1" - // content for the object to be uploaded. - buffer1 := bytes.NewReader([]byte("hello one")) - // create HTTP request for the object upload. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request for object upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the returned values. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // create HTTP request to fetch the object which was uploaded above. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert whether 200 OK response status is obtained. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // extract the response body. - responseBody, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - // assert the content body for the expected object data. - c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello one"))) - - // data for new object to be uploaded. - buffer2 := bytes.NewReader([]byte("hello two")) - objectName = "testObject2" - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request for object upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the response status code for expected value 200 OK. - c.Assert(response.StatusCode, Equals, http.StatusOK) - // fetch the object which was uploaded above. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to fetch the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - // assert the response status code for expected value 200 OK. - 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"))) - - // data for new object to be uploaded. - buffer3 := bytes.NewReader([]byte("hello three")) - objectName = "testObject3" - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer3.Len()), buffer3, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // verify the response code with the expected value of 200 OK. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // fetch the object which was uploaded above. - request, err = newTestSignedRequestV2("GET", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - 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"))) -} - -// TestNotImplemented - validates if object policy is implemented, should return 'NotImplemented'. -func (s *TestSuiteCommonV2) TestNotImplemented(c *C) { - // Generate a random bucket name. - bucketName := getRandomBucketName() - request, err := newTestSignedRequestV2("GET", s.endPoint+"/"+bucketName+"/object?policy", - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusNotImplemented) -} - -// TestHeader - Validates the error response for an attempt to fetch non-existent object. -func (s *TestSuiteCommonV2) TestHeader(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // obtain HTTP request to fetch an object from non-existent bucket/object. - request, err := newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, "testObject"), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - response, err := client.Do(request) - c.Assert(err, IsNil) - // asserting for the expected error response. - verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist", http.StatusNotFound) -} - -func (s *TestSuiteCommonV2) TestPutBucket(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // Block 1: Testing for racey access - // The assertion is removed from this block since the purpose of this block is to find races - // The purpose this block is not to check for correctness of functionality - // Run the test with -race flag to utilize this - var wg sync.WaitGroup - for i := 0; i < testConcurrencyLevel; i++ { - wg.Add(1) - go func() { - defer wg.Done() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - response, err := client.Do(request) - if err != nil { - c.Fatalf("Put bucket Failed: %s", err) - } - defer response.Body.Close() - }() - } - wg.Wait() - - bucketName = getRandomBucketName() - //Block 2: testing for correctness of the functionality - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - response.Body.Close() -} - -// TestCopyObject - Validates copy object. -// The following is the test flow. -// 1. Create bucket. -// 2. Insert Object. -// 3. Use "X-Amz-Copy-Source" header to copy the previously created object. -// 4. Validate the content of copied object. -func (s *TestSuiteCommonV2) TestCopyObject(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // content for the object to be created. - buffer1 := bytes.NewReader([]byte("hello world")) - objectName := "testObject" - // create HTTP request for object upload. - request, err = newTestSignedRequestV2ContentType("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, "application/json") - c.Assert(err, IsNil) - // execute the HTTP request for object upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - objectName2 := "testObject2" - // Unlike the actual PUT object request, the request to Copy Object doesn't contain request body, - // empty body with the "X-Amz-Copy-Source" header pointing to the object to copies it in the backend. - request, err = newTestRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName2), 0, nil) - c.Assert(err, IsNil) - // setting the "X-Amz-Copy-Source" to allow copying the content of previously uploaded object. - request.Header.Set("X-Amz-Copy-Source", url.QueryEscape("/"+bucketName+"/"+objectName)) - err = signRequestV2(request, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request. - // the content is expected to have the content of previous disk. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // creating HTTP request to fetch the previously uploaded object. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName2), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // executing the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // validating the response status code. - c.Assert(response.StatusCode, Equals, http.StatusOK) - // reading the response body. - // response body is expected to have the copied content of the first uploaded object. - object, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - c.Assert(string(object), Equals, "hello world") -} - -// TestPutObject - Tests successful put object request. -func (s *TestSuiteCommonV2) TestPutObject(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // content for new object upload. - buffer1 := bytes.NewReader([]byte("hello world")) - objectName := "testObject" - // creating HTTP request for object upload. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request for object upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // fetch the object back and verify its contents. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request to fetch the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - c.Assert(response.ContentLength, Equals, int64(len([]byte("hello world")))) - var buffer2 bytes.Buffer - // retrive the contents of response body. - n, err := io.Copy(&buffer2, response.Body) - c.Assert(err, IsNil) - c.Assert(n, Equals, int64(len([]byte("hello world")))) - // asserted the contents of the fetched object with the expected result. - c.Assert(true, Equals, bytes.Equal(buffer2.Bytes(), []byte("hello world"))) - -} - -// TestListBuckets - Make request for listing of all buckets. -// XML response is parsed. -// Its success verifies the format of the response. -func (s *TestSuiteCommonV2) TestListBuckets(c *C) { - // create HTTP request for listing buckets. - request, err := newTestSignedRequestV2("GET", getListBucketURL(s.endPoint), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to list buckets. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - var results ListBucketsResponse - // parse the list bucket response. - decoder := xml.NewDecoder(response.Body) - err = decoder.Decode(&results) - // validating that the xml-decoding/parsing was successful. - c.Assert(err, IsNil) -} - -// This tests validate if PUT handler can successfully detect signature mismatch. -func (s *TestSuiteCommonV2) TestValidateSignature(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // Execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - objName := "test-object" - - // Body is on purpose set to nil so that we get payload generated for empty bytes. - - // Create new HTTP request with incorrect secretKey to generate an incorrect signature. - secretKey := s.secretKey + "a" - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objName), 0, nil, s.accessKey, secretKey) - c.Assert(err, IsNil) - response, err = client.Do(request) - c.Assert(err, IsNil) - verifyError(c, response, "SignatureDoesNotMatch", "The request signature we calculated does not match the signature you provided. Check your key and signing method.", http.StatusForbidden) -} - -// TestNotBeAbleToCreateObjectInNonexistentBucket - Validates the error response -// on an attempt to upload an object into a non-existent bucket. -func (s *TestSuiteCommonV2) TestPutObjectLongName(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // Execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - // Content for the object to be uploaded. - buffer := bytes.NewReader([]byte("hello world")) - // make long object name. - longObjName := fmt.Sprintf("%0255d/%0255d/%0255d", 1, 1, 1) - // create new HTTP request to insert the object. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, longObjName), - int64(buffer.Len()), buffer, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - // make long object name. - longObjName = fmt.Sprintf("%0256d", 1) - buffer = bytes.NewReader([]byte("hello world")) - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, longObjName), - int64(buffer.Len()), buffer, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - response, err = client.Do(request) - c.Assert(err, IsNil) - verifyError(c, response, "XMinioInvalidObjectName", "Object name contains unsupported characters. Unsupported characters are `^*|\\\"", http.StatusBadRequest) -} - -// TestNotBeAbleToCreateObjectInNonexistentBucket - Validates the error response -// on an attempt to upload an object into a non-existent bucket. -func (s *TestSuiteCommonV2) TestNotBeAbleToCreateObjectInNonexistentBucket(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // content of the object to be uploaded. - buffer1 := bytes.NewReader([]byte("hello world")) - - // preparing for upload by generating the upload URL. - objectName := "test-object" - request, err := newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // Execute the HTTP request. - response, err := client.Do(request) - c.Assert(err, IsNil) - // Assert the response error message. - verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist", http.StatusNotFound) -} - -// TestHeadOnObjectLastModified - Asserts response for HEAD on an object. -// HEAD requests on an object validates the existence of the object. -// The responses for fetching the object when If-Modified-Since -// and If-Unmodified-Since headers set are validated. -// If-Modified-Since - Return the object only if it has been modified since the specified time, else return a 304 (not modified). -// If-Unmodified-Since - Return the object only if it has not been modified since the specified time, else return a 412 (precondition failed). -func (s *TestSuiteCommonV2) TestHeadOnObjectLastModified(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // preparing for object upload. - objectName := "test-object" - // content for the object to be uploaded. - buffer1 := bytes.NewReader([]byte("hello world")) - // obtaining URL for uploading the object. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - // executing the HTTP request to download the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - // make HTTP request to obtain object info. - request, err = newTestSignedRequestV2("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // verify the status of the HTTP response. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // retrive the info of last modification time of the object from the response header. - lastModified := response.Header.Get("Last-Modified") - // Parse it into time.Time structure. - t, err := time.Parse(http.TimeFormat, lastModified) - c.Assert(err, IsNil) - - // make HTTP request to obtain object info. - // But this time set the "If-Modified-Since" header to be 10 minute more than the actual - // last modified time of the object. - request, err = newTestSignedRequestV2("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - request.Header.Set("If-Modified-Since", t.Add(10*time.Minute).UTC().Format(http.TimeFormat)) - response, err = client.Do(request) - c.Assert(err, IsNil) - // Since the "If-Modified-Since" header was ahead in time compared to the actual - // modified time of the object expecting the response status to be http.StatusNotModified. - c.Assert(response.StatusCode, Equals, http.StatusNotModified) - - // Again, obtain the object info. - // This time setting "If-Unmodified-Since" to a time after the object is modified. - // As documented above, expecting http.StatusPreconditionFailed. - request, err = newTestSignedRequestV2("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - request.Header.Set("If-Unmodified-Since", t.Add(-10*time.Minute).UTC().Format(http.TimeFormat)) - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusPreconditionFailed) -} - -// TestHeadOnBucket - Validates response for HEAD on the bucket. -// HEAD request on the bucket validates the existence of the bucket. -func (s *TestSuiteCommonV2) TestHeadOnBucket(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getHEADBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - // make HEAD request on the bucket. - request, err = newTestSignedRequestV2("HEAD", getHEADBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // Asserting the response status for expected value of http.StatusOK. - c.Assert(response.StatusCode, Equals, http.StatusOK) -} - -// TestContentTypePersists - Object upload with different Content-type is first done. -// And then a HEAD and GET request on these objects are done to validate if the same Content-Type set during upload persists. -func (s *TestSuiteCommonV2) TestContentTypePersists(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // Uploading a new object with Content-Type "image/png". - // content for the object to be uploaded. - buffer1 := bytes.NewReader([]byte("hello world")) - objectName := "test-object.png" - // constructing HTTP request for object upload. - request, err = newTestSignedRequestV2ContentType("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey, "image/png") - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request for object upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // Fetching the object info using HEAD request for the object which was uploaded above. - request, err = newTestSignedRequestV2("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - // Execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // Verify if the Content-Type header is set during the object persists. - c.Assert(response.Header.Get("Content-Type"), Equals, "image/png") - - // Fetching the object itself and then verify the Content-Type header. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // Execute the HTTP to fetch the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - // Verify if the Content-Type header is set during the object persists. - c.Assert(response.Header.Get("Content-Type"), Equals, "image/png") - - // Uploading a new object with Content-Type "application/json". - objectName = "test-object.json" - buffer2 := bytes.NewReader([]byte("hello world")) - request, err = newTestSignedRequestV2ContentType("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey, "application/json") - c.Assert(err, IsNil) - - // Execute the HTTP request to upload the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // Obtain the info of the object which was uploaded above using HEAD request. - request, err = newTestSignedRequestV2("HEAD", getHeadObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // Execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // Assert if the content-type header set during the object upload persists. - c.Assert(response.Header.Get("Content-Type"), Equals, "application/json") - - // Fetch the object and assert whether the Content-Type header persists. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - // Execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // Assert if the content-type header set during the object upload persists. - c.Assert(response.Header.Get("Content-Type"), Equals, "application/json") -} - -// TestPartialContent - Validating for GetObject with partial content request. -// By setting the Range header, A request to send specific bytes range of data from an -// already uploaded object can be done. -func (s *TestSuiteCommonV2) TestPartialContent(c *C) { - bucketName := getRandomBucketName() - - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - buffer1 := bytes.NewReader([]byte("Hello World")) - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, "bar"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - 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 = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, "bar"), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - 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") -} - -// TestListObjectsHandler - Setting valid parameters to List Objects -// and then asserting the response with the expected one. -func (s *TestSuiteCommonV2) TestListObjectsHandler(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - buffer1 := bytes.NewReader([]byte("Hello World")) - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, "bar"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // create listObjectsV1 request with valid parameters - request, err = newTestSignedRequestV2("GET", getListObjectsV1URL(s.endPoint, bucketName, "1000"), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - getContent, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - c.Assert(strings.Contains(string(getContent), "bar"), Equals, true) - - // create listObjectsV2 request with valid parameters - request, err = newTestSignedRequestV2("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", ""), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - getContent, err = ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - c.Assert(strings.Contains(string(getContent), "bar"), Equals, true) - c.Assert(strings.Contains(string(getContent), ""), Equals, true) - - // create listObjectsV2 request with valid parameters and fetch-owner activated - request, err = newTestSignedRequestV2("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", "true"), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - getContent, err = ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - - c.Assert(strings.Contains(string(getContent), "bar"), Equals, true) - c.Assert(strings.Contains(string(getContent), "miniominio"), Equals, true) - -} - -// TestListObjectsHandlerErrors - Setting invalid parameters to List Objects -// and then asserting the error response with the expected one. -func (s *TestSuiteCommonV2) TestListObjectsHandlerErrors(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // create listObjectsV1 request with invalid value of max-keys parameter. max-keys is set to -2. - request, err = newTestSignedRequestV2("GET", getListObjectsV1URL(s.endPoint, bucketName, "-2"), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // validating the error response. - verifyError(c, response, "InvalidArgument", "Argument maxKeys must be an integer between 0 and 2147483647", http.StatusBadRequest) - - // create listObjectsV2 request with invalid value of max-keys parameter. max-keys is set to -2. - request, err = newTestSignedRequestV2("GET", getListObjectsV2URL(s.endPoint, bucketName, "-2", ""), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // validating the error response. - verifyError(c, response, "InvalidArgument", "Argument maxKeys must be an integer between 0 and 2147483647", http.StatusBadRequest) - -} - -// TestPutBucketErrors - request for non valid bucket operation -// and validate it with expected error result. -func (s *TestSuiteCommonV2) TestPutBucketErrors(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // generating a HTTP request to create bucket. - // using invalid bucket name. - request, err := newTestSignedRequestV2("PUT", s.endPoint+"/putbucket-.", - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - response, err := client.Do(request) - c.Assert(err, IsNil) - // expected to fail with error message "InvalidBucketName". - verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest) - // HTTP request to create the bucket. - request, err = newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to create bucket. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - // make HTTP request to create the same bucket again. - // expected to fail with error message "BucketAlreadyOwnedByYou". - request, err = newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - response, err = client.Do(request) - c.Assert(err, IsNil) - verifyError(c, response, "BucketAlreadyOwnedByYou", "Your previous request to create the named bucket succeeded and you already own it.", - http.StatusConflict) - - // request for ACL. - // Since Minio server doesn't support ACL's the request is expected to fail with "NotImplemented" error message. - request, err = newTestSignedRequestV2("PUT", s.endPoint+"/"+bucketName+"?acl", - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - 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 *TestSuiteCommonV2) TestGetObjectLarge10MiB(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // form HTTP reqest to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create the bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - var buffer bytes.Buffer - line := `1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,123"` - // Create 10MiB content where each line contains 1024 characters. - for i := 0; i < 10*1024; i++ { - buffer.WriteString(fmt.Sprintf("[%05d] %s\n", i, line)) - } - putContent := buffer.String() - - buf := bytes.NewReader([]byte(putContent)) - - objectName := "test-big-object" - // create HTTP request for object upload. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // Assert the status code to verify successful upload. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // prepare HTTP requests to download the object. - request, err = newTestSignedRequestV2("GET", getPutObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to download the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - // extract the content from response body. - getContent, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - - // Compare putContent and getContent. - c.Assert(string(getContent), Equals, putContent) -} - -// TestGetObjectLarge11MiB - Tests validate fetching of an object of size 11MB. -func (s *TestSuiteCommonV2) TestGetObjectLarge11MiB(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - var buffer bytes.Buffer - line := `1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,123` - // Create 11MiB content where each line contains 1024 characters. - for i := 0; i < 11*1024; i++ { - buffer.WriteString(fmt.Sprintf("[%05d] %s\n", i, line)) - } - putMD5 := sumMD5(buffer.Bytes()) - - objectName := "test-11Mb-object" - // Put object - buf := bytes.NewReader(buffer.Bytes()) - // create HTTP request foe object upload. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request for object upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // create HTTP request to download the object. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - // fetch the content from response body. - getContent, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - - // Get md5Sum of the response content. - getMD5 := sumMD5(getContent) - - // Compare putContent and getContent. - c.Assert(hex.EncodeToString(putMD5), Equals, hex.EncodeToString(getMD5)) -} - -// TestGetPartialObjectMisAligned - tests get object partially mis-aligned. -// create a large buffer of mis-aligned data and upload it. -// then make partial range requests to while fetching it back and assert the response content. -func (s *TestSuiteCommonV2) TestGetPartialObjectMisAligned(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create the bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - var buffer bytes.Buffer - line := `1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,123` - - rand.Seed(time.Now().UTC().UnixNano()) - // Create a misalgined data. - for i := 0; i < 13*rand.Intn(1<<16); i++ { - buffer.WriteString(fmt.Sprintf("[%05d] %s\n", i, line[:rand.Intn(1<<8)])) - } - putContent := buffer.String() - buf := bytes.NewReader([]byte(putContent)) - - objectName := "test-big-file" - // HTTP request to upload the object. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to upload the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // test Cases containing data to make partial range requests. - // also has expected response data. - var testCases = []struct { - byteRange string - expectedString string - }{ - // request for byte range 10-11. - // expecting the result to contain only putContent[10:12] bytes. - {"10-11", putContent[10:12]}, - // request for object data after the first byte. - {"1-", putContent[1:]}, - // request for object data after the first byte. - {"6-", putContent[6:]}, - // request for last 2 bytes of th object. - {"-2", putContent[len(putContent)-2:]}, - // request for last 7 bytes of the object. - {"-7", putContent[len(putContent)-7:]}, - } - for _, t := range testCases { - // HTTP request to download the object. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // Get partial content based on the byte range set. - request.Header.Add("Range", "bytes="+t.byteRange) - - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // Since only part of the object is requested, expecting response status to be http.StatusPartialContent . - c.Assert(response.StatusCode, Equals, http.StatusPartialContent) - // parse the HTTP response body. - getContent, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - - // Compare putContent and getContent. - c.Assert(string(getContent), Equals, t.expectedString) - } -} - -// TestGetPartialObjectLarge11MiB - Test validates partial content request for a 11MiB object. -func (s *TestSuiteCommonV2) TestGetPartialObjectLarge11MiB(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create the bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - var buffer bytes.Buffer - line := `234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,123` - // Create 11MiB content where each line contains 1024 - // characters. - for i := 0; i < 11*1024; i++ { - buffer.WriteString(fmt.Sprintf("[%05d] %s\n", i, line)) - } - putContent := buffer.String() - - objectName := "test-large-11Mb-object" - - buf := bytes.NewReader([]byte(putContent)) - // HTTP request to upload the object. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to upload the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // HTTP request to download the object. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // This range spans into first two blocks. - request.Header.Add("Range", "bytes=10485750-10485769") - - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // Since only part of the object is requested, expecting response status to be http.StatusPartialContent . - c.Assert(response.StatusCode, Equals, http.StatusPartialContent) - // read the downloaded content from the response body. - getContent, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - - // Compare putContent and getContent. - c.Assert(string(getContent), Equals, putContent[10485750:10485770]) -} - -// TestGetPartialObjectLarge11MiB - Test validates partial content request for a 10MiB object. -func (s *TestSuiteCommonV2) TestGetPartialObjectLarge10MiB(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - // expecting the error to be nil. - c.Assert(err, IsNil) - // expecting the HTTP response status code to 200 OK. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - var buffer bytes.Buffer - line := `1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890, - 1234567890,1234567890,1234567890,123` - // Create 10MiB content where each line contains 1024 characters. - for i := 0; i < 10*1024; i++ { - buffer.WriteString(fmt.Sprintf("[%05d] %s\n", i, line)) - } - - putContent := buffer.String() - buf := bytes.NewReader([]byte(putContent)) - - objectName := "test-big-10Mb-file" - // HTTP request to upload the object. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buf.Len()), buf, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to upload the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - // verify whether upload was successful. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // HTTP request to download the object. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // Get partial content based on the byte range set. - request.Header.Add("Range", "bytes=2048-2058") - - client = http.Client{} - // execute the HTTP request to download the partila content. - response, err = client.Do(request) - c.Assert(err, IsNil) - // Since only part of the object is requested, expecting response status to be http.StatusPartialContent . - c.Assert(response.StatusCode, Equals, http.StatusPartialContent) - // read the downloaded content from the response body. - getContent, err := ioutil.ReadAll(response.Body) - c.Assert(err, IsNil) - - // Compare putContent and getContent. - c.Assert(string(getContent), Equals, putContent[2048:2059]) -} - -// TestGetObjectErrors - Tests validate error response for invalid object operations. -func (s *TestSuiteCommonV2) TestGetObjectErrors(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - objectName := "test-non-exitent-object" - // HTTP request to download the object. - // Since the specified object doesn't exist in the given bucket, - // expected to fail with error message "NoSuchKey" - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - 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 to download an object, but an invalid bucket name is set. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, "/getobjecterrors-.", objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // expected to fail with "InvalidBucketName". - verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest) -} - -// TestGetObjectRangeErrors - Validate error response when object is fetched with incorrect byte range value. -func (s *TestSuiteCommonV2) TestGetObjectRangeErrors(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // content for the object to be uploaded. - buffer1 := bytes.NewReader([]byte("Hello World")) - - objectName := "test-object" - // HTTP request to upload the object. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to upload the object. - response, err = client.Do(request) - c.Assert(err, IsNil) - // verify whether upload was successful. - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // HTTP request to download the object. - request, err = newTestSignedRequestV2("GET", getGetObjectURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - // Invalid byte range set. - request.Header.Add("Range", "bytes=-0") - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // expected to fail with "InvalidRange" error message. - verifyError(c, response, "InvalidRange", "The requested range is not satisfiable", http.StatusRequestedRangeNotSatisfiable) -} - -// TestObjectMultipartAbort - Test validates abortion of a multipart upload after uploading 2 parts. -func (s *TestSuiteCommonV2) TestObjectMultipartAbort(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - objectName := "test-multipart-object" - - // 1. Initiate 2 uploads for the same object - // 2. Upload 2 parts for the second upload - // 3. Abort the second upload. - // 4. Abort the first upload. - // This will test abort upload when there are more than one upload IDs - // and the case where there is only one upload ID. - - // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV2("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - // execute the HTTP request initiating the new multipart upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // parse the response body and obtain the new upload ID. - decoder := xml.NewDecoder(response.Body) - newResponse := &InitiateMultipartUploadResponse{} - - err = decoder.Decode(newResponse) - c.Assert(err, IsNil) - c.Assert(len(newResponse.UploadID) > 0, Equals, true) - - // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV2("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - // execute the HTTP request initiating the new multipart upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // parse the response body and obtain the new upload ID. - decoder = xml.NewDecoder(response.Body) - newResponse = &InitiateMultipartUploadResponse{} - - err = decoder.Decode(newResponse) - c.Assert(err, IsNil) - c.Assert(len(newResponse.UploadID) > 0, Equals, true) - // uploadID to be used for rest of the multipart operations on the object. - uploadID := newResponse.UploadID - - // content for the part to be uploaded. - buffer1 := bytes.NewReader([]byte("hello world")) - // HTTP request for the part to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request to upload the first part. - response1, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response1.StatusCode, Equals, http.StatusOK) - - // content for the second part to be uploaded. - buffer2 := bytes.NewReader([]byte("hello world")) - // HTTP request for the second part to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request to upload the second part. - response2, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response2.StatusCode, Equals, http.StatusOK) - // HTTP request for aborting the multipart upload. - request, err = newTestSignedRequestV2("DELETE", getAbortMultipartUploadURL(s.endPoint, bucketName, objectName, uploadID), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request to abort the multipart upload. - response3, err := client.Do(request) - c.Assert(err, IsNil) - // expecting the response status code to be http.StatusNoContent. - // The assertion validates the success of Abort Multipart operation. - c.Assert(response3.StatusCode, Equals, http.StatusNoContent) -} - -// TestBucketMultipartList - Initiates a NewMultipart upload, uploads parts and validates listing of the parts. -func (s *TestSuiteCommonV2) TestBucketMultipartList(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), 0, - nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, 200) - - objectName := "test-multipart-object" - // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV2("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request initiating the new multipart upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - // expecting the response status code to be http.StatusOK(200 OK) . - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // parse the response body and obtain the new upload ID. - decoder := xml.NewDecoder(response.Body) - newResponse := &InitiateMultipartUploadResponse{} - - err = decoder.Decode(newResponse) - c.Assert(err, IsNil) - c.Assert(len(newResponse.UploadID) > 0, Equals, true) - // uploadID to be used for rest of the multipart operations on the object. - uploadID := newResponse.UploadID - - // content for the part to be uploaded. - buffer1 := bytes.NewReader([]byte("hello world")) - // HTTP request for the part to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request to upload the first part. - response1, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response1.StatusCode, Equals, http.StatusOK) - - // content for the second part to be uploaded. - buffer2 := bytes.NewReader([]byte("hello world")) - // HTTP request for the second part to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request to upload the second part. - response2, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response2.StatusCode, Equals, http.StatusOK) - - // HTTP request to ListMultipart Uploads. - request, err = newTestSignedRequestV2("GET", getListMultipartURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request. - response3, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response3.StatusCode, Equals, http.StatusOK) - - // The reason to duplicate this structure here is to verify if the - // unmarshalling works from a client perspective, specifically - // while unmarshalling time.Time type for 'Initiated' field. - // time.Time does not honor xml marshaler, it means that we need - // to encode/format it before giving it to xml marshalling. - - // This below check adds client side verification to see if its - // truly parseable. - - // listMultipartUploadsResponse - format for list multipart uploads response. - type listMultipartUploadsResponse struct { - XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListMultipartUploadsResult" json:"-"` - - Bucket string - KeyMarker string - UploadIDMarker string `xml:"UploadIdMarker"` - NextKeyMarker string - NextUploadIDMarker string `xml:"NextUploadIdMarker"` - EncodingType string - MaxUploads int - IsTruncated bool - // All the in progress multipart uploads. - Uploads []struct { - Key string - UploadID string `xml:"UploadId"` - Initiator Initiator - Owner Owner - StorageClass string - Initiated time.Time // Keep this native to be able to parse properly. - } - Prefix string - Delimiter string - CommonPrefixes []CommonPrefix - } - - // parse the response body. - decoder = xml.NewDecoder(response3.Body) - newResponse3 := &listMultipartUploadsResponse{} - err = decoder.Decode(newResponse3) - c.Assert(err, IsNil) - // Assert the bucket name in the response with the expected bucketName. - c.Assert(newResponse3.Bucket, Equals, bucketName) - // Assert the bucket name in the response with the expected bucketName. - c.Assert(newResponse3.IsTruncated, Equals, false) -} - -// TestValidateObjectMultipartUploadID - Test Initiates a new multipart upload and validates the uploadID. -func (s *TestSuiteCommonV2) TestValidateObjectMultipartUploadID(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, 200) - - objectName := "directory1/directory2/object" - // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV2("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request initiating the new multipart upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - - // parse the response body and obtain the new upload ID. - decoder := xml.NewDecoder(response.Body) - newResponse := &InitiateMultipartUploadResponse{} - err = decoder.Decode(newResponse) - // expecting the decoding error to be nil. - c.Assert(err, IsNil) - // Verifying for Upload ID value to be greater than 0. - c.Assert(len(newResponse.UploadID) > 0, Equals, true) -} - -// TestObjectMultipartListError - Initiates a NewMultipart upload, uploads parts and validates -// error response for an incorrect max-parts parameter . -func (s *TestSuiteCommonV2) TestObjectMultipartListError(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, 200) - - objectName := "test-multipart-object" - // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV2("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request initiating the new multipart upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, http.StatusOK) - // parse the response body and obtain the new upload ID. - decoder := xml.NewDecoder(response.Body) - newResponse := &InitiateMultipartUploadResponse{} - - err = decoder.Decode(newResponse) - c.Assert(err, IsNil) - c.Assert(len(newResponse.UploadID) > 0, Equals, true) - // uploadID to be used for rest of the multipart operations on the object. - uploadID := newResponse.UploadID - - // content for the part to be uploaded. - buffer1 := bytes.NewReader([]byte("hello world")) - // HTTP request for the part to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request to upload the first part. - response1, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response1.StatusCode, Equals, http.StatusOK) - - // content for the second part to be uploaded. - buffer2 := bytes.NewReader([]byte("hello world")) - // HTTP request for the second part to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - // execute the HTTP request to upload the second part. - response2, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response2.StatusCode, Equals, http.StatusOK) - - // HTTP request to ListMultipart Uploads. - // max-keys is set to valid value of 1 - request, err = newTestSignedRequestV2("GET", getListMultipartURLWithParams(s.endPoint, bucketName, objectName, uploadID, "1", "", ""), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request. - response3, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response3.StatusCode, Equals, http.StatusOK) - - // HTTP request to ListMultipart Uploads. - // max-keys is set to invalid value of -2. - request, err = newTestSignedRequestV2("GET", getListMultipartURLWithParams(s.endPoint, bucketName, objectName, uploadID, "-2", "", ""), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // execute the HTTP request. - response4, err := client.Do(request) - c.Assert(err, IsNil) - // Since max-keys parameter in the ListMultipart request set to invalid value of -2, - // its expected to fail with error message "InvalidArgument". - verifyError(c, response4, "InvalidArgument", "Argument max-parts must be an integer between 0 and 2147483647", http.StatusBadRequest) -} - -// TestObjectValidMD5 - First uploads an object with a valid Content-Md5 header and verifies the status, -// then upload an object in a wrong Content-Md5 and validate the error response. -func (s *TestSuiteCommonV2) TestObjectValidMD5(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, 200) - - // Create a byte array of 5MB. - // content for the object to be uploaded. - data := bytes.Repeat([]byte("0123456789abcdef"), 5*1024*1024/16) - // calculate md5Sum of the data. - hasher := md5.New() - hasher.Write(data) - md5Sum := hasher.Sum(nil) - - buffer1 := bytes.NewReader(data) - objectName := "test-1-object" - // HTTP request for the object to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // set the Content-Md5 to be the hash to content. - request.Header.Set("Content-Md5", base64.StdEncoding.EncodeToString(md5Sum)) - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - // expecting a successful upload. - c.Assert(response.StatusCode, Equals, http.StatusOK) - objectName = "test-2-object" - buffer1 = bytes.NewReader(data) - // HTTP request for the object to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPutObjectURL(s.endPoint, bucketName, objectName), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // set Content-Md5 to invalid value. - request.Header.Set("Content-Md5", "kvLTlMrX9NpYDQlEIFlnDA==") - // expecting a failure during upload. - client = http.Client{} - response, err = client.Do(request) - c.Assert(err, IsNil) - // Since Content-Md5 header was wrong, expecting to fail with "SignatureDoesNotMatch" error. - verifyError(c, response, "SignatureDoesNotMatch", "The request signature we calculated does not match the signature you provided. Check your key and signing method.", http.StatusForbidden) -} - -// TestObjectMultipart - Initiates a NewMultipart upload, uploads 2 parts, -// completes the multipart upload and validates the status of the operation. -func (s *TestSuiteCommonV2) TestObjectMultipart(c *C) { - // generate a random bucket name. - bucketName := getRandomBucketName() - // HTTP request to create the bucket. - request, err := newTestSignedRequestV2("PUT", getMakeBucketURL(s.endPoint, bucketName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client := http.Client{} - // execute the HTTP request to create bucket. - response, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response.StatusCode, Equals, 200) - - objectName := "test-multipart-object" - // construct HTTP request to initiate a NewMultipart upload. - request, err = newTestSignedRequestV2("POST", getNewMultipartURL(s.endPoint, bucketName, objectName), - 0, nil, s.accessKey, s.secretKey) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request initiating the new multipart upload. - response, err = client.Do(request) - c.Assert(err, IsNil) - // expecting the response status code to be http.StatusOK(200 OK). - c.Assert(response.StatusCode, Equals, http.StatusOK) - // parse the response body and obtain the new upload ID. - decoder := xml.NewDecoder(response.Body) - newResponse := &InitiateMultipartUploadResponse{} - - err = decoder.Decode(newResponse) - c.Assert(err, IsNil) - c.Assert(len(newResponse.UploadID) > 0, Equals, true) - // uploadID to be used for rest of the multipart operations on the object. - uploadID := newResponse.UploadID - - // content for the part to be uploaded. - // Create a byte array of 5MB. - data := bytes.Repeat([]byte("0123456789abcdef"), 5*1024*1024/16) - // calculate md5Sum of the data. - hasher := md5.New() - hasher.Write(data) - md5Sum := hasher.Sum(nil) - - buffer1 := bytes.NewReader(data) - // HTTP request for the part to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "1"), - int64(buffer1.Len()), buffer1, s.accessKey, s.secretKey) - // set the Content-Md5 header to the base64 encoding the md5Sum of the content. - request.Header.Set("Content-Md5", base64.StdEncoding.EncodeToString(md5Sum)) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to upload the first part. - response1, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response1.StatusCode, Equals, http.StatusOK) - - // content for the second part to be uploaded. - // Create a byte array of 1 byte. - data = []byte("0") - - hasher = md5.New() - hasher.Write(data) - // calculate md5Sum of the data. - md5Sum = hasher.Sum(nil) - - buffer2 := bytes.NewReader(data) - // HTTP request for the second part to be uploaded. - request, err = newTestSignedRequestV2("PUT", getPartUploadURL(s.endPoint, bucketName, objectName, uploadID, "2"), - int64(buffer2.Len()), buffer2, s.accessKey, s.secretKey) - // set the Content-Md5 header to the base64 encoding the md5Sum of the content. - request.Header.Set("Content-Md5", base64.StdEncoding.EncodeToString(md5Sum)) - c.Assert(err, IsNil) - - client = http.Client{} - // execute the HTTP request to upload the second part. - response2, err := client.Do(request) - c.Assert(err, IsNil) - c.Assert(response2.StatusCode, Equals, http.StatusOK) - - // Complete multipart upload - completeUploads := &completeMultipartUpload{ - Parts: []completePart{ - { - PartNumber: 1, - ETag: response1.Header.Get("ETag"), - }, - { - PartNumber: 2, - ETag: response2.Header.Get("ETag"), - }, - }, - } - - completeBytes, err := xml.Marshal(completeUploads) - c.Assert(err, IsNil) - // Indicating that all parts are uploaded and initiating completeMultipartUpload. - request, err = newTestSignedRequestV2("POST", getCompleteMultipartUploadURL(s.endPoint, bucketName, objectName, uploadID), - int64(len(completeBytes)), bytes.NewReader(completeBytes), s.accessKey, s.secretKey) - c.Assert(err, IsNil) - // Execute the complete multipart request. - response, err = client.Do(request) - c.Assert(err, IsNil) - // verify whether complete multipart was successful. - c.Assert(response.StatusCode, Equals, http.StatusOK) - -} diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index f79ea6bfd..0a1665158 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -1015,25 +1015,20 @@ func newTestRequest(method, urlStr string, contentLength int64, body io.ReadSeek return req, nil } -func newTestSignedRequestV2ContentType(method, urlStr string, contentLength int64, body io.ReadSeeker, accessKey, secretKey, contentType string) (*http.Request, error) { - req, err := newTestRequest(method, urlStr, contentLength, body) - if err != nil { - return nil, err - } - req.Header.Del("x-amz-content-sha256") - req.Header.Set("Content-Type", contentType) +// Various signature types we are supporting, currently +// two main signature types. +type signerType int - // Anonymous request return quickly. - if accessKey == "" || secretKey == "" { - return req, nil - } +const ( + signerV2 signerType = iota + signerV4 +) - err = signRequestV2(req, accessKey, secretKey) - if err != nil { - return nil, err +func newTestSignedRequest(method, urlStr string, contentLength int64, body io.ReadSeeker, accessKey, secretKey string, signer signerType) (*http.Request, error) { + if signer == signerV2 { + return newTestSignedRequestV2(method, urlStr, contentLength, body, accessKey, secretKey) } - - return req, nil + return newTestSignedRequestV4(method, urlStr, contentLength, body, accessKey, secretKey) } // Returns new HTTP request object signed with signature v2.