2015-07-12 15:40:38 -04:00
/ *
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
* Minio Cloud Storage , ( C ) 2015 , 2016 Minio , Inc .
2015-07-12 15:40:38 -04: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 03:52:01 -04:00
package main
2015-07-12 15:40:38 -04:00
import (
"bytes"
2016-04-11 04:29:18 -04:00
"crypto/md5"
2016-06-21 15:10:18 -04:00
"encoding/base64"
2016-06-25 06:03:27 -04:00
"encoding/hex"
2016-06-21 15:10:18 -04:00
"encoding/xml"
2016-06-13 05:53:09 -04:00
"fmt"
2016-06-29 05:30:36 -04:00
"io"
2015-07-12 15:40:38 -04:00
"io/ioutil"
2016-06-25 06:03:27 -04:00
"math/rand"
2016-06-21 15:10:18 -04:00
"net/http"
2016-03-07 22:07:43 -05:00
"sync"
2015-09-20 15:44:44 -04:00
"time"
2015-07-12 15:40:38 -04:00
2015-08-22 21:34:00 -04:00
. "gopkg.in/check.v1"
2015-07-12 15:40:38 -04:00
)
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
// API suite container.
2016-06-29 05:30:36 -04:00
type TestSuiteFS struct {
2016-06-21 15:10:18 -04:00
testServer TestServer
2016-06-29 05:30:36 -04:00
endPoint string
accessKey string
secretKey string
2015-07-12 15:40:38 -04:00
}
2016-06-21 15:10:18 -04:00
// Initializing the test suite.
2016-06-29 05:30:36 -04:00
var _ = Suite ( & TestSuiteFS { } )
2015-07-12 15:40:38 -04:00
2016-06-21 15:10:18 -04:00
// Setting up the test suite.
// Starting the Test server with temporary FS backend.
2016-06-29 05:30:36 -04:00
func ( s * TestSuiteFS ) SetUpSuite ( c * C ) {
2016-06-21 15:10:18 -04:00
s . testServer = StartTestServer ( c , "FS" )
2016-06-29 05:30:36 -04:00
s . endPoint = s . testServer . Server . URL
s . accessKey = s . testServer . AccessKey
s . secretKey = s . testServer . SecretKey
2015-07-12 15:40:38 -04:00
}
2016-06-21 15:10:18 -04:00
// Called implicitly by "gopkg.in/check.v1" after all tests are run.
2016-06-29 05:30:36 -04:00
func ( s * TestSuiteFS ) TearDownSuite ( c * C ) {
2016-06-21 15:10:18 -04:00
s . testServer . Stop ( )
2016-06-20 09:18:47 -04:00
}
2016-06-29 05:30:36 -04:00
func ( s * TestSuiteFS ) TestAuth ( c * C ) {
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
secretID , err := genSecretAccessKey ( )
2015-10-16 14:26:01 -04:00
c . Assert ( err , IsNil )
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
accessID , err := genAccessKeyID ( )
2015-10-16 14:26:01 -04:00
c . Assert ( err , IsNil )
c . Assert ( len ( secretID ) , Equals , minioSecretID )
c . Assert ( len ( accessID ) , Equals , minioAccessID )
}
2016-06-29 05:30:36 -04:00
// TestBucketPolicy - Inserts the bucket policy and verifies it by fetching the policy back.
// Deletes the policy and verifies the deletion by fetching it back.
func ( s * TestSuiteFS ) TestBucketPolicy ( c * C ) {
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
// Sample bucket policy.
bucketPolicyBuf := ` {
"Version" : "2012-10-17" ,
"Statement" : [
{
"Action" : [
"s3:GetBucketLocation" ,
"s3:ListBucket"
] ,
"Effect" : "Allow" ,
"Principal" : {
"AWS" : [
"*"
]
} ,
"Resource" : [
2016-06-29 05:30:36 -04:00
"arn:aws:s3:::%s"
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
]
} ,
{
"Action" : [
"s3:GetObject"
] ,
"Effect" : "Allow" ,
"Principal" : {
"AWS" : [
"*"
]
} ,
"Resource" : [
2016-06-29 05:30:36 -04:00
"arn:aws:s3:::%s/this*"
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
]
}
]
} `
2016-06-29 05:30:36 -04:00
// generate a random bucket Name.
bucketName := getRandomBucketName ( )
// create the policy statement string with the randomly generated bucket name.
bucketPolicyStr := fmt . Sprintf ( bucketPolicyBuf , bucketName , bucketName )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the request.
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the http response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
/// Put a new bucket policy.
request , err = newTestRequest ( "PUT" , getPutPolicyURL ( s . endPoint , bucketName ) ,
int64 ( len ( bucketPolicyStr ) ) , bytes . NewReader ( [ ] byte ( bucketPolicyStr ) ) , s . accessKey , s . secretKey )
c . Assert ( err , IsNil )
client = http . Client { }
// execute the HTTP request to create bucket.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
// Fetch the uploaded policy.
2016-06-29 05:30:36 -04:00
request , err = newTestRequest ( "GET" , getGetPolicyURL ( s . endPoint , bucketName ) , 0 , nil ,
s . accessKey , s . secretKey )
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
bucketPolicyReadBuf , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
// Verify if downloaded policy matches with previousy uploaded.
2016-06-29 05:30:36 -04:00
c . Assert ( bytes . Equal ( [ ] byte ( bucketPolicyStr ) , bucketPolicyReadBuf ) , Equals , true )
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
// Delete policy.
2016-06-29 05:30:36 -04:00
request , err = newTestRequest ( "DELETE" , getDeletePolicyURL ( s . endPoint , bucketName ) , 0 , nil ,
s . accessKey , s . secretKey )
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2016-05-02 19:58:10 -04:00
// Verify if the policy was indeed deleted.
2016-06-29 05:30:36 -04:00
request , err = newTestRequest ( "GET" , getGetPolicyURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-05-02 19:58:10 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusNotFound )
bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/*"
]
},
{
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Effect": "Deny",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::jarjarbing/restic/key/*"
]
}
]
}
```
2016-03-15 13:38:04 -04:00
}
2016-06-29 05:30:36 -04:00
// TestDeleteBucket - validates DELETE bucket operation.
func ( s * TestSuiteFS ) TestDeleteBucket ( c * C ) {
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-16 17:08:33 -04:00
c . Assert ( err , IsNil )
2015-10-16 14:26:01 -04:00
client := http . Client { }
2015-07-16 17:08:33 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the response status code.
2015-10-16 14:26:01 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// construct request to delete the bucket.
request , err = newTestRequest ( "DELETE" , getDeleteBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-10-16 14:26:01 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Assert the response status code.
2015-10-16 23:02:37 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2015-07-16 17:08:33 -04:00
}
2016-06-29 05:30:36 -04:00
// TestDeleteBucketNotEmpty - Validates the operation during an attempt to delete a non-empty bucket.
func ( s * TestSuiteFS ) TestDeleteBucketNotEmpty ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-05-05 04:35:21 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the request.
2016-05-05 04:35:21 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the response status code.
2016-05-05 04:35:21 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// generate http request for an object upload.
// "test-object" is the object name.
objectName := "test-object"
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-05-05 04:35:21 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the request to complete object upload.
2016-05-05 04:35:21 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the status code of the response.
2016-05-05 04:35:21 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// constructing http request to delete the bucket.
// making an attempt to delete an non-empty bucket.
// expected to fail.
request , err = newTestRequest ( "DELETE" , getDeleteBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-05-05 04:35:21 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusConflict )
2016-06-29 05:30:36 -04:00
2016-05-05 04:35:21 -04:00
}
2016-05-14 18:47:19 -04:00
// Tests delete object responses and success.
2016-06-29 05:30:36 -04:00
func ( s * TestSuiteFS ) TestDeleteObject ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-16 17:08:33 -04:00
c . Assert ( err , IsNil )
2015-10-16 14:26:01 -04:00
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the request.
2015-07-16 17:08:33 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the http response status code.
2015-10-16 14:26:01 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
objectName := "prefix/myobject"
// obtain http request to upload object.
// object Name contains a prefix.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-10-16 14:26:01 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the http request.
2015-10-16 14:26:01 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the status of http response.
2015-10-16 14:26:01 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// object name was "prefix/myobject", an attempt to delelte "prefix"
2016-06-17 01:18:43 -04:00
// Should not delete "prefix/myobject"
2016-06-29 05:30:36 -04:00
request , err = newTestRequest ( "DELETE" , getDeleteObjectURL ( s . endPoint , bucketName , "prefix" ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-17 01:18:43 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2016-06-29 05:30:36 -04:00
// create http request to HEAD on the object.
// this helps to validate the existence of the bucket.
request , err = newTestRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-10-16 14:26:01 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
2015-10-16 14:26:01 -04:00
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Assert the HTTP response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
// create HTTP request to delete the object.
request , err = newTestRequest ( "DELETE" , getDeleteObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
c . Assert ( err , IsNil )
client = http . Client { }
// execute the http request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
// assert the http response status code.
2015-10-16 23:02:37 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2016-05-14 18:47:19 -04:00
2016-06-29 05:30:36 -04:00
// Delete of non-existent data should return success.
request , err = newTestRequest ( "DELETE" , getDeleteObjectURL ( s . endPoint , bucketName , "prefix/myobject1" ) ,
0 , nil , s . accessKey , s . secretKey )
2016-05-14 18:47:19 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the http request.
2016-05-14 18:47:19 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the http response status.
2016-05-14 18:47:19 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2015-07-16 17:08:33 -04:00
}
2016-06-29 05:30:36 -04:00
// TestNonExistentBucket - Asserts response for HEAD on non-existent bucket.
func ( s * TestSuiteFS ) TestNonExistentBucket ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// create request to HEAD on the bucket.
// HEAD on an bucket helps validate the existence of the bucket.
request , err := newTestRequest ( "HEAD" , getHEADBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the http request.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Assert the response.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusNotFound )
}
2016-06-29 05:30:36 -04:00
// TestEmptyObject - Asserts the response for operation on a 0 byte object.
func ( s * TestSuiteFS ) TestEmptyObject ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the http request.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the http response status code.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
objectName := "test-object"
// construct http request for uploading the object.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the upload request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the http response.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// make HTTP request to fetch the object.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the http request to fetch object.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the http response status code.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 05:30:36 -04:00
// extract the body of the response.
2015-07-12 15:40:38 -04:00
responseBody , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the http response body content.
2015-07-12 15:40:38 -04:00
c . Assert ( true , Equals , bytes . Equal ( responseBody , buffer . Bytes ( ) ) )
}
2016-06-29 05:30:36 -04:00
func ( s * TestSuiteFS ) TestBucket ( c * C ) {
2016-06-21 15:10:18 -04:00
request , err := newTestRequest ( "PUT" , s . testServer . Server . URL + "/bucket" ,
0 , nil , s . testServer . AccessKey , s . testServer . SecretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-21 15:10:18 -04:00
request , err = newTestRequest ( "HEAD" , s . testServer . Server . URL + "/bucket" ,
0 , nil , s . testServer . AccessKey , s . testServer . SecretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
}
2016-06-29 05:30:36 -04:00
// TestGetObject - Tests fetching of a small object after its insertion into the bucket.
func ( s * TestSuiteFS ) TestObjectGet ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
2015-07-12 15:40:38 -04:00
buffer := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the make bucket http request.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the response http status code.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
objectName := "testObject"
// create HTTP request to upload the object.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer . Len ( ) ) , buffer , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the object.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the HTTP response status code.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// create HTTP request to fetch the object.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the http request to fetch the object.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the http response status code.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// extract response body content.
2015-07-12 15:40:38 -04:00
responseBody , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the HTTP response body content with the expected content.
2015-07-12 15:40:38 -04:00
c . Assert ( responseBody , DeepEquals , [ ] byte ( "hello world" ) )
}
2016-06-29 05:30:36 -04:00
// TestMultipleObjects - Validates upload and fetching of multiple object into the bucket.
func ( s * TestSuiteFS ) TestMultipleObjects ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create the bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// constructing HTTP request to fetch a non-existent object.
// expected to fail, error response asserted for expected error values later.
objectName := "testObject"
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Asserting the error response with the expected values.
2015-07-12 15:40:38 -04:00
verifyError ( c , response , "NoSuchKey" , "The specified key does not exist." , http . StatusNotFound )
2016-06-29 05:30:36 -04:00
objectName = "testObject1"
// content for the object to be uploaded.
2015-07-12 15:40:38 -04:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello one" ) )
2016-06-29 05:30:36 -04:00
// create HTTP request for the object upload.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request for object upload.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the returned values.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// create HTTP request to fetch the object which was uploaded above.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert whether 200 OK response status is obtained.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// extract the response body.
2015-07-12 15:40:38 -04:00
responseBody , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the content body for the expected object data.
2015-07-12 15:40:38 -04:00
c . Assert ( true , Equals , bytes . Equal ( responseBody , [ ] byte ( "hello one" ) ) )
2016-06-29 05:30:36 -04:00
// data for new object to be uploaded.
2015-07-12 15:40:38 -04:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello two" ) )
2016-06-29 05:30:36 -04:00
objectName = "testObject2"
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request for object upload.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the response status code for expected value 200 OK.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// fetch the object which was uploaded above.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to fetch the object.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// assert the response status code for expected value 200 OK.
2015-07-12 15:40:38 -04:00
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" ) ) )
2016-06-29 05:30:36 -04:00
// data for new object to be uploaded.
2015-07-12 15:40:38 -04:00
buffer3 := bytes . NewReader ( [ ] byte ( "hello three" ) )
2016-06-29 05:30:36 -04:00
objectName = "testObject3"
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer3 . Len ( ) ) , buffer3 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// verify the response code with the expected value of 200 OK.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// fetch the object which was uploaded above.
request , err = newTestRequest ( "GET" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// verify object.
2015-07-12 15:40:38 -04:00
responseBody , err = ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
c . Assert ( true , Equals , bytes . Equal ( responseBody , [ ] byte ( "hello three" ) ) )
}
2016-06-29 05:30:36 -04:00
// TestNotImplemented - Validates response for obtaining policy on an non-existent bucket and object.
func ( s * TestSuiteFS ) TestNotImplemented ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
request , err := newTestRequest ( "GET" , s . endPoint + "/" + bucketName + "/object?policy" ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusNotImplemented )
}
2016-06-29 05:30:36 -04:00
// TestHeader - Validates the error response for an attempt to fetch non-existent object.
func ( s * TestSuiteFS ) TestHeader ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// obtain HTTP request to fetch an object from non-existent bucket/object.
request , err := newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , "testObject" ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// asserting for the expected error response.
verifyError ( c , response , "NoSuchBucket" , "The specified bucket does not exist." , http . StatusNotFound )
2015-07-12 15:40:38 -04:00
}
2016-06-29 05:30:36 -04:00
func ( s * TestSuiteFS ) TestPutBucket ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
2016-03-07 22:07:43 -05:00
// Block 1: Testing for racey access
// The assertion is removed from this block since the purpose of this block is to find races
// The purpose this block is not to check for correctness of functionality
// Run the test with -race flag to utilize this
var wg sync . WaitGroup
for i := 0 ; i < ConcurrencyLevel ; i ++ {
wg . Add ( 1 )
go func ( ) {
defer wg . Done ( )
2016-06-29 05:30:36 -04:00
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-03-07 22:07:43 -05:00
c . Assert ( err , IsNil )
client := http . Client { }
response , err := client . Do ( request )
defer response . Body . Close ( )
} ( )
}
wg . Wait ( )
2016-06-29 05:30:36 -04:00
bucketName = getRandomBucketName ( )
2016-03-07 22:07:43 -05:00
//Block 2: testing for correctness of the functionality
2016-06-29 05:30:36 -04:00
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-03-07 22:07:43 -05:00
response . Body . Close ( )
2015-07-12 15:40:38 -04:00
}
2016-06-29 05:30:36 -04:00
// TestCopyObject - Validates copy object.
// The following is the test flow.
// 1. Create bucket.
// 2. Insert Object.
// 3. Use "X-Amz-Copy-Source" header to copy the previously inserted object.
// 4. Validate the content of copied object.
func ( s * TestSuiteFS ) TestCopyObject ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-02-27 06:04:52 -05:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2016-02-27 06:04:52 -05:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// content for the object to be inserted.
2016-02-27 06:04:52 -05:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
objectName := "testObject"
// create HTTP request for object upload.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
request . Header . Set ( "Content-Type" , "application/json" )
2016-02-27 06:04:52 -05:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request for object upload.
2016-02-27 06:04:52 -05:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
objectName2 := "testObject2"
// creating HTTP request for uploading the object.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName2 ) ,
0 , nil , s . accessKey , s . secretKey )
// setting the "X-Amz-Copy-Source" to allow copying the content of
// previously uploaded object.
request . Header . Set ( "X-Amz-Copy-Source" , "/" + bucketName + "/" + objectName )
2016-02-27 06:04:52 -05:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
// the content is expected to have the content of previous disk.
2016-02-27 06:04:52 -05:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// creating HTTP request to fetch the previously uploaded object.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName2 ) ,
0 , nil , s . accessKey , s . secretKey )
2016-02-27 06:04:52 -05:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// executing the HTTP request.
2016-02-27 06:04:52 -05:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// validating the response status code.
2016-02-27 06:04:52 -05:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// reading the response body.
// response body is expected to have the copied content of the first uploaded object.
2016-02-27 06:04:52 -05:00
object , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
c . Assert ( string ( object ) , Equals , "hello world" )
}
2016-06-29 05:30:36 -04:00
// TestPutObject - Tests successful put object request.
func ( s * TestSuiteFS ) TestPutObject ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// content for new object upload.
2015-07-12 15:40:38 -04:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
objectName := "testObject"
// creating HTTP request for object upload.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
c . Assert ( err , IsNil )
// execute the HTTP request for object upload.
response , err = client . Do ( request )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2015-07-12 15:40:38 -04:00
2016-06-29 05:30:36 -04:00
// fetch the object back and verify its contents.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
c . Assert ( err , IsNil )
// execute the HTTP request to fetch the object.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
c . Assert ( response . ContentLength , Equals , int64 ( len ( [ ] byte ( "hello world" ) ) ) )
var buffer2 bytes . Buffer
// retrive the contents of response body.
n , err := io . Copy ( & buffer2 , response . Body )
c . Assert ( err , IsNil )
c . Assert ( n , Equals , int64 ( len ( [ ] byte ( "hello world" ) ) ) )
// asserted the contents of the fetched object with the expected result.
c . Assert ( true , Equals , bytes . Equal ( buffer2 . Bytes ( ) , [ ] byte ( "hello world" ) ) )
2015-07-12 15:40:38 -04:00
}
2016-06-29 05:30:36 -04:00
// TestListBuckets - Make request for listing of all buckets.
// XML response is parsed.
// Its success verifies the format of the response.
func ( s * TestSuiteFS ) TestListBuckets ( c * C ) {
// create HTTP request for listing buckets.
request , err := newTestRequest ( "GET" , getListBucketURL ( s . endPoint ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to list buckets.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2015-09-19 03:52:01 -04:00
var results ListBucketsResponse
2016-06-29 05:30:36 -04:00
// parse the list bucket response.
2015-07-12 15:40:38 -04:00
decoder := xml . NewDecoder ( response . Body )
err = decoder . Decode ( & results )
2016-06-29 05:30:36 -04:00
// validating that the xml-decoding/parsing was successfull.
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
}
2016-06-29 05:30:36 -04:00
// TestNotBeAbleToCreateObjectInNonexistentBucket - Validates the error response
// on an attempt to upload an object into a non-existent bucket.
func ( s * TestSuiteFS ) TestPutObjectLongName ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-13 05:53:09 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2016-06-13 05:53:09 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// content for the object to be uploaded.
2016-06-13 05:53:09 -04:00
buffer := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// make long object name.
2016-06-13 05:53:09 -04:00
longObjName := fmt . Sprintf ( "%0255d/%0255d/%0255d" , 1 , 1 , 1 )
2016-06-29 05:30:36 -04:00
// create new HTTP request to insert the object.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , longObjName ) ,
int64 ( buffer . Len ( ) ) , buffer , s . accessKey , s . secretKey )
2016-06-13 05:53:09 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2016-06-13 05:53:09 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// make long object name.
2016-06-13 05:53:09 -04:00
longObjName = fmt . Sprintf ( "%0256d" , 1 )
2016-06-29 05:30:36 -04:00
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , longObjName ) ,
int64 ( buffer . Len ( ) ) , buffer , s . accessKey , s . secretKey )
2016-06-13 05:53:09 -04:00
c . Assert ( err , IsNil )
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusNotFound )
}
2016-06-29 05:30:36 -04:00
// TestNotBeAbleToCreateObjectInNonexistentBucket - Validates the error response
// on an attempt to upload an object into a non-existent bucket.
func ( s * TestSuiteFS ) TestNotBeAbleToCreateObjectInNonexistentBucket ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// content of the object to be uploaded.
2015-07-12 15:40:38 -04:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// preparing for upload by generating the upload URL.
objectName := "test-object"
request , err := newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// Execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Assert the response error message.
2015-07-12 15:40:38 -04:00
verifyError ( c , response , "NoSuchBucket" , "The specified bucket does not exist." , http . StatusNotFound )
}
2016-06-29 05:30:36 -04:00
// TestHeadOnObjectLastModified - Asserts response for HEAD on an object.
// HEAD requests on an object validates the existence of the object.
// The responses for fetching the object when If-Modified-Since
// and If-Unmodified-Since headers set are validated.
// If-Modified-Since - Return the object only if it has been modified since the specified time, else return a 304 (not modified).
// If-Unmodified-Since - Return the object only if it has not been modified since the specified time, else return a 412 (precondition failed).
func ( s * TestSuiteFS ) TestHeadOnObjectLastModified ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// preparing for object upload.
objectName := "test-object"
// content for the object to be uploaded.
2015-07-12 15:40:38 -04:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// obtaining URL for uploading the object.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// executing the HTTP request to download the object.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// make HTTP request to obtain object info.
request , err = newTestRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// verify the status of the HTTP response.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-02-28 21:10:37 -05:00
2016-06-29 05:30:36 -04:00
// retrive the info of last modification time of the object from the response header.
2016-02-28 21:10:37 -05:00
lastModified := response . Header . Get ( "Last-Modified" )
2016-06-29 05:30:36 -04:00
// Parse it into time.Time structure.
2016-02-28 21:10:37 -05:00
t , err := time . Parse ( http . TimeFormat , lastModified )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// make HTTP request to obtain object info.
// But this time set the "If-Modified-Since" header to be a minute more than the actual
// last modified time of the object.
request , err = newTestRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-02-28 21:10:37 -05:00
c . Assert ( err , IsNil )
request . Header . Set ( "If-Modified-Since" , t . Add ( 1 * time . Minute ) . UTC ( ) . Format ( http . TimeFormat ) )
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Since the "If-Modified-Since" header was ahead in time compared to the actual modified time of the object
// expecting the response status to be http.StatusNotModified.
2016-02-28 21:10:37 -05:00
c . Assert ( response . StatusCode , Equals , http . StatusNotModified )
2016-06-29 05:30:36 -04:00
// Again, obtain the object info.
// This time setting "If-Unmodified-Since" to a time after the object is modified.
// As documented above, expecting http.StatusPreconditionFailed.
request , err = newTestRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-02-28 21:10:37 -05:00
c . Assert ( err , IsNil )
request . Header . Set ( "If-Unmodified-Since" , t . Add ( - 1 * time . Minute ) . UTC ( ) . Format ( http . TimeFormat ) )
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusPreconditionFailed )
2015-07-12 15:40:38 -04:00
}
2016-06-29 05:30:36 -04:00
// TestHeadOnBucket - Validates response for HEAD on the bucket.
// HEAD request on the bucket validates the existence of the bucket.
func ( s * TestSuiteFS ) TestHeadOnBucket ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getHEADBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// make HEAD request on the bucket.
request , err = newTestRequest ( "HEAD" , getHEADBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Asserting the response status for expected value of http.StatusOK.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
}
2016-06-29 05:30:36 -04:00
// TestContentTypePersists - Object upload with different Content-type is first done.
// And then a HEAD and GET request on these objects are done to validate if the same Content-Type set during upload persists.
func ( s * TestSuiteFS ) TestContentTypePersists ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// Uploading a new object with Content-Type "application/zip".
// content for the object to be uploaded.
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
objectName := "test-object.png"
// constructing HTTP request for object upload.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
delete ( request . Header , "Content-Type" )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request for object upload.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// Fetching the object info using HEAD request for the object which was uploaded above.
request , err = newTestRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Verify if the Content-Type header is set during the object persists.
2016-06-17 00:42:02 -04:00
c . Assert ( response . Header . Get ( "Content-Type" ) , Equals , "image/png" )
2015-07-12 15:40:38 -04:00
2016-06-29 05:30:36 -04:00
// Fetching the object itself and then verify the Content-Type header.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// Execute the HTTP to fetch the object.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// Verify if the Content-Type header is set during the object persists.
2016-06-17 00:42:02 -04:00
c . Assert ( response . Header . Get ( "Content-Type" ) , Equals , "image/png" )
2015-07-12 15:40:38 -04:00
2016-06-29 05:30:36 -04:00
// Uploading a new object with Content-Type "application/json".
objectName = "test-object.json"
2015-07-12 15:40:38 -04:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey )
// deleting the old header value.
2015-07-12 15:40:38 -04:00
delete ( request . Header , "Content-Type" )
2016-06-29 05:30:36 -04:00
// setting the request header to be application/json.
2015-07-12 15:40:38 -04:00
request . Header . Add ( "Content-Type" , "application/json" )
2016-06-29 05:30:36 -04:00
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Execute the HTTP request to upload the object.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// Obtain the info of the object which was uploaded above using HEAD request.
request , err = newTestRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Assert if the content-type header set during the object upload persists.
2016-06-17 00:42:02 -04:00
c . Assert ( response . Header . Get ( "Content-Type" ) , Equals , "application/json" )
2015-07-12 15:40:38 -04:00
2016-06-29 05:30:36 -04:00
// Fetch the object and assert whether the Content-Type header persists.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Assert if the content-type header set during the object upload persists.
2016-06-17 00:42:02 -04:00
c . Assert ( response . Header . Get ( "Content-Type" ) , Equals , "application/json" )
2015-07-12 15:40:38 -04:00
}
2016-06-29 05:30:36 -04:00
// TestPartialContent - Validating for GetObject with partial content request.
// By setting the Range header, A request to send specific bytes range of data from an
// already uploaded object can be done.
func ( s * TestSuiteFS ) TestPartialContent ( c * C ) {
2016-06-21 15:10:18 -04:00
request , err := newTestRequest ( "PUT" , s . testServer . Server . URL + "/partial-content" ,
0 , nil , s . testServer . AccessKey , s . testServer . SecretKey )
2015-07-12 15:40:38 -04: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" ) )
2016-06-21 15:10:18 -04:00
request , err = newTestRequest ( "PUT" , s . testServer . Server . URL + "/partial-content/bar" ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . testServer . AccessKey , s . testServer . SecretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
objectAPI: Fix object API interface, remove unnecessary structs.
ObjectAPI changes.
```
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsInfo, *probe.Error)
ListMultipartUploads(bucket, objectPrefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (ListMultipartsInfo, *probe.Error)
ListObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (ListPartsInfo, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []completePart) (ObjectInfo, *probe.Error)
```
2016-04-03 04:34:20 -04:00
// Prepare request
2016-06-21 15:10:18 -04:00
request , err = newTestRequest ( "GET" , s . testServer . Server . URL + "/partial-content/bar" ,
0 , nil , s . testServer . AccessKey , s . testServer . SecretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
request . Header . Add ( "Range" , "bytes=6-7" )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusPartialContent )
partialObject , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
c . Assert ( string ( partialObject ) , Equals , "Wo" )
}
2016-06-29 05:30:36 -04:00
// TestListObjectsHandlerErrors - Setting invalid parameters to List Objects
// and then asserting the error response with the expected one.
func ( s * TestSuiteFS ) TestListObjectsHandlerErrors ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2015-07-16 20:32:33 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// create HTTP request with invalid value of max-keys parameter.
// max-keys is set to -2.
request , err = newTestRequest ( "GET" , getListObjectsURL ( s . endPoint , bucketName , "-2" ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-16 20:32:33 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2015-07-16 20:32:33 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// validating the error response.
2015-09-18 17:48:01 -04:00
verifyError ( c , response , "InvalidArgument" , "Argument maxKeys must be an integer between 0 and 2147483647." , http . StatusBadRequest )
2015-07-12 15:40:38 -04:00
}
2016-06-29 05:30:36 -04:00
// TestPutBucketErrors - request for non valid bucket operation
// and validate it with expected error result.
func ( s * TestSuiteFS ) TestPutBucketErrors ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// generating a HTTP request to create bucket.
// using invalid bucket name.
request , err := newTestRequest ( "PUT" , s . endPoint + "/putbucket-." ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// expected to fail with error message "InvalidBucketName".
2015-07-12 15:40:38 -04:00
verifyError ( c , response , "InvalidBucketName" , "The specified bucket is not valid." , http . StatusBadRequest )
2016-06-29 05:30:36 -04:00
// HTTP request to create the bucket.
request , err = newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// make HTTP request to create the same bucket again.
// expected to fail with error message "BucketAlreadyOwnedByYou".
request , err = newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
verifyError ( c , response , "BucketAlreadyOwnedByYou" , "Your previous request to create the named bucket succeeded and you already own it." ,
http . StatusConflict )
2015-07-12 15:40:38 -04:00
2016-06-29 05:30:36 -04:00
// request for ACL.
// Since Minio server doesn't support ACL's the request is expected to fail with "NotImplemented" error message.
request , err = newTestRequest ( "PUT" , s . endPoint + "/" + bucketName + "?acl" ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
response , err = client . Do ( request )
c . Assert ( err , IsNil )
verifyError ( c , response , "NotImplemented" , "A header you provided implies functionality that is not implemented." , http . StatusNotImplemented )
}
2016-06-29 05:30:36 -04:00
func ( s * TestSuiteFS ) TestGetObjectLarge10MiB ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// form HTTP reqest to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create the bucket.
2016-06-25 06:03:27 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 05:30:36 -04:00
line := ` 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 123 " `
2016-06-25 06:03:27 -04:00
// Create 10MiB content where each line contains 1024 characters.
for i := 0 ; i < 10 * 1024 ; i ++ {
buffer . WriteString ( fmt . Sprintf ( "[%05d] %s\n" , i , line ) )
}
putContent := buffer . String ( )
buf := bytes . NewReader ( [ ] byte ( putContent ) )
2016-06-29 05:30:36 -04:00
objectName := "test-big-object"
// create HTTP request for object upload.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buf . Len ( ) ) , buf , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Assert the status code to verify successful upload.
2016-06-25 06:03:27 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// prepare HTTP requests to download the object.
request , err = newTestRequest ( "GET" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to download the object.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// extract the content from response body.
2016-06-25 06:03:27 -04:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Compare putContent and getContent.
2016-06-25 06:03:27 -04:00
c . Assert ( string ( getContent ) , Equals , putContent )
}
2016-06-29 05:30:36 -04:00
// TestGetObjectLarge11MiB - Tests validate fetching of an object of size 11MB.
func ( s * TestSuiteFS ) TestGetObjectLarge11MiB ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2016-06-25 06:03:27 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 05:30:36 -04:00
line := ` 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 123 `
2016-06-25 06:03:27 -04:00
// Create 11MiB content where each line contains 1024 characters.
for i := 0 ; i < 11 * 1024 ; i ++ {
buffer . WriteString ( fmt . Sprintf ( "[%05d] %s\n" , i , line ) )
}
putMD5 := sumMD5 ( buffer . Bytes ( ) )
2016-06-29 05:30:36 -04:00
objectName := "test-11Mb-object"
2016-06-25 06:03:27 -04:00
// Put object
buf := bytes . NewReader ( buffer . Bytes ( ) )
2016-06-29 05:30:36 -04:00
// create HTTP request foe object upload.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buf . Len ( ) ) , buf , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request for object upload.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// create HTTP request to download the object.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// fetch the content from response body.
2016-06-25 06:03:27 -04:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Get md5Sum of the response content.
getMD5 := sumMD5 ( getContent )
2016-06-25 06:03:27 -04:00
2016-06-29 05:30:36 -04:00
// Compare putContent and getContent.
2016-06-25 06:03:27 -04:00
c . Assert ( hex . EncodeToString ( putMD5 ) , Equals , hex . EncodeToString ( getMD5 ) )
}
// TestGetPartialObjectMisAligned - tests get object partially mis-aligned.
2016-06-29 05:30:36 -04:00
// create a large buffer of mis-aligned data and upload it.
// then make partial range requests to while fetching it back and assert the response content.
func ( s * TestSuiteFS ) TestGetPartialObjectMisAligned ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
2016-06-25 06:03:27 -04:00
0 , nil , s . testServer . AccessKey , s . testServer . SecretKey )
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create the bucket.
2016-06-25 06:03:27 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 05:30:36 -04:00
line := ` 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 123 `
2016-06-25 06:03:27 -04:00
rand . Seed ( time . Now ( ) . UTC ( ) . UnixNano ( ) )
// Create a misalgined data.
for i := 0 ; i < 13 * rand . Intn ( 1 << 16 ) ; i ++ {
buffer . WriteString ( fmt . Sprintf ( "[%05d] %s\n" , i , line [ : rand . Intn ( 1 << 8 ) ] ) )
}
putContent := buffer . String ( )
buf := bytes . NewReader ( [ ] byte ( putContent ) )
2016-06-29 05:30:36 -04:00
objectName := "test-big-file"
// HTTP request to upload the object.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
2016-06-25 06:03:27 -04:00
int64 ( buf . Len ( ) ) , buf , s . testServer . AccessKey , s . testServer . SecretKey )
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the object.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// test Cases containing data to make partial range requests.
// also has expected response data.
2016-06-25 06:03:27 -04:00
var testCases = [ ] struct {
byteRange string
expectedString string
} {
2016-06-29 05:30:36 -04:00
// request for byte range 10-11.
// expecting the result to contain only putContent[10:12] bytes.
2016-06-25 06:03:27 -04:00
{ "10-11" , putContent [ 10 : 12 ] } ,
2016-06-29 05:30:36 -04:00
// request for object data after the first byte.
2016-06-25 06:03:27 -04:00
{ "1-" , putContent [ 1 : ] } ,
2016-06-29 05:30:36 -04:00
// request for object data after the first byte.
2016-06-25 06:03:27 -04:00
{ "6-" , putContent [ 6 : ] } ,
2016-06-29 05:30:36 -04:00
// request for last 2 bytes of th object.
2016-06-25 06:03:27 -04:00
{ "-2" , putContent [ len ( putContent ) - 2 : ] } ,
2016-06-29 05:30:36 -04:00
// request for last 7 bytes of the object.
2016-06-25 06:03:27 -04:00
{ "-7" , putContent [ len ( putContent ) - 7 : ] } ,
}
for _ , t := range testCases {
2016-06-29 05:30:36 -04:00
// HTTP request to download the object.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
2016-06-25 06:03:27 -04:00
0 , nil , s . testServer . AccessKey , s . testServer . SecretKey )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Get partial content based on the byte range set.
2016-06-25 06:03:27 -04:00
request . Header . Add ( "Range" , "bytes=" + t . byteRange )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
2016-06-25 06:03:27 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusPartialContent )
2016-06-29 05:30:36 -04:00
// parse the HTTP response body.
2016-06-25 06:03:27 -04:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Compare putContent and getContent.
2016-06-25 06:03:27 -04:00
c . Assert ( string ( getContent ) , Equals , t . expectedString )
}
}
2016-06-29 05:30:36 -04:00
// TestGetPartialObjectLarge11MiB - Test validates partial content request for a 11MiB object.
func ( s * TestSuiteFS ) TestGetPartialObjectLarge11MiB ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create the bucket.
2016-06-25 06:03:27 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 05:30:36 -04:00
line := ` 234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 123 `
2016-06-25 06:03:27 -04:00
// Create 11MiB content where each line contains 1024
// characters.
for i := 0 ; i < 11 * 1024 ; i ++ {
buffer . WriteString ( fmt . Sprintf ( "[%05d] %s\n" , i , line ) )
}
putContent := buffer . String ( )
2016-06-29 05:30:36 -04:00
objectName := "test-large-11Mb-object"
2016-06-25 06:03:27 -04:00
buf := bytes . NewReader ( [ ] byte ( putContent ) )
2016-06-29 05:30:36 -04:00
// HTTP request to upload the object.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buf . Len ( ) ) , buf , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the object.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// HTTP request to download the object.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
// This range spans into first two blocks.
request . Header . Add ( "Range" , "bytes=10485750-10485769" )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
2016-06-25 06:03:27 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusPartialContent )
2016-06-29 05:30:36 -04:00
// read the downloaded content from the response body.
2016-06-25 06:03:27 -04:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Compare putContent and getContent.
2016-06-25 06:03:27 -04:00
c . Assert ( string ( getContent ) , Equals , putContent [ 10485750 : 10485770 ] )
}
2016-06-29 05:30:36 -04:00
// TestGetPartialObjectLarge11MiB - Test validates partial content request for a 10MiB object.
func ( s * TestSuiteFS ) TestGetPartialObjectLarge10MiB ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2016-06-25 06:03:27 -04:00
response , err := client . Do ( request )
2016-06-29 05:30:36 -04:00
// expecting the error to be nil.
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// expecting the HTTP response status code to 200 OK.
2016-06-25 06:03:27 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 05:30:36 -04:00
line := ` 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 , 1234567890 ,
1234567890 , 1234567890 , 1234567890 , 123 `
2016-06-25 06:03:27 -04:00
// Create 10MiB content where each line contains 1024 characters.
for i := 0 ; i < 10 * 1024 ; i ++ {
buffer . WriteString ( fmt . Sprintf ( "[%05d] %s\n" , i , line ) )
}
2016-06-29 05:30:36 -04:00
putContent := buffer . String ( )
2016-06-25 06:03:27 -04:00
buf := bytes . NewReader ( [ ] byte ( putContent ) )
2016-06-29 05:30:36 -04:00
objectName := "test-big-10Mb-file"
// HTTP request to upload the object.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buf . Len ( ) ) , buf , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the object.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// verify whether upload was successfull.
2016-06-25 06:03:27 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// HTTP request to download the object.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-06-25 06:03:27 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Get partial content based on the byte range set.
2016-06-25 06:03:27 -04:00
request . Header . Add ( "Range" , "bytes=2048-2058" )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to download the partila content.
2016-06-25 06:03:27 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
2016-06-25 06:03:27 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusPartialContent )
2016-06-29 05:30:36 -04:00
// read the downloaded content from the response body.
2016-06-25 06:03:27 -04:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Compare putContent and getContent.
2016-06-25 06:03:27 -04:00
c . Assert ( string ( getContent ) , Equals , putContent [ 2048 : 2059 ] )
}
2016-06-29 05:30:36 -04:00
// TestGetObjectErrors - Tests validate error response for invalid object operations.
func ( s * TestSuiteFS ) TestGetObjectErrors ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
objectName := "test-non-exitent-object"
// HTTP request to download the object.
// Since the specified object doesn't exist in the given bucket,
// expected to fail with error message "NoSuchKey"
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04: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 )
2016-06-29 05:30:36 -04:00
// request to download an object, but an invalid bucket name is set.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , "/getobjecterrors-." , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// expected to fail with "InvalidBucketName".
2015-07-12 15:40:38 -04:00
verifyError ( c , response , "InvalidBucketName" , "The specified bucket is not valid." , http . StatusBadRequest )
}
2016-06-29 05:30:36 -04:00
// TestGetObjectRangeErrors - Validate error response when object is fetched with incorrect byte range value.
func ( s * TestSuiteFS ) TestGetObjectRangeErrors ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// content for the object to be uploaded.
2015-07-12 15:40:38 -04:00
buffer1 := bytes . NewReader ( [ ] byte ( "Hello World" ) )
2016-06-29 05:30:36 -04:00
objectName := "test-object"
// HTTP request to upload the object.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the object.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// verify whether upload was successfull.
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// HTTP request to download the object.
request , err = newTestRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
// invalid byte range set.
2015-07-12 15:40:38 -04:00
request . Header . Add ( "Range" , "bytes=7-6" )
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// expected to fail with "InvalidRange" error message.
2015-07-12 15:40:38 -04:00
verifyError ( c , response , "InvalidRange" , "The requested range cannot be satisfied." , http . StatusRequestedRangeNotSatisfiable )
}
2016-06-29 05:30:36 -04:00
// TestObjectMultipartAbort - Test validates abortion of a multipart upload after uploading 2 parts.
func ( s * TestSuiteFS ) TestObjectMultipartAbort ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2015-07-12 15:40:38 -04:00
2016-06-29 05:30:36 -04:00
objectName := "test-multipart-object"
// construct HTTP request to initiate a NewMultipart upload.
request , err = newTestRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request initiating the new multipart upload.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// parse the response body and obtain the new upload ID.
2015-07-12 15:40:38 -04:00
decoder := xml . NewDecoder ( response . Body )
2015-09-19 03:52:01 -04:00
newResponse := & InitiateMultipartUploadResponse { }
2015-07-12 15:40:38 -04:00
err = decoder . Decode ( newResponse )
c . Assert ( err , IsNil )
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
2016-06-29 05:30:36 -04:00
// uploadID to be used for rest of the multipart operations on the object.
2015-07-12 15:40:38 -04:00
uploadID := newResponse . UploadID
2016-06-29 05:30:36 -04:00
// content for the part to be uploaded.
2015-07-12 15:40:38 -04:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// HTTP request for the part to be uploaded.
request , err = newTestRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "1" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the first part.
2015-07-12 15:40:38 -04:00
response1 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response1 . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// content for the second part to be uploaded.
2015-07-12 15:40:38 -04:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// HTTP request for the second part to be uploaded.
request , err = newTestRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "2" ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the second part.
2015-07-12 15:40:38 -04:00
response2 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response2 . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// HTTP request for aborting the multipart upload.
request , err = newTestRequest ( "DELETE" , getAbortMultipartUploadURL ( s . endPoint , bucketName , objectName , uploadID ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request to abort the multipart upload.
2015-07-12 15:40:38 -04:00
response3 , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// expecting the response status code to be http.StatusNoContent.
// The assertion validates the success of Abort Multipart operation.
2015-07-12 15:40:38 -04:00
c . Assert ( response3 . StatusCode , Equals , http . StatusNoContent )
}
2016-06-29 05:30:36 -04:00
// TestBucketMultipartList - Initiates a NewMultipart upload, uploads parts and validates listing of the parts.
func ( s * TestSuiteFS ) TestBucketMultipartList ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) , 0 ,
nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , 200 )
2016-06-29 05:30:36 -04:00
objectName := "test-multipart-object"
// construct HTTP request to initiate a NewMultipart upload.
request , err = newTestRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request initiating the new multipart upload.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// expecting the response status code to be http.StatusOK(200 OK) .
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// parse the response body and obtain the new upload ID.
2015-07-12 15:40:38 -04:00
decoder := xml . NewDecoder ( response . Body )
2015-09-19 03:52:01 -04:00
newResponse := & InitiateMultipartUploadResponse { }
2015-07-12 15:40:38 -04:00
err = decoder . Decode ( newResponse )
c . Assert ( err , IsNil )
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
2016-06-29 05:30:36 -04:00
// uploadID to be used for rest of the multipart operations on the object.
2015-07-12 15:40:38 -04:00
uploadID := newResponse . UploadID
2016-06-29 05:30:36 -04:00
// content for the part to be uploaded.
2015-07-12 15:40:38 -04:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// HTTP request for the part to be uploaded.
request , err = newTestRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "1" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the first part.
2015-07-12 15:40:38 -04:00
response1 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response1 . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// content for the second part to be uploaded.
2015-07-12 15:40:38 -04:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// HTTP request for the second part to be uploaded.
request , err = newTestRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "2" ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the second part.
2015-07-12 15:40:38 -04:00
response2 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response2 . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// HTTP request to ListMultipart Uploads.
request , err = newTestRequest ( "GET" , getListMultipartURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2015-07-12 15:40:38 -04:00
response3 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response3 . StatusCode , Equals , http . StatusOK )
2016-03-21 04:06:07 -04:00
// The reason to duplicate this structure here is to verify if the
// unmarshalling works from a client perspective, specifically
// while unmarshalling time.Time type for 'Initiated' field.
// time.Time does not honor xml marshaler, it means that we need
// to encode/format it before giving it to xml marshalling.
// This below check adds client side verification to see if its
// truly parseable.
2016-03-20 02:44:43 -04:00
// listMultipartUploadsResponse - format for list multipart uploads response.
type listMultipartUploadsResponse struct {
XMLName xml . Name ` xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListMultipartUploadsResult" json:"-" `
Bucket string
KeyMarker string
UploadIDMarker string ` xml:"UploadIdMarker" `
NextKeyMarker string
NextUploadIDMarker string ` xml:"NextUploadIdMarker" `
EncodingType string
MaxUploads int
IsTruncated bool
// All the in progress multipart uploads.
Uploads [ ] struct {
Key string
UploadID string ` xml:"UploadId" `
Initiator Initiator
Owner Owner
StorageClass string
Initiated time . Time // Keep this native to be able to parse properly.
}
Prefix string
Delimiter string
CommonPrefixes [ ] CommonPrefix
}
2016-06-29 05:30:36 -04:00
// parse the response body.
2015-07-12 15:40:38 -04:00
decoder = xml . NewDecoder ( response3 . Body )
2016-03-20 02:44:43 -04:00
newResponse3 := & listMultipartUploadsResponse { }
2015-07-12 15:40:38 -04:00
err = decoder . Decode ( newResponse3 )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Assert the bucket name in the response with the expected bucketName.
c . Assert ( newResponse3 . Bucket , Equals , bucketName )
// Assert the bucket name in the response with the expected bucketName.
c . Assert ( newResponse3 . IsTruncated , Equals , false )
2015-07-12 15:40:38 -04:00
}
2016-06-29 05:30:36 -04:00
// TestValidateObjectMultipartUploadID - Test Initiates a new multipart upload and validates the uploadID.
func ( s * TestSuiteFS ) TestValidateObjectMultipartUploadID ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-01-26 17:57:46 -05:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2016-01-26 17:57:46 -05:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , 200 )
2016-06-29 05:30:36 -04:00
objectName := "directory1/directory2/object"
// construct HTTP request to initiate a NewMultipart upload.
request , err = newTestRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-01-26 17:57:46 -05:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request initiating the new multipart upload.
2016-01-26 17:57:46 -05:00
response , err = client . Do ( request )
2016-04-13 14:32:47 -04:00
c . Assert ( err , IsNil )
2016-01-26 17:57:46 -05:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// parse the response body and obtain the new upload ID.
2016-01-26 17:57:46 -05:00
decoder := xml . NewDecoder ( response . Body )
newResponse := & InitiateMultipartUploadResponse { }
err = decoder . Decode ( newResponse )
2016-06-29 05:30:36 -04:00
// expecting the decoding error to be nil.
2016-01-26 17:57:46 -05:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Verifying for Upload ID value to be greater than 0.
2016-01-26 17:57:46 -05:00
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
}
2016-06-29 05:30:36 -04:00
// TestObjectMultipartListError - Initiates a NewMultipart upload, uploads parts and validates
// error response for an incorrect max-parts parameter .
func ( s * TestSuiteFS ) TestObjectMultipartListError ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , 200 )
2016-06-29 05:30:36 -04:00
objectName := "test-multipart-object"
// construct HTTP request to initiate a NewMultipart upload.
request , err = newTestRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request initiating the new multipart upload.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// parse the response body and obtain the new upload ID.
2015-07-12 15:40:38 -04:00
decoder := xml . NewDecoder ( response . Body )
2015-09-19 03:52:01 -04:00
newResponse := & InitiateMultipartUploadResponse { }
2015-07-12 15:40:38 -04:00
err = decoder . Decode ( newResponse )
c . Assert ( err , IsNil )
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
2016-06-29 05:30:36 -04:00
// uploadID to be used for rest of the multipart operations on the object.
2015-07-12 15:40:38 -04:00
uploadID := newResponse . UploadID
2016-06-29 05:30:36 -04:00
// content for the part to be uploaded.
2015-07-12 15:40:38 -04:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// HTTP request for the part to be uploaded.
request , err = newTestRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "1" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the first part.
2015-07-12 15:40:38 -04:00
response1 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response1 . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// content for the second part to be uploaded.
2015-07-12 15:40:38 -04:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 05:30:36 -04:00
// HTTP request for the second part to be uploaded.
request , err = newTestRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "2" ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the second part.
2015-07-12 15:40:38 -04:00
response2 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response2 . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// HTTP request to ListMultipart Uploads.
// max-keys is set to invalid value of -2.
request , err = newTestRequest ( "GET" , getListMultipartURLWithParams ( s . endPoint , bucketName , objectName , uploadID , "-2" ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-16 20:32:33 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// execute the HTTP request.
2015-07-16 20:32:33 -04:00
response4 , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Since max-keys parameter in the ListMultipart request set to invalid value of -2,
// its expected to fail with error message "InvalidArgument".
2015-09-18 17:48:01 -04:00
verifyError ( c , response4 , "InvalidArgument" , "Argument maxParts must be an integer between 1 and 10000." , http . StatusBadRequest )
2015-07-12 15:40:38 -04:00
}
2016-06-29 05:30:36 -04:00
// TestObjectValidMD5 - First uploads an object with a valid Content-Md5 header and verifies the status,
// then upload an object in a wrong Content-Md5 and validate the error response.
func ( s * TestSuiteFS ) TestObjectValidMD5 ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2016-05-11 19:13:37 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2016-05-11 19:13:37 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , 200 )
// Create a byte array of 5MB.
2016-06-29 05:30:36 -04:00
// content for the object to be uploaded.
2016-05-11 19:13:37 -04:00
data := bytes . Repeat ( [ ] byte ( "0123456789abcdef" ) , 5 * 1024 * 1024 / 16 )
2016-06-29 05:30:36 -04:00
// calculate md5Sum of the data.
2016-05-11 19:13:37 -04:00
hasher := md5 . New ( )
hasher . Write ( data )
md5Sum := hasher . Sum ( nil )
buffer1 := bytes . NewReader ( data )
2016-06-29 05:30:36 -04:00
objectName := "test-1-object"
// HTTP request for the object to be uploaded.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2016-05-11 19:13:37 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// set the Content-Md5 to be the hash to content.
2016-05-11 19:13:37 -04:00
request . Header . Set ( "Content-Md5" , base64 . StdEncoding . EncodeToString ( md5Sum ) )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-07-02 04:59:28 -04:00
// exepcting a successful upload.
2016-05-11 19:13:37 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
objectName = "test-2-object"
2016-05-11 19:13:37 -04:00
buffer1 = bytes . NewReader ( data )
2016-06-29 05:30:36 -04:00
// HTTP request for the object to be uploaded.
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
2016-05-11 19:13:37 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// set Content-Md5 to invalid value.
2016-05-11 19:13:37 -04:00
request . Header . Set ( "Content-Md5" , "WvLTlMrX9NpYDQlEIFlnDw==" )
client = http . Client { }
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Since Content-Md5 header was wrong, expecting to fail with "SignatureDoesNotMatch" error.
2016-06-21 15:10:18 -04:00
verifyError ( c , response , "SignatureDoesNotMatch" , "The request signature we calculated does not match the signature you provided. Check your key and signing method." , http . StatusForbidden )
2016-05-11 19:13:37 -04:00
}
2016-06-29 05:30:36 -04:00
// TestObjectMultipart - Initiates a NewMultipart upload, uploads 2 parts,
// completes the multipart upload and validates the status of the operation.
func ( s * TestSuiteFS ) TestObjectMultipart ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client := http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to create bucket.
2015-07-12 15:40:38 -04:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , 200 )
2016-06-29 05:30:36 -04:00
objectName := "test-multipart-object"
// construct HTTP request to initiate a NewMultipart upload.
request , err = newTestRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request initiating the new multipart upload.
2015-07-12 15:40:38 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// expecting the response status code to be http.StatusOK(200 OK).
2015-07-12 15:40:38 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// parse the response body and obtain the new upload ID.
2015-07-12 15:40:38 -04:00
decoder := xml . NewDecoder ( response . Body )
2015-09-19 03:52:01 -04:00
newResponse := & InitiateMultipartUploadResponse { }
2015-07-12 15:40:38 -04:00
err = decoder . Decode ( newResponse )
c . Assert ( err , IsNil )
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
2016-06-29 05:30:36 -04:00
// uploadID to be used for rest of the multipart operations on the object.
2015-07-12 15:40:38 -04:00
uploadID := newResponse . UploadID
2016-06-29 05:30:36 -04:00
// content for the part to be uploaded.
2016-05-09 02:49:49 -04:00
// Create a byte array of 5MB.
data := bytes . Repeat ( [ ] byte ( "0123456789abcdef" ) , 5 * 1024 * 1024 / 16 )
2016-06-29 05:30:36 -04:00
// calculate md5Sum of the data.
2016-02-05 23:05:56 -05:00
hasher := md5 . New ( )
2016-05-09 02:49:49 -04:00
hasher . Write ( data )
2016-02-05 23:05:56 -05:00
md5Sum := hasher . Sum ( nil )
2016-05-09 02:49:49 -04:00
buffer1 := bytes . NewReader ( data )
2016-06-29 05:30:36 -04:00
// HTTP request for the part to be uploaded.
request , err = newTestRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "1" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey )
// set the Content-Md5 header to the base64 encoding the md5Sum of the content.
2016-03-05 19:43:48 -05:00
request . Header . Set ( "Content-Md5" , base64 . StdEncoding . EncodeToString ( md5Sum ) )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the first part.
2015-07-12 15:40:38 -04:00
response1 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response1 . StatusCode , Equals , http . StatusOK )
2016-06-29 05:30:36 -04:00
// content for the second part to be uploaded.
// Create a byte array of 1 byte.
2016-05-09 02:49:49 -04:00
data = [ ] byte ( "0" )
hasher = md5 . New ( )
hasher . Write ( data )
2016-06-29 05:30:36 -04:00
// calculate md5Sum of the data.
2016-05-09 02:49:49 -04:00
md5Sum = hasher . Sum ( nil )
buffer2 := bytes . NewReader ( data )
2016-06-29 05:30:36 -04:00
// HTTP request for the second part to be uploaded.
request , err = newTestRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "2" ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey )
// set the Content-Md5 header to the base64 encoding the md5Sum of the content.
2016-03-05 19:43:48 -05:00
request . Header . Set ( "Content-Md5" , base64 . StdEncoding . EncodeToString ( md5Sum ) )
2015-07-12 15:40:38 -04:00
c . Assert ( err , IsNil )
client = http . Client { }
2016-06-29 05:30:36 -04:00
// execute the HTTP request to upload the second part.
2015-07-12 15:40:38 -04:00
response2 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response2 . StatusCode , Equals , http . StatusOK )
2016-02-05 23:05:56 -05:00
// Complete multipart upload
objectAPI: Fix object API interface, remove unnecessary structs.
ObjectAPI changes.
```
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsInfo, *probe.Error)
ListMultipartUploads(bucket, objectPrefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (ListMultipartsInfo, *probe.Error)
ListObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (ListPartsInfo, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []completePart) (ObjectInfo, *probe.Error)
```
2016-04-03 04:34:20 -04:00
completeUploads := & completeMultipartUpload {
Parts : [ ] completePart {
2015-07-12 15:40:38 -04:00
{
PartNumber : 1 ,
ETag : response1 . Header . Get ( "ETag" ) ,
} ,
{
PartNumber : 2 ,
ETag : response2 . Header . Get ( "ETag" ) ,
} ,
} ,
}
completeBytes , err := xml . Marshal ( completeUploads )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Indicating that all parts are uploaded and initiating completeMultipartUpload.
request , err = newTestRequest ( "POST" , getCompleteMultipartUploadURL ( s . endPoint , bucketName , objectName , uploadID ) ,
int64 ( len ( completeBytes ) ) , bytes . NewReader ( completeBytes ) , s . accessKey , s . secretKey )
2016-06-20 09:18:47 -04:00
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// Execute the complete multipart request.
2016-06-20 09:18:47 -04:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 05:30:36 -04:00
// verify whether complete multipart was successfull.
2016-06-20 09:18:47 -04:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
}