2015-07-03 03:29:54 -04:00
|
|
|
/*
|
|
|
|
* Minimalist Object Storage, (C) 2014 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"encoding/xml"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
|
|
|
|
. "github.com/minio/check"
|
|
|
|
"github.com/minio/minio/pkg/server/api"
|
|
|
|
)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func TestAPI(t *testing.T) { TestingT(t) }
|
2015-07-03 03:29:54 -04:00
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
type MyAPISuite struct{}
|
2015-07-03 03:29:54 -04:00
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
var _ = Suite(&MyAPISuite{})
|
2015-07-03 03:29:54 -04:00
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
var testAPIServer *httptest.Server
|
2015-07-03 03:29:54 -04:00
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) SetUpSuite(c *C) {
|
2015-07-03 03:29:54 -04:00
|
|
|
httpHandler, minioAPI := getAPIHandler(api.Config{RateLimit: 16})
|
|
|
|
go startTM(minioAPI)
|
2015-07-07 20:27:34 -04:00
|
|
|
testAPIServer = httptest.NewServer(httpHandler)
|
2015-07-03 03:29:54 -04:00
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TearDownSuite(c *C) {
|
|
|
|
testAPIServer.Close()
|
2015-07-03 03:29:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func setDummyAuthHeader(req *http.Request) {
|
|
|
|
authDummy := "AWS4-HMAC-SHA256 Credential=AC5NH40NQLTL4DUMMY/20130524/us-east-1/s3/aws4_request, SignedHeaders=date;host;x-amz-content-sha256;x-amz-date;x-amz-storage-class, Signature=98ad721746da40c64f1a55b78f14c238d841ea1380cd77a1b5971af0ece108bd"
|
|
|
|
req.Header.Set("Authorization", authDummy)
|
|
|
|
req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestNonExistantBucket(c *C) {
|
|
|
|
request, err := http.NewRequest("HEAD", testAPIServer.URL+"/nonexistantbucket", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestEmptyObject(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/emptyobject", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/emptyobject/object", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/emptyobject/object", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, buffer.Bytes()))
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestBucket(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/bucket", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("HEAD", testAPIServer.URL+"/bucket", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestObject(c *C) {
|
2015-07-03 03:29:54 -04:00
|
|
|
buffer := bytes.NewBufferString("hello world")
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/testobject", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/testobject/object", buffer)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/testobject/object", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(responseBody, DeepEquals, []byte("hello world"))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestMultipleObjects(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/multipleobjects", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/multipleobjects/object", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
|
|
|
|
|
|
|
|
//// test object 1
|
|
|
|
|
|
|
|
// get object
|
|
|
|
buffer1 := bytes.NewBufferString("hello one")
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/multipleobjects/object1", buffer1)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/multipleobjects/object1", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
// verify response data
|
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello one")))
|
|
|
|
|
|
|
|
buffer2 := bytes.NewBufferString("hello two")
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/multipleobjects/object2", buffer2)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/multipleobjects/object2", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
// verify response data
|
|
|
|
responseBody, err = ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello two")))
|
|
|
|
|
|
|
|
buffer3 := bytes.NewBufferString("hello three")
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/multipleobjects/object3", buffer3)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/multipleobjects/object3", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
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")))
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestNotImplemented(c *C) {
|
|
|
|
request, err := http.NewRequest("GET", testAPIServer.URL+"/bucket/object?policy", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNotImplemented)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestHeader(c *C) {
|
|
|
|
request, err := http.NewRequest("GET", testAPIServer.URL+"/bucket/object", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestPutBucket(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/put-bucket", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestPutObject(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/put-object", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/put-object/object", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestListBuckets(c *C) {
|
|
|
|
request, err := http.NewRequest("GET", testAPIServer.URL+"/", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
_, err = readListBucket(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func readListBucket(reader io.Reader) (api.ListBucketsResponse, error) {
|
|
|
|
var results api.ListBucketsResponse
|
|
|
|
decoder := xml.NewDecoder(reader)
|
|
|
|
err := decoder.Decode(&results)
|
|
|
|
return results, err
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestNotBeAbleToCreateObjectInNonexistantBucket(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/innonexistantbucket/object", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestHeadOnObject(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/headonobject", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/headonobject/object1", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("HEAD", testAPIServer.URL+"/headonobject/object1", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestHeadOnBucket(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/headonbucket", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("HEAD", testAPIServer.URL+"/headonbucket", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestDateFormat(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/dateformat", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
// set an invalid date
|
|
|
|
request.Header.Set("Date", "asfasdfadf")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "RequestTimeTooSkewed",
|
|
|
|
"The difference between the request time and the server's time is too large.", http.StatusForbidden)
|
|
|
|
|
|
|
|
request.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentType string, etag string) {
|
|
|
|
// Verify date
|
|
|
|
c.Assert(header.Get("Last-Modified"), Equals, date.Format(http.TimeFormat))
|
|
|
|
|
|
|
|
// verify size
|
|
|
|
c.Assert(header.Get("Content-Length"), Equals, strconv.Itoa(size))
|
|
|
|
|
|
|
|
// verify content type
|
|
|
|
c.Assert(header.Get("Content-Type"), Equals, contentType)
|
|
|
|
|
|
|
|
// verify etag
|
|
|
|
c.Assert(header.Get("Etag"), Equals, "\""+etag+"\"")
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestXMLNameNotInBucketListJson(c *C) {
|
|
|
|
request, err := http.NewRequest("GET", testAPIServer.URL+"/", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
byteResults, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(strings.Contains(string(byteResults), "XML"), Equals, false)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestXMLNameNotInObjectListJson(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/xmlnamenotinobjectlistjson", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/xmlnamenotinobjectlistjson", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
byteResults, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(strings.Contains(string(byteResults), "XML"), Equals, false)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestContentTypePersists(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/contenttype-persists", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/contenttype-persists/one", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
delete(request.Header, "Content-Type")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("HEAD", testAPIServer.URL+"/contenttype-persists/one", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/contenttype-persists/one", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/contenttype-persists/two", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
delete(request.Header, "Content-Type")
|
|
|
|
request.Header.Add("Content-Type", "application/json")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("HEAD", testAPIServer.URL+"/contenttype-persists/two", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/contenttype-persists/two", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestPartialContent(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/partial-content", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/partial-content/bar", bytes.NewBufferString("Hello World"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
// prepare request
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/partial-content/bar", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
request.Header.Add("Range", "bytes=6-7")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestListObjectsHandlerErrors(c *C) {
|
|
|
|
request, err := http.NewRequest("GET", testAPIServer.URL+"/objecthandlererrors-.", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/objecthandlererrors", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestPutBucketErrors(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/putbucket-.", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/putbucket", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/putbucket", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "BucketAlreadyExists", "The requested bucket name is not available.", http.StatusConflict)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/putbucket?acl", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "unknown")
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestGetObjectErrors(c *C) {
|
|
|
|
request, err := http.NewRequest("GET", testAPIServer.URL+"/getobjecterrors", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/getobjecterrors", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/getobjecterrors/bar", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/getobjecterrors-./bar", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestGetObjectRangeErrors(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/getobjectrangeerrors", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/getobjectrangeerrors/bar", bytes.NewBufferString("Hello World"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/getobjectrangeerrors/bar", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
request.Header.Add("Range", "bytes=7-6")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "InvalidRange", "The requested range cannot be satisfied.", http.StatusRequestedRangeNotSatisfiable)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestObjectMultipartAbort(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/objectmultipartabort", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, 200)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("POST", testAPIServer.URL+"/objectmultipartabort/object?uploads", bytes.NewBufferString(""))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder := xml.NewDecoder(response.Body)
|
|
|
|
newResponse := &api.InitiateMultipartUploadResult{}
|
|
|
|
|
|
|
|
err = decoder.Decode(newResponse)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
|
|
|
|
uploadID := newResponse.UploadID
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response1, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response1.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response2, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response2.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("DELETE", testAPIServer.URL+"/objectmultipartabort/object?uploadId="+uploadID, nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response3, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response3.StatusCode, Equals, http.StatusNoContent)
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestBucketMultipartList(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/bucketmultipartlist", bytes.NewBufferString(""))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, 200)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("POST", testAPIServer.URL+"/bucketmultipartlist/object?uploads", bytes.NewBufferString(""))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder := xml.NewDecoder(response.Body)
|
|
|
|
newResponse := &api.InitiateMultipartUploadResult{}
|
|
|
|
|
|
|
|
err = decoder.Decode(newResponse)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
|
|
|
|
uploadID := newResponse.UploadID
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response1, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response1.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response2, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response2.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/bucketmultipartlist?uploads", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response3, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response3.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder = xml.NewDecoder(response3.Body)
|
|
|
|
newResponse3 := &api.ListMultipartUploadsResponse{}
|
|
|
|
err = decoder.Decode(newResponse3)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(newResponse3.Bucket, Equals, "bucketmultipartlist")
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestObjectMultipartList(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/objectmultipartlist", bytes.NewBufferString(""))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, 200)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("POST", testAPIServer.URL+"/objectmultipartlist/object?uploads", bytes.NewBufferString(""))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder := xml.NewDecoder(response.Body)
|
|
|
|
newResponse := &api.InitiateMultipartUploadResult{}
|
|
|
|
|
|
|
|
err = decoder.Decode(newResponse)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
|
|
|
|
uploadID := newResponse.UploadID
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response1, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response1.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response2, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response2.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/objectmultipartlist/object?uploadId="+uploadID, nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response3, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response3.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
func (s *MyAPISuite) TestObjectMultipart(c *C) {
|
|
|
|
request, err := http.NewRequest("PUT", testAPIServer.URL+"/objectmultiparts", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, 200)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("POST", testAPIServer.URL+"/objectmultiparts/object?uploads", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder := xml.NewDecoder(response.Body)
|
|
|
|
newResponse := &api.InitiateMultipartUploadResult{}
|
|
|
|
|
|
|
|
err = decoder.Decode(newResponse)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
|
|
|
|
uploadID := newResponse.UploadID
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response1, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response1.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("PUT", testAPIServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response2, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response2.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
// complete multipart upload
|
|
|
|
completeUploads := &api.CompleteMultipartUpload{
|
|
|
|
Part: []api.Part{
|
|
|
|
{
|
|
|
|
PartNumber: 1,
|
|
|
|
ETag: response1.Header.Get("ETag"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PartNumber: 2,
|
|
|
|
ETag: response2.Header.Get("ETag"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var completeBuffer bytes.Buffer
|
|
|
|
encoder := xml.NewEncoder(&completeBuffer)
|
|
|
|
encoder.Encode(completeUploads)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("POST", testAPIServer.URL+"/objectmultiparts/object?uploadId="+uploadID, &completeBuffer)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-07-07 20:27:34 -04:00
|
|
|
request, err = http.NewRequest("GET", testAPIServer.URL+"/objectmultiparts/object", nil)
|
2015-07-03 03:29:54 -04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
setDummyAuthHeader(request)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
object, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(string(object), Equals, ("hello worldhello world"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyError(c *C, response *http.Response, code, description string, statusCode int) {
|
|
|
|
data, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
errorResponse := api.ErrorResponse{}
|
|
|
|
err = xml.Unmarshal(data, &errorResponse)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(errorResponse.Code, Equals, code)
|
|
|
|
c.Assert(errorResponse.Message, Equals, description)
|
|
|
|
c.Assert(response.StatusCode, Equals, statusCode)
|
|
|
|
}
|