2015-07-12 21:40:38 +02:00
|
|
|
/*
|
2015-10-16 20:26:01 +02:00
|
|
|
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
2015-07-12 21:40:38 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-09-19 09:52:01 +02:00
|
|
|
package main
|
2015-07-12 21:40:38 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2015-09-20 21:44:44 +02:00
|
|
|
"sort"
|
2015-07-12 21:40:38 +02:00
|
|
|
"strings"
|
2015-09-20 21:44:44 +02:00
|
|
|
"time"
|
2015-07-12 21:40:38 +02:00
|
|
|
|
2015-09-20 21:44:44 +02:00
|
|
|
"encoding/hex"
|
2015-07-12 21:40:38 +02:00
|
|
|
"encoding/xml"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
"github.com/minio/minio/pkg/fs"
|
2015-08-23 03:34:00 +02:00
|
|
|
. "gopkg.in/check.v1"
|
2015-07-12 21:40:38 +02:00
|
|
|
)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
const (
|
|
|
|
yyyymmdd = "20060102"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MyAPIFSCacheSuite struct {
|
2015-07-12 21:40:38 +02:00
|
|
|
root string
|
|
|
|
req *http.Request
|
|
|
|
body io.ReadSeeker
|
|
|
|
accessKeyID string
|
|
|
|
secretAccessKey string
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
var _ = Suite(&MyAPIFSCacheSuite{})
|
2015-07-12 21:40:38 +02:00
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
var testAPIFSCacheServer *httptest.Server
|
2015-07-12 21:40:38 +02:00
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) SetUpSuite(c *C) {
|
2015-07-12 21:40:38 +02:00
|
|
|
root, err := ioutil.TempDir(os.TempDir(), "api-")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
s.root = root
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
fsroot, err := ioutil.TempDir(os.TempDir(), "api-")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
fs.SetFSMultipartsConfigPath(filepath.Join(root, "multiparts.json"))
|
|
|
|
multiparts := &fs.Multiparts{}
|
|
|
|
multiparts.ActiveSession = make(map[string]*fs.MultipartSession)
|
|
|
|
perr := fs.SaveMultipartsSession(multiparts)
|
2015-08-08 08:47:22 +02:00
|
|
|
c.Assert(perr, IsNil)
|
2015-07-12 21:40:38 +02:00
|
|
|
|
2015-10-05 08:11:18 +02:00
|
|
|
accessKeyID, perr := generateAccessKeyID()
|
2015-08-08 08:47:22 +02:00
|
|
|
c.Assert(perr, IsNil)
|
2015-10-05 08:11:18 +02:00
|
|
|
secretAccessKey, perr := generateSecretAccessKey()
|
2015-08-08 08:47:22 +02:00
|
|
|
c.Assert(perr, IsNil)
|
2015-07-12 21:40:38 +02:00
|
|
|
|
2015-10-20 09:33:53 +02:00
|
|
|
conf := newConfigV2()
|
|
|
|
conf.Credentials.AccessKeyID = string(accessKeyID)
|
|
|
|
conf.Credentials.SecretAccessKey = string(secretAccessKey)
|
2015-07-12 21:40:38 +02:00
|
|
|
s.accessKeyID = string(accessKeyID)
|
|
|
|
s.secretAccessKey = string(secretAccessKey)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
// do this only once here
|
|
|
|
customConfigPath = root
|
|
|
|
|
2015-10-20 09:33:53 +02:00
|
|
|
perr = saveConfig(conf)
|
2015-08-08 08:47:22 +02:00
|
|
|
c.Assert(perr, IsNil)
|
2015-07-12 21:40:38 +02:00
|
|
|
|
2015-10-20 09:33:53 +02:00
|
|
|
cloudServer := cloudServerConfig{
|
2015-10-18 04:17:33 +02:00
|
|
|
Path: fsroot,
|
|
|
|
MinFreeDisk: 0,
|
|
|
|
Anonymous: false,
|
|
|
|
}
|
2015-10-20 09:33:53 +02:00
|
|
|
cloudStorageAPI := getNewCloudStorageAPI(cloudServer)
|
2015-10-18 04:17:33 +02:00
|
|
|
httpHandler := getCloudStorageAPIHandler(cloudStorageAPI)
|
2015-10-16 20:26:01 +02:00
|
|
|
testAPIFSCacheServer = httptest.NewServer(httpHandler)
|
2015-07-12 21:40:38 +02:00
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TearDownSuite(c *C) {
|
2015-07-12 21:40:38 +02:00
|
|
|
os.RemoveAll(s.root)
|
2015-10-16 20:26:01 +02:00
|
|
|
testAPIFSCacheServer.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Excerpts from @lsegal - https://github.com/aws/aws-sdk-js/issues/659#issuecomment-120477258
|
|
|
|
///
|
|
|
|
/// User-Agent:
|
|
|
|
///
|
|
|
|
/// This is ignored from signing because signing this causes problems with generating pre-signed URLs
|
|
|
|
/// (that are executed by other agents) or when customers pass requests through proxies, which may
|
|
|
|
/// modify the user-agent.
|
|
|
|
///
|
|
|
|
/// Content-Length:
|
|
|
|
///
|
|
|
|
/// This is ignored from signing because generating a pre-signed URL should not provide a content-length
|
|
|
|
/// constraint, specifically when vending a S3 pre-signed PUT URL. The corollary to this is that when
|
|
|
|
/// sending regular requests (non-pre-signed), the signature contains a checksum of the body, which
|
|
|
|
/// implicitly validates the payload length (since changing the number of bytes would change the checksum)
|
|
|
|
/// and therefore this header is not valuable in the signature.
|
|
|
|
///
|
|
|
|
/// Content-Type:
|
|
|
|
///
|
|
|
|
/// Signing this header causes quite a number of problems in browser environments, where browsers
|
|
|
|
/// like to modify and normalize the content-type header in different ways. There is more information
|
|
|
|
/// on this in https://github.com/aws/aws-sdk-js/issues/244. Avoiding this field simplifies logic
|
|
|
|
/// and reduces the possibility of future bugs
|
|
|
|
///
|
|
|
|
/// Authorization:
|
|
|
|
///
|
|
|
|
/// Is skipped for obvious reasons
|
|
|
|
///
|
|
|
|
var ignoredHeaders = map[string]bool{
|
|
|
|
"Authorization": true,
|
|
|
|
"Content-Type": true,
|
|
|
|
"Content-Length": true,
|
|
|
|
"User-Agent": true,
|
2015-07-12 21:40:38 +02:00
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) newRequest(method, urlStr string, contentLength int64, body io.ReadSeeker) (*http.Request, error) {
|
2015-09-20 21:44:44 +02:00
|
|
|
t := time.Now().UTC()
|
|
|
|
req, err := http.NewRequest(method, urlStr, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Header.Set("x-amz-date", t.Format(iso8601Format))
|
|
|
|
if method == "" {
|
|
|
|
method = "POST"
|
|
|
|
}
|
|
|
|
|
|
|
|
// add Content-Length
|
|
|
|
req.ContentLength = contentLength
|
|
|
|
|
|
|
|
// add body
|
|
|
|
switch {
|
|
|
|
case body == nil:
|
|
|
|
req.Body = nil
|
|
|
|
default:
|
|
|
|
req.Body = ioutil.NopCloser(body)
|
|
|
|
}
|
|
|
|
|
|
|
|
// save for subsequent use
|
|
|
|
hash := func() string {
|
|
|
|
switch {
|
|
|
|
case body == nil:
|
|
|
|
return hex.EncodeToString(sum256([]byte{}))
|
|
|
|
default:
|
|
|
|
sum256Bytes, _ := sum256Reader(body)
|
|
|
|
return hex.EncodeToString(sum256Bytes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hashedPayload := hash()
|
|
|
|
req.Header.Set("x-amz-content-sha256", hashedPayload)
|
|
|
|
|
|
|
|
var headers []string
|
|
|
|
vals := make(map[string][]string)
|
|
|
|
for k, vv := range req.Header {
|
|
|
|
if _, ok := ignoredHeaders[http.CanonicalHeaderKey(k)]; ok {
|
|
|
|
continue // ignored header
|
|
|
|
}
|
|
|
|
headers = append(headers, strings.ToLower(k))
|
|
|
|
vals[strings.ToLower(k)] = vv
|
|
|
|
}
|
|
|
|
headers = append(headers, "host")
|
|
|
|
sort.Strings(headers)
|
|
|
|
|
|
|
|
var canonicalHeaders bytes.Buffer
|
|
|
|
for _, k := range headers {
|
|
|
|
canonicalHeaders.WriteString(k)
|
|
|
|
canonicalHeaders.WriteByte(':')
|
|
|
|
switch {
|
|
|
|
case k == "host":
|
|
|
|
canonicalHeaders.WriteString(req.URL.Host)
|
|
|
|
fallthrough
|
|
|
|
default:
|
|
|
|
for idx, v := range vals[k] {
|
|
|
|
if idx > 0 {
|
|
|
|
canonicalHeaders.WriteByte(',')
|
|
|
|
}
|
|
|
|
canonicalHeaders.WriteString(v)
|
|
|
|
}
|
|
|
|
canonicalHeaders.WriteByte('\n')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
signedHeaders := strings.Join(headers, ";")
|
|
|
|
|
|
|
|
req.URL.RawQuery = strings.Replace(req.URL.Query().Encode(), "+", "%20", -1)
|
2015-10-09 04:56:41 +02:00
|
|
|
encodedPath := getURLEncodedName(req.URL.Path)
|
2015-09-20 21:44:44 +02:00
|
|
|
// convert any space strings back to "+"
|
|
|
|
encodedPath = strings.Replace(encodedPath, "+", "%20", -1)
|
|
|
|
|
|
|
|
//
|
|
|
|
// canonicalRequest =
|
|
|
|
// <HTTPMethod>\n
|
|
|
|
// <CanonicalURI>\n
|
|
|
|
// <CanonicalQueryString>\n
|
|
|
|
// <CanonicalHeaders>\n
|
|
|
|
// <SignedHeaders>\n
|
|
|
|
// <HashedPayload>
|
|
|
|
//
|
|
|
|
canonicalRequest := strings.Join([]string{
|
|
|
|
req.Method,
|
|
|
|
encodedPath,
|
|
|
|
req.URL.RawQuery,
|
|
|
|
canonicalHeaders.String(),
|
|
|
|
signedHeaders,
|
|
|
|
hashedPayload,
|
|
|
|
}, "\n")
|
|
|
|
|
|
|
|
scope := strings.Join([]string{
|
|
|
|
t.Format(yyyymmdd),
|
|
|
|
"milkyway",
|
|
|
|
"s3",
|
|
|
|
"aws4_request",
|
|
|
|
}, "/")
|
|
|
|
|
|
|
|
stringToSign := authHeaderPrefix + "\n" + t.Format(iso8601Format) + "\n"
|
|
|
|
stringToSign = stringToSign + scope + "\n"
|
|
|
|
stringToSign = stringToSign + hex.EncodeToString(sum256([]byte(canonicalRequest)))
|
|
|
|
|
|
|
|
date := sumHMAC([]byte("AWS4"+s.secretAccessKey), []byte(t.Format(yyyymmdd)))
|
|
|
|
region := sumHMAC(date, []byte("milkyway"))
|
|
|
|
service := sumHMAC(region, []byte("s3"))
|
|
|
|
signingKey := sumHMAC(service, []byte("aws4_request"))
|
|
|
|
|
|
|
|
signature := hex.EncodeToString(sumHMAC(signingKey, []byte(stringToSign)))
|
|
|
|
|
|
|
|
// final Authorization header
|
|
|
|
parts := []string{
|
|
|
|
authHeaderPrefix + " Credential=" + s.accessKeyID + "/" + scope,
|
|
|
|
"SignedHeaders=" + signedHeaders,
|
|
|
|
"Signature=" + signature,
|
|
|
|
}
|
|
|
|
auth := strings.Join(parts, ", ")
|
|
|
|
req.Header.Set("Authorization", auth)
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestAuth(c *C) {
|
|
|
|
secretID, err := generateSecretAccessKey()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
accessID, err := generateAccessKeyID()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
c.Assert(len(secretID), Equals, minioSecretID)
|
|
|
|
c.Assert(len(accessID), Equals, minioAccessID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MyAPIFSCacheSuite) TestDeleteBucket(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/deletebucket", 0, nil)
|
2015-07-16 23:08:33 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
client := http.Client{}
|
2015-07-16 23:08:33 +02:00
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
2015-10-16 20:26:01 +02:00
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
request, err = s.newRequest("DELETE", testAPIFSCacheServer.URL+"/deletebucket", 0, nil)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
2015-10-17 05:02:37 +02:00
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNoContent)
|
2015-07-16 23:08:33 +02:00
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestDeleteObject(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/deletebucketobject", 0, nil)
|
2015-07-16 23:08:33 +02:00
|
|
|
c.Assert(err, IsNil)
|
2015-10-16 20:26:01 +02:00
|
|
|
|
|
|
|
client := http.Client{}
|
2015-07-16 23:08:33 +02:00
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
2015-10-16 20:26:01 +02:00
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/deletebucketobject/myobject", 0, nil)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
request, err = s.newRequest("DELETE", testAPIFSCacheServer.URL+"/deletebucketobject/myobject", 0, nil)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
2015-10-17 05:02:37 +02:00
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNoContent)
|
2015-07-16 23:08:33 +02:00
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestNonExistantBucket(c *C) {
|
|
|
|
request, err := s.newRequest("HEAD", testAPIFSCacheServer.URL+"/nonexistantbucket", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestEmptyObject(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/emptyobject", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/emptyobject/object", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/emptyobject/object", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, buffer.Bytes()))
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestBucket(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/bucket", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("HEAD", testAPIFSCacheServer.URL+"/bucket", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestObject(c *C) {
|
2015-07-12 21:40:38 +02:00
|
|
|
buffer := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/testobject", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/testobject/object", int64(buffer.Len()), buffer)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/testobject/object", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(responseBody, DeepEquals, []byte("hello world"))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestMultipleObjects(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/multipleobjects", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/multipleobjects/object", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
|
|
|
|
|
|
|
|
//// test object 1
|
|
|
|
|
|
|
|
// get object
|
|
|
|
buffer1 := bytes.NewReader([]byte("hello one"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/multipleobjects/object1", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/multipleobjects/object1", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
// verify response data
|
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello one")))
|
|
|
|
|
|
|
|
buffer2 := bytes.NewReader([]byte("hello two"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/multipleobjects/object2", int64(buffer2.Len()), buffer2)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/multipleobjects/object2", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
// verify response data
|
|
|
|
responseBody, err = ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello two")))
|
|
|
|
|
|
|
|
buffer3 := bytes.NewReader([]byte("hello three"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/multipleobjects/object3", int64(buffer3.Len()), buffer3)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/multipleobjects/object3", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
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")))
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestNotImplemented(c *C) {
|
|
|
|
request, err := s.newRequest("GET", testAPIFSCacheServer.URL+"/bucket/object?policy", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNotImplemented)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestHeader(c *C) {
|
|
|
|
request, err := s.newRequest("GET", testAPIFSCacheServer.URL+"/bucket/object", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestPutBucket(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/put-bucket", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestPutObject(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/put-object", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
buffer1 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/put-object/object", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestListBuckets(c *C) {
|
|
|
|
request, err := s.newRequest("GET", testAPIFSCacheServer.URL+"/", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-09-19 09:52:01 +02:00
|
|
|
var results ListBucketsResponse
|
2015-07-12 21:40:38 +02:00
|
|
|
decoder := xml.NewDecoder(response.Body)
|
|
|
|
err = decoder.Decode(&results)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestNotBeAbleToCreateObjectInNonexistantBucket(c *C) {
|
2015-07-12 21:40:38 +02:00
|
|
|
buffer1 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/innonexistantbucket/object", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestHeadOnObject(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/headonobject", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
buffer1 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/headonobject/object1", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("HEAD", testAPIFSCacheServer.URL+"/headonobject/object1", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestHeadOnBucket(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/headonbucket", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("HEAD", testAPIFSCacheServer.URL+"/headonbucket", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestXMLNameNotInBucketListJson(c *C) {
|
|
|
|
request, err := s.newRequest("GET", testAPIFSCacheServer.URL+"/", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
byteResults, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(strings.Contains(string(byteResults), "XML"), Equals, false)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestXMLNameNotInObjectListJson(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/xmlnamenotinobjectlistjson", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/xmlnamenotinobjectlistjson", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
byteResults, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(strings.Contains(string(byteResults), "XML"), Equals, false)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestContentTypePersists(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/contenttype-persists", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
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"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/contenttype-persists/one", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
delete(request.Header, "Content-Type")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("HEAD", testAPIFSCacheServer.URL+"/contenttype-persists/one", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/contenttype-persists/one", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
|
|
|
|
|
|
|
buffer2 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/contenttype-persists/two", int64(buffer2.Len()), buffer2)
|
2015-07-12 21:40:38 +02:00
|
|
|
delete(request.Header, "Content-Type")
|
|
|
|
request.Header.Add("Content-Type", "application/json")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("HEAD", testAPIFSCacheServer.URL+"/contenttype-persists/two", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/contenttype-persists/two", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestPartialContent(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/partial-content", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
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"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/partial-content/bar", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
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
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/partial-content/bar", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
request.Header.Add("Range", "bytes=6-7")
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusPartialContent)
|
|
|
|
partialObject, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
c.Assert(string(partialObject), Equals, "Wo")
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestListObjectsHandlerErrors(c *C) {
|
|
|
|
request, err := s.newRequest("GET", testAPIFSCacheServer.URL+"/objecthandlererrors-.", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/objecthandlererrors", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
|
2015-07-17 02:32:33 +02:00
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/objecthandlererrors", 0, nil)
|
2015-07-17 02:32:33 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/objecthandlererrors?max-keys=-2", 0, nil)
|
2015-07-17 02:32:33 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
2015-09-18 23:48:01 +02:00
|
|
|
verifyError(c, response, "InvalidArgument", "Argument maxKeys must be an integer between 0 and 2147483647.", http.StatusBadRequest)
|
2015-07-12 21:40:38 +02:00
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestPutBucketErrors(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/putbucket-.", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/putbucket", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/putbucket", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "private")
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "BucketAlreadyExists", "The requested bucket name is not available.", http.StatusConflict)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/putbucket?acl", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
request.Header.Add("x-amz-acl", "unknown")
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NotImplemented", "A header you provided implies functionality that is not implemented.", http.StatusNotImplemented)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestGetObjectErrors(c *C) {
|
|
|
|
request, err := s.newRequest("GET", testAPIFSCacheServer.URL+"/getobjecterrors", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/getobjecterrors", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/getobjecterrors/bar", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
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)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/getobjecterrors-./bar", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestGetObjectRangeErrors(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/getobjectrangeerrors", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
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"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/getobjectrangeerrors/bar", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/getobjectrangeerrors/bar", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
request.Header.Add("Range", "bytes=7-6")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
verifyError(c, response, "InvalidRange", "The requested range cannot be satisfied.", http.StatusRequestedRangeNotSatisfiable)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestObjectMultipartAbort(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/objectmultipartabort", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, 200)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("POST", testAPIFSCacheServer.URL+"/objectmultipartabort/object?uploads", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder := xml.NewDecoder(response.Body)
|
2015-09-19 09:52:01 +02:00
|
|
|
newResponse := &InitiateMultipartUploadResponse{}
|
2015-07-12 21:40:38 +02:00
|
|
|
|
|
|
|
err = decoder.Decode(newResponse)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
|
|
|
|
uploadID := newResponse.UploadID
|
|
|
|
|
|
|
|
buffer1 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=1", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response1, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response1.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
buffer2 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/objectmultipartabort/object?uploadId="+uploadID+"&partNumber=2", int64(buffer2.Len()), buffer2)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response2, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response2.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("DELETE", testAPIFSCacheServer.URL+"/objectmultipartabort/object?uploadId="+uploadID, 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response3, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response3.StatusCode, Equals, http.StatusNoContent)
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestBucketMultipartList(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/bucketmultipartlist", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, 200)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("POST", testAPIFSCacheServer.URL+"/bucketmultipartlist/object?uploads", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder := xml.NewDecoder(response.Body)
|
2015-09-19 09:52:01 +02:00
|
|
|
newResponse := &InitiateMultipartUploadResponse{}
|
2015-07-12 21:40:38 +02:00
|
|
|
|
|
|
|
err = decoder.Decode(newResponse)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
|
|
|
|
uploadID := newResponse.UploadID
|
|
|
|
|
|
|
|
buffer1 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=1", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response1, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response1.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
buffer2 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=2", int64(buffer2.Len()), buffer2)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response2, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response2.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/bucketmultipartlist?uploads", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response3, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response3.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder = xml.NewDecoder(response3.Body)
|
2015-09-19 09:52:01 +02:00
|
|
|
newResponse3 := &ListMultipartUploadsResponse{}
|
2015-07-12 21:40:38 +02:00
|
|
|
err = decoder.Decode(newResponse3)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(newResponse3.Bucket, Equals, "bucketmultipartlist")
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestObjectMultipartList(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/objectmultipartlist", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, 200)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("POST", testAPIFSCacheServer.URL+"/objectmultipartlist/object?uploads", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder := xml.NewDecoder(response.Body)
|
2015-09-19 09:52:01 +02:00
|
|
|
newResponse := &InitiateMultipartUploadResponse{}
|
2015-07-12 21:40:38 +02:00
|
|
|
|
|
|
|
err = decoder.Decode(newResponse)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
|
|
|
|
uploadID := newResponse.UploadID
|
|
|
|
|
|
|
|
buffer1 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=1", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response1, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response1.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
buffer2 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/objectmultipartlist/object?uploadId="+uploadID+"&partNumber=2", int64(buffer2.Len()), buffer2)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response2, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response2.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/objectmultipartlist/object?uploadId="+uploadID, 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response3, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response3.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("GET", testAPIFSCacheServer.URL+"/objectmultipartlist/object?max-parts=-2&uploadId="+uploadID, 0, nil)
|
2015-07-17 02:32:33 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response4, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
2015-09-18 23:48:01 +02:00
|
|
|
verifyError(c, response4, "InvalidArgument", "Argument maxParts must be an integer between 1 and 10000.", http.StatusBadRequest)
|
2015-07-12 21:40:38 +02:00
|
|
|
}
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
func (s *MyAPIFSCacheSuite) TestObjectMultipart(c *C) {
|
|
|
|
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/objectmultiparts", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, 200)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("POST", testAPIFSCacheServer.URL+"/objectmultiparts/object?uploads", 0, nil)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
decoder := xml.NewDecoder(response.Body)
|
2015-09-19 09:52:01 +02:00
|
|
|
newResponse := &InitiateMultipartUploadResponse{}
|
2015-07-12 21:40:38 +02:00
|
|
|
|
|
|
|
err = decoder.Decode(newResponse)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(len(newResponse.UploadID) > 0, Equals, true)
|
|
|
|
uploadID := newResponse.UploadID
|
|
|
|
|
|
|
|
buffer1 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=1", int64(buffer1.Len()), buffer1)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response1, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response1.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
buffer2 := bytes.NewReader([]byte("hello world"))
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/objectmultiparts/object?uploadId="+uploadID+"&partNumber=2", int64(buffer2.Len()), buffer2)
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client = http.Client{}
|
|
|
|
response2, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response2.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
// complete multipart upload
|
2015-10-16 20:26:01 +02:00
|
|
|
completeUploads := &fs.CompleteMultipartUpload{
|
|
|
|
Part: []fs.CompletePart{
|
2015-07-12 21:40:38 +02:00
|
|
|
{
|
|
|
|
PartNumber: 1,
|
|
|
|
ETag: response1.Header.Get("ETag"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PartNumber: 2,
|
|
|
|
ETag: response2.Header.Get("ETag"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
completeBytes, err := xml.Marshal(completeUploads)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
2015-10-16 20:26:01 +02:00
|
|
|
request, err = s.newRequest("POST", testAPIFSCacheServer.URL+"/objectmultiparts/object?uploadId="+uploadID, int64(len(completeBytes)), bytes.NewReader(completeBytes))
|
2015-07-12 21:40:38 +02:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
}
|
2015-10-07 08:32:20 +02:00
|
|
|
|
|
|
|
func verifyError(c *C, response *http.Response, code, description string, statusCode int) {
|
|
|
|
data, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
errorResponse := APIErrorResponse{}
|
|
|
|
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)
|
|
|
|
}
|