2015-07-12 21:40:38 +02: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-13 00:27:10 +01:00
* Minio Cloud Storage , ( C ) 2015 , 2016 Minio , Inc .
2015-07-12 21:40:38 +02:00
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* /
2016-08-19 01:23:42 +02:00
package cmd
2015-07-12 21:40:38 +02:00
import (
"bytes"
2016-10-26 11:30:31 +02:00
"crypto/tls"
2016-11-11 16:18:44 +01:00
"crypto/x509"
2016-06-21 21:10:18 +02:00
"encoding/xml"
2016-06-13 11:53:09 +02:00
"fmt"
2016-06-29 11:30:36 +02:00
"io"
2015-07-12 21:40:38 +02:00
"io/ioutil"
2016-06-25 12:03:27 +02:00
"math/rand"
2016-06-21 21:10:18 +02:00
"net/http"
2016-07-06 23:00:29 +02:00
"net/url"
2016-08-12 20:28:27 +02:00
"strings"
2016-03-08 04:07:43 +01:00
"sync"
2015-09-20 21:44:44 +02:00
"time"
2015-07-12 21:40:38 +02:00
2016-11-23 03:18:22 +01:00
humanize "github.com/dustin/go-humanize"
2015-08-23 03:34:00 +02:00
. "gopkg.in/check.v1"
2015-07-12 21:40:38 +02:00
)
2016-07-04 22:18:41 +02:00
// API suite container common to both FS and XL.
type TestSuiteCommon struct {
serverType string
2016-06-21 21:10:18 +02:00
testServer TestServer
2016-06-29 11:30:36 +02:00
endPoint string
accessKey string
secretKey string
2016-10-25 22:34:14 +02:00
signer signerType
2016-10-26 11:30:31 +02:00
secure bool
transport * http . Transport
2015-07-12 21:40:38 +02:00
}
2016-07-04 22:18:41 +02:00
// Init and run test on FS backend.
2016-10-25 22:34:14 +02:00
var _ = Suite ( & TestSuiteCommon { serverType : "FS" , signer : signerV4 } )
// Init and run test on FS backend with AWS signature v2.
var _ = Suite ( & TestSuiteCommon { serverType : "FS" , signer : signerV2 } )
2016-07-04 22:18:41 +02:00
2016-10-26 11:30:31 +02:00
// Init and run test on FS backend, with tls enabled.
var _ = Suite ( & TestSuiteCommon { serverType : "FS" , signer : signerV4 , secure : true } )
2016-07-04 22:18:41 +02:00
// Init and run test on XL backend.
2016-10-25 22:34:14 +02:00
var _ = Suite ( & TestSuiteCommon { serverType : "XL" , signer : signerV4 } )
2015-07-12 21:40:38 +02:00
2016-06-21 21:10:18 +02:00
// Setting up the test suite.
// Starting the Test server with temporary FS backend.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) SetUpSuite ( c * C ) {
2016-10-26 11:30:31 +02:00
if s . secure {
2016-11-11 16:18:44 +01:00
cert , key , err := generateTLSCertKey ( "127.0.0.1" )
c . Assert ( err , IsNil )
s . testServer = StartTestTLSServer ( c , s . serverType , cert , key )
rootCAs := x509 . NewCertPool ( )
rootCAs . AppendCertsFromPEM ( cert )
tlsConfig := & tls . Config {
RootCAs : rootCAs ,
}
tlsConfig . BuildNameToCertificate ( )
2016-10-26 11:30:31 +02:00
s . transport = & http . Transport {
2016-11-11 16:18:44 +01:00
TLSClientConfig : tlsConfig ,
2016-10-26 11:30:31 +02:00
}
} else {
s . testServer = StartTestServer ( c , s . serverType )
s . transport = & http . Transport { }
}
2016-06-29 11:30:36 +02:00
s . endPoint = s . testServer . Server . URL
s . accessKey = s . testServer . AccessKey
s . secretKey = s . testServer . SecretKey
2015-07-12 21:40:38 +02:00
}
2016-06-21 21:10:18 +02:00
// Called implicitly by "gopkg.in/check.v1" after all tests are run.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TearDownSuite ( c * C ) {
2016-06-21 21:10:18 +02:00
s . testServer . Stop ( )
2016-06-20 15:18:47 +02:00
}
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestAuth ( c * C ) {
2017-03-16 08:16:06 +01:00
cred := mustGetNewCredential ( )
2015-10-16 20:26:01 +02:00
2016-12-26 19:21:23 +01:00
c . Assert ( len ( cred . AccessKey ) , Equals , accessKeyMaxLen )
c . Assert ( len ( cred . SecretKey ) , Equals , secretKeyMaxLen )
2015-10-16 20:26:01 +02:00
}
2017-01-09 23:22:10 +01:00
func ( s * TestSuiteCommon ) TestBucketSQSNotificationWebHook ( c * C ) {
// Sample bucket notification.
bucketNotificationBuf := ` <NotificationConfiguration><QueueConfiguration><Event>s3:ObjectCreated:Put</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>images/</Value></FilterRule></S3Key></Filter><Id>1</Id><Queue>arn:minio:sqs:us-east-1:444455556666:webhook</Queue></QueueConfiguration></NotificationConfiguration> `
// generate a random bucket Name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
c . Assert ( err , IsNil )
client := http . Client { Transport : s . transport }
// execute the request.
response , err := client . Do ( request )
c . Assert ( err , IsNil )
// assert the http response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
request , err = newTestSignedRequest ( "PUT" , getPutNotificationURL ( s . endPoint , bucketName ) ,
int64 ( len ( bucketNotificationBuf ) ) , bytes . NewReader ( [ ] byte ( bucketNotificationBuf ) ) , s . accessKey , s . secretKey , s . signer )
c . Assert ( err , IsNil )
client = http . Client { Transport : s . transport }
// execute the HTTP request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
verifyError ( c , response , "InvalidArgument" , "A specified destination ARN does not exist or is not well-formed. Verify the destination ARN." , http . StatusBadRequest )
}
2017-01-21 01:33:01 +01:00
func ( s * TestSuiteCommon ) TestObjectDir ( c * C ) {
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
c . Assert ( err , IsNil )
client := http . Client { Transport : s . transport }
// execute the request.
response , err := client . Do ( request )
c . Assert ( err , IsNil )
// assert the http response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , "my-object-directory/" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
c . Assert ( err , IsNil )
client = http . Client { Transport : s . transport }
// execute the HTTP request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
// assert the http response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , "my-object-directory/" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
c . Assert ( err , IsNil )
helloReader := bytes . NewReader ( [ ] byte ( "Hello, World" ) )
request . ContentLength = helloReader . Size ( )
request . Body = ioutil . NopCloser ( helloReader )
client = http . Client { Transport : s . transport }
// execute the HTTP request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
verifyError ( c , response , "XMinioInvalidObjectName" , "Object name contains unsupported characters. Unsupported characters are `^*|\\\"" , http . StatusBadRequest )
}
2017-01-09 23:22:10 +01:00
func ( s * TestSuiteCommon ) TestBucketSQSNotificationAMQP ( c * C ) {
2016-09-17 12:19:39 +02:00
// Sample bucket notification.
bucketNotificationBuf := ` <NotificationConfiguration><QueueConfiguration><Event>s3:ObjectCreated:Put</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>images/</Value></FilterRule></S3Key></Filter><Id>1</Id><Queue>arn:minio:sqs:us-east-1:444455556666:amqp</Queue></QueueConfiguration></NotificationConfiguration> `
// generate a random bucket Name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-09-17 12:19:39 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-09-17 12:19:39 +02:00
// execute the request.
response , err := client . Do ( request )
c . Assert ( err , IsNil )
// assert the http response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutNotificationURL ( s . endPoint , bucketName ) ,
int64 ( len ( bucketNotificationBuf ) ) , bytes . NewReader ( [ ] byte ( bucketNotificationBuf ) ) , s . accessKey , s . secretKey , s . signer )
2016-09-17 12:19:39 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-09-17 12:19:39 +02:00
// execute the HTTP request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
verifyError ( c , response , "InvalidArgument" , "A specified destination ARN does not exist or is not well-formed. Verify the destination ARN." , http . StatusBadRequest )
}
2016-06-29 11:30:36 +02: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.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) 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 18:38:04 +01:00
// Sample bucket policy.
2016-08-20 12:16:38 +02:00
bucketPolicyBuf := ` { "Version":"2012-10-17","Statement":[ { "Action":["s3:GetBucketLocation","s3:ListBucket"],"Effect":"Allow","Principal": { "AWS":["*"]},"Resource":["arn:aws:s3:::%s"],"Sid":""}, { "Action":["s3:GetObject"],"Effect":"Allow","Principal": { "AWS":["*"]},"Resource":["arn:aws:s3:::%s/this*"],"Sid":""}]} `
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 18:38:04 +01:00
2016-06-29 11:30:36 +02: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.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
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 18:38:04 +01:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02: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 18:38:04 +01:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the http response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
/// Put a new bucket policy.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutPolicyURL ( s . endPoint , bucketName ) ,
int64 ( len ( bucketPolicyStr ) ) , bytes . NewReader ( [ ] byte ( bucketPolicyStr ) ) , s . accessKey , s . secretKey , s . signer )
2016-06-29 11:30:36 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// 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 18:38:04 +01:00
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
// Fetch the uploaded policy.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetPolicyURL ( s . endPoint , bucketName ) , 0 , nil ,
s . accessKey , s . secretKey , s . signer )
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 18:38:04 +01:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
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 18:38:04 +01:00
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 11:30:36 +02: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 18:38:04 +01:00
// Delete policy.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "DELETE" , getDeletePolicyURL ( s . endPoint , bucketName ) , 0 , nil ,
s . accessKey , s . secretKey , s . signer )
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 18:38:04 +01:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
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 18:38:04 +01:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2016-05-03 01:58:10 +02:00
// Verify if the policy was indeed deleted.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetPolicyURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-05-03 01:58:10 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-05-03 01:58:10 +02:00
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 18:38:04 +01:00
}
2016-06-29 11:30:36 +02:00
// TestDeleteBucket - validates DELETE bucket operation.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestDeleteBucket ( c * C ) {
2016-06-29 11:30:36 +02:00
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-16 23:08:33 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2015-07-16 23:08:33 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the response status code.
2015-10-16 20:26:01 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// construct request to delete the bucket.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "DELETE" , getDeleteBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-10-16 20:26:01 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2015-10-16 20:26:01 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Assert the response status code.
2015-10-17 05:02:37 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2015-07-16 23:08:33 +02:00
}
2016-06-29 11:30:36 +02:00
// TestDeleteBucketNotEmpty - Validates the operation during an attempt to delete a non-empty bucket.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestDeleteBucketNotEmpty ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-05-05 10:35:21 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the request.
2016-05-05 10:35:21 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the response status code.
2016-05-05 10:35:21 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// generate http request for an object upload.
// "test-object" is the object name.
objectName := "test-object"
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-05-05 10:35:21 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the request to complete object upload.
2016-05-05 10:35:21 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the status code of the response.
2016-05-05 10:35:21 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// constructing http request to delete the bucket.
// making an attempt to delete an non-empty bucket.
// expected to fail.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "DELETE" , getDeleteBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-05-05 10:35:21 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-05-05 10:35:21 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusConflict )
2016-06-29 11:30:36 +02:00
2016-05-05 10:35:21 +02:00
}
2016-10-22 07:56:27 +02:00
func ( s * TestSuiteCommon ) TestListenBucketNotificationHandler ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
req , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-10-22 07:56:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-10-22 07:56:27 +02:00
// execute the request.
response , err := client . Do ( req )
c . Assert ( err , IsNil )
// assert the http response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
invalidBucket := "Invalid\\Bucket"
tooByte := bytes . Repeat ( [ ] byte ( "a" ) , 1025 )
tooBigPrefix := string ( tooByte )
validEvents := [ ] string { "s3:ObjectCreated:*" , "s3:ObjectRemoved:*" }
invalidEvents := [ ] string { "invalidEvent" }
2016-10-25 22:34:14 +02:00
req , err = newTestSignedRequest ( "GET" ,
2016-10-22 07:56:27 +02:00
getListenBucketNotificationURL ( s . endPoint , invalidBucket , [ ] string { } , [ ] string { } , [ ] string { } ) ,
2016-10-25 22:34:14 +02:00
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-10-22 07:56:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-10-22 07:56:27 +02:00
// execute the request.
response , err = client . Do ( req )
c . Assert ( err , IsNil )
verifyError ( c , response , "InvalidBucketName" , "The specified bucket is not valid." , http . StatusBadRequest )
2016-10-25 22:34:14 +02:00
req , err = newTestSignedRequest ( "GET" ,
2016-10-22 07:56:27 +02:00
getListenBucketNotificationURL ( s . endPoint , bucketName , [ ] string { } , [ ] string { } , invalidEvents ) ,
2016-10-25 22:34:14 +02:00
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-10-22 07:56:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-10-22 07:56:27 +02:00
// execute the request.
response , err = client . Do ( req )
c . Assert ( err , IsNil )
verifyError ( c , response , "InvalidArgument" , "A specified event is not supported for notifications." , http . StatusBadRequest )
2016-10-25 22:34:14 +02:00
req , err = newTestSignedRequest ( "GET" ,
2016-10-22 07:56:27 +02:00
getListenBucketNotificationURL ( s . endPoint , bucketName , [ ] string { tooBigPrefix } , [ ] string { } , validEvents ) ,
2016-10-25 22:34:14 +02:00
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-10-22 07:56:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-10-22 07:56:27 +02:00
// execute the request.
response , err = client . Do ( req )
c . Assert ( err , IsNil )
verifyError ( c , response , "InvalidArgument" , "Size of filter rule value cannot exceed 1024 bytes in UTF-8 representation" , http . StatusBadRequest )
2016-10-25 22:34:14 +02:00
req , err = newTestSignedRequest ( "GET" ,
2016-10-22 07:56:27 +02:00
getListenBucketNotificationURL ( s . endPoint , bucketName , [ ] string { } , [ ] string { } , validEvents ) ,
2016-10-25 22:34:14 +02:00
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-10-22 07:56:27 +02:00
c . Assert ( err , IsNil )
req . Header . Set ( "x-amz-content-sha256" , "somethingElse" )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-10-22 07:56:27 +02:00
// execute the request.
response , err = client . Do ( req )
c . Assert ( err , IsNil )
2016-10-25 22:34:14 +02:00
if s . signer == signerV4 {
verifyError ( c , response , "XAmzContentSHA256Mismatch" , "The provided 'x-amz-content-sha256' header does not match what was computed." , http . StatusBadRequest )
}
2016-10-22 07:56:27 +02:00
// Change global value from 5 second to 100millisecond.
globalSNSConnAlive = 100 * time . Millisecond
2016-10-25 22:34:14 +02:00
req , err = newTestSignedRequest ( "GET" ,
2016-10-22 07:56:27 +02:00
getListenBucketNotificationURL ( s . endPoint , bucketName ,
2016-10-25 22:34:14 +02:00
[ ] string { } , [ ] string { } , validEvents ) , 0 , nil , s . accessKey , s . secretKey , s . signer )
2016-10-22 07:56:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-10-22 07:56:27 +02:00
// execute the request.
response , err = client . Do ( req )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
// FIXME: uncomment this in future when we have a code to read notifications from.
// go func() {
// buf := bytes.NewReader(tooByte)
2016-10-25 22:34:14 +02:00
// rreq, rerr := newTestSignedRequest("GET",
2016-10-22 07:56:27 +02:00
// getPutObjectURL(s.endPoint, bucketName, "myobject/1"),
2016-10-25 22:34:14 +02:00
// int64(buf.Len()), buf, s.accessKey, s.secretKey, s.signer)
2016-10-22 07:56:27 +02:00
// c.Assert(rerr, IsNil)
2016-10-26 11:30:31 +02:00
// client = http.Client{Transport: s.transport}
2016-10-22 07:56:27 +02:00
// // execute the request.
// resp, rerr := client.Do(rreq)
// c.Assert(rerr, IsNil)
// c.Assert(resp.StatusCode, Equals, http.StatusOK)
// }()
response . Body . Close ( ) // FIXME. Find a way to read from the returned body.
}
2016-09-14 04:00:01 +02:00
// Test deletes multple objects and verifies server resonse.
2016-09-02 10:59:08 +02:00
func ( s * TestSuiteCommon ) TestDeleteMultipleObjects ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-09-02 10:59:08 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-09-02 10:59:08 +02:00
// execute the request.
response , err := client . Do ( request )
c . Assert ( err , IsNil )
// assert the http response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
objectName := "prefix/myobject"
delObjReq := DeleteObjectsRequest {
Quiet : false ,
}
for i := 0 ; i < 10 ; i ++ {
// Obtain http request to upload object.
// object Name contains a prefix.
objName := fmt . Sprintf ( "%d/%s" , i , objectName )
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-09-02 10:59:08 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-09-02 10:59:08 +02:00
// execute the http request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
// assert the status of http response.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
// Append all objects.
delObjReq . Objects = append ( delObjReq . Objects , ObjectIdentifier {
ObjectName : objName ,
} )
}
// Marshal delete request.
deleteReqBytes , err := xml . Marshal ( delObjReq )
c . Assert ( err , IsNil )
2016-09-14 04:00:01 +02:00
// Delete list of objects.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "POST" , getMultiDeleteObjectURL ( s . endPoint , bucketName ) ,
int64 ( len ( deleteReqBytes ) ) , bytes . NewReader ( deleteReqBytes ) , s . accessKey , s . secretKey , s . signer )
2016-09-02 10:59:08 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-09-02 10:59:08 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var deleteResp = DeleteObjectsResponse { }
delRespBytes , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
err = xml . Unmarshal ( delRespBytes , & deleteResp )
c . Assert ( err , IsNil )
2016-09-14 04:00:01 +02:00
for i := 0 ; i < 10 ; i ++ {
2016-09-07 20:49:12 +02:00
// All the objects should be under deleted list (including non-existent object)
2016-09-02 10:59:08 +02:00
c . Assert ( deleteResp . DeletedObjects [ i ] , DeepEquals , delObjReq . Objects [ i ] )
}
c . Assert ( len ( deleteResp . Errors ) , Equals , 0 )
2016-09-14 04:00:01 +02:00
// Attempt second time results should be same, NoSuchKey for objects not found
// shouldn't be set.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "POST" , getMultiDeleteObjectURL ( s . endPoint , bucketName ) ,
int64 ( len ( deleteReqBytes ) ) , bytes . NewReader ( deleteReqBytes ) , s . accessKey , s . secretKey , s . signer )
2016-09-14 04:00:01 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-09-14 04:00:01 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
deleteResp = DeleteObjectsResponse { }
delRespBytes , err = ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
err = xml . Unmarshal ( delRespBytes , & deleteResp )
c . Assert ( err , IsNil )
for i := 0 ; i < 10 ; i ++ {
c . Assert ( deleteResp . DeletedObjects [ i ] , DeepEquals , delObjReq . Objects [ i ] )
}
c . Assert ( len ( deleteResp . Errors ) , Equals , 0 )
2016-09-02 10:59:08 +02:00
}
2016-05-15 00:47:19 +02:00
// Tests delete object responses and success.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestDeleteObject ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-16 23:08:33 +02:00
c . Assert ( err , IsNil )
2015-10-16 20:26:01 +02:00
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the request.
2015-07-16 23:08:33 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the http response status code.
2015-10-16 20:26:01 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
objectName := "prefix/myobject"
// obtain http request to upload object.
// object Name contains a prefix.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-10-16 20:26:01 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the http request.
2015-10-16 20:26:01 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the status of http response.
2015-10-16 20:26:01 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// object name was "prefix/myobject", an attempt to delelte "prefix"
2016-06-17 07:18:43 +02:00
// Should not delete "prefix/myobject"
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "DELETE" , getDeleteObjectURL ( s . endPoint , bucketName , "prefix" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-17 07:18:43 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-17 07:18:43 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2016-06-29 11:30:36 +02:00
// create http request to HEAD on the object.
// this helps to validate the existence of the bucket.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-10-16 20:26:01 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2015-10-16 20:26:01 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Assert the HTTP response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
// create HTTP request to delete the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "DELETE" , getDeleteObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-29 11:30:36 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the http request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
// assert the http response status code.
2015-10-17 05:02:37 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2016-05-15 00:47:19 +02:00
2016-06-29 11:30:36 +02:00
// Delete of non-existent data should return success.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "DELETE" , getDeleteObjectURL ( s . endPoint , bucketName , "prefix/myobject1" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-05-15 00:47:19 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the http request.
2016-05-15 00:47:19 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the http response status.
2016-05-15 00:47:19 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusNoContent )
2015-07-16 23:08:33 +02:00
}
2016-06-29 11:30:36 +02:00
// TestNonExistentBucket - Asserts response for HEAD on non-existent bucket.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestNonExistentBucket ( c * C ) {
2016-06-29 11:30:36 +02:00
// 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.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "HEAD" , getHEADBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the http request.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Assert the response.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusNotFound )
}
2016-06-29 11:30:36 +02:00
// TestEmptyObject - Asserts the response for operation on a 0 byte object.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestEmptyObject ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the http request.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the http response status code.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
objectName := "test-object"
// construct http request for uploading the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the upload request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the http response.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// make HTTP request to fetch the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the http request to fetch object.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the http response status code.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 11:30:36 +02:00
// extract the body of the response.
2015-07-12 21:40:38 +02:00
responseBody , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the http response body content.
2015-07-12 21:40:38 +02:00
c . Assert ( true , Equals , bytes . Equal ( responseBody , buffer . Bytes ( ) ) )
}
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestBucket ( c * C ) {
2016-07-05 10:06:30 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "HEAD" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
}
2016-08-11 05:10:48 +02:00
// Tests get anonymous object.
func ( s * TestSuiteCommon ) TestObjectGetAnonymous ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
buffer := bytes . NewReader ( [ ] byte ( "hello world" ) )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-08-11 05:10:48 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-08-11 05:10:48 +02:00
// execute the make bucket http request.
response , err := client . Do ( request )
c . Assert ( err , IsNil )
// assert the response http status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
objectName := "testObject"
// create HTTP request to upload the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer . Len ( ) ) , buffer , s . accessKey , s . secretKey , s . signer )
2016-08-11 05:10:48 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-08-11 05:10:48 +02:00
// execute the HTTP request to upload the object.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
// assert the HTTP response status code.
c . Assert ( response . StatusCode , Equals , http . StatusOK )
// initiate anonymous HTTP request to fetch the object which does not exist. We need to return AccessDenied.
2016-10-26 11:30:31 +02:00
response , err = client . Get ( getGetObjectURL ( s . endPoint , bucketName , objectName + ".1" ) )
2016-08-11 05:10:48 +02:00
c . Assert ( err , IsNil )
// assert the http response status code.
verifyError ( c , response , "AccessDenied" , "Access Denied." , http . StatusForbidden )
// initiate anonymous HTTP request to fetch the object which does exist. We need to return AccessDenied.
2016-10-26 11:30:31 +02:00
response , err = client . Get ( getGetObjectURL ( s . endPoint , bucketName , objectName ) )
2016-08-11 05:10:48 +02:00
c . Assert ( err , IsNil )
// assert the http response status code.
verifyError ( c , response , "AccessDenied" , "Access Denied." , http . StatusForbidden )
}
2016-06-29 11:30:36 +02:00
// TestGetObject - Tests fetching of a small object after its insertion into the bucket.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestObjectGet ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
2015-07-12 21:40:38 +02:00
buffer := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the make bucket http request.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the response http status code.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
objectName := "testObject"
// create HTTP request to upload the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer . Len ( ) ) , buffer , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the object.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the HTTP response status code.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-08-17 04:24:23 +02:00
// concurrently reading the object, safety check for races.
var wg sync . WaitGroup
2016-09-16 11:45:42 +02:00
for i := 0 ; i < testConcurrencyLevel ; i ++ {
2016-08-17 04:24:23 +02:00
wg . Add ( 1 )
go func ( ) {
defer wg . Done ( )
// HTTP request to create the bucket.
// create HTTP request to fetch the object.
2016-10-25 22:34:14 +02:00
getRequest , err := newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-08-17 04:24:23 +02:00
c . Assert ( err , IsNil )
2015-07-12 21:40:38 +02:00
2016-10-26 11:30:31 +02:00
reqClient := http . Client { Transport : s . transport }
2016-08-17 04:24:23 +02:00
// execute the http request to fetch the object.
getResponse , err := reqClient . Do ( getRequest )
c . Assert ( err , IsNil )
defer getResponse . Body . Close ( )
// assert the http response status code.
c . Assert ( getResponse . StatusCode , Equals , http . StatusOK )
2015-07-12 21:40:38 +02:00
2016-08-17 04:24:23 +02:00
// extract response body content.
responseBody , err := ioutil . ReadAll ( getResponse . Body )
c . Assert ( err , IsNil )
// assert the HTTP response body content with the expected content.
c . Assert ( responseBody , DeepEquals , [ ] byte ( "hello world" ) )
} ( )
2015-07-12 21:40:38 +02:00
2016-08-17 04:24:23 +02:00
}
wg . Wait ( )
2015-07-12 21:40:38 +02:00
}
2016-06-29 11:30:36 +02:00
// TestMultipleObjects - Validates upload and fetching of multiple object into the bucket.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestMultipleObjects ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create the bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// constructing HTTP request to fetch a non-existent object.
// expected to fail, error response asserted for expected error values later.
objectName := "testObject"
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Asserting the error response with the expected values.
2015-07-12 21:40:38 +02:00
verifyError ( c , response , "NoSuchKey" , "The specified key does not exist." , http . StatusNotFound )
2016-06-29 11:30:36 +02:00
objectName = "testObject1"
// content for the object to be uploaded.
2015-07-12 21:40:38 +02:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello one" ) )
2016-06-29 11:30:36 +02:00
// create HTTP request for the object upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request for object upload.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the returned values.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// create HTTP request to fetch the object which was uploaded above.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert whether 200 OK response status is obtained.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// extract the response body.
2015-07-12 21:40:38 +02:00
responseBody , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the content body for the expected object data.
2015-07-12 21:40:38 +02:00
c . Assert ( true , Equals , bytes . Equal ( responseBody , [ ] byte ( "hello one" ) ) )
2016-06-29 11:30:36 +02:00
// data for new object to be uploaded.
2015-07-12 21:40:38 +02:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello two" ) )
2016-06-29 11:30:36 +02:00
objectName = "testObject2"
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request for object upload.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the response status code for expected value 200 OK.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// fetch the object which was uploaded above.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to fetch the object.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// assert the response status code for expected value 200 OK.
2015-07-12 21:40:38 +02: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 11:30:36 +02:00
// data for new object to be uploaded.
2015-07-12 21:40:38 +02:00
buffer3 := bytes . NewReader ( [ ] byte ( "hello three" ) )
2016-06-29 11:30:36 +02:00
objectName = "testObject3"
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer3 . Len ( ) ) , buffer3 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// verify the response code with the expected value of 200 OK.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// fetch the object which was uploaded above.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// verify object.
2015-07-12 21:40:38 +02:00
responseBody , err = ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
c . Assert ( true , Equals , bytes . Equal ( responseBody , [ ] byte ( "hello three" ) ) )
}
2016-07-05 10:06:30 +02:00
// TestNotImplemented - validates if object policy is implemented, should return 'NotImplemented'.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestNotImplemented ( c * C ) {
2016-07-05 10:06:30 +02:00
// Generate a random bucket name.
2016-06-29 11:30:36 +02:00
bucketName := getRandomBucketName ( )
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "GET" , s . endPoint + "/" + bucketName + "/object?policy" ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusNotImplemented )
}
2016-06-29 11:30:36 +02:00
// TestHeader - Validates the error response for an attempt to fetch non-existent object.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestHeader ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// obtain HTTP request to fetch an object from non-existent bucket/object.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , "testObject" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// asserting for the expected error response.
2016-07-05 10:06:30 +02:00
verifyError ( c , response , "NoSuchBucket" , "The specified bucket does not exist" , http . StatusNotFound )
2015-07-12 21:40:38 +02:00
}
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestPutBucket ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
2016-03-08 04:07:43 +01: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
2016-09-16 11:45:42 +02:00
for i := 0 ; i < testConcurrencyLevel ; i ++ {
2016-03-08 04:07:43 +01:00
wg . Add ( 1 )
go func ( ) {
defer wg . Done ( )
2016-06-29 11:30:36 +02:00
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-03-08 04:07:43 +01:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-03-08 04:07:43 +01:00
response , err := client . Do ( request )
2016-08-12 09:26:30 +02:00
if err != nil {
c . Fatalf ( "Put bucket Failed: <ERROR> %s" , err )
}
2016-03-08 04:07:43 +01:00
defer response . Body . Close ( )
} ( )
}
wg . Wait ( )
2016-06-29 11:30:36 +02:00
bucketName = getRandomBucketName ( )
2016-03-08 04:07:43 +01:00
//Block 2: testing for correctness of the functionality
2016-06-29 11:30:36 +02:00
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-03-08 04:07:43 +01:00
response . Body . Close ( )
2015-07-12 21:40:38 +02:00
}
2016-06-29 11:30:36 +02:00
// TestCopyObject - Validates copy object.
// The following is the test flow.
// 1. Create bucket.
// 2. Insert Object.
2016-10-04 09:09:21 +02:00
// 3. Use "X-Amz-Copy-Source" header to copy the previously created object.
2016-06-29 11:30:36 +02:00
// 4. Validate the content of copied object.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestCopyObject ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-02-27 12:04:52 +01:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2016-02-27 12:04:52 +01:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-10-04 09:09:21 +02:00
// content for the object to be created.
2016-02-27 12:04:52 +01:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
objectName := "testObject"
// create HTTP request for object upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2016-06-29 11:30:36 +02:00
request . Header . Set ( "Content-Type" , "application/json" )
2016-10-25 22:34:14 +02:00
if s . signer == signerV2 {
c . Assert ( err , IsNil )
err = signRequestV2 ( request , s . accessKey , s . secretKey )
}
2016-02-27 12:04:52 +01:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request for object upload.
2016-02-27 12:04:52 +01:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
objectName2 := "testObject2"
2016-08-17 04:24:23 +02:00
// Unlike the actual PUT object request, the request to Copy Object doesn't contain request body,
// empty body with the "X-Amz-Copy-Source" header pointing to the object to copies it in the backend.
2016-07-10 20:10:59 +02:00
request , err = newTestRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName2 ) , 0 , nil )
c . Assert ( err , IsNil )
2016-07-05 10:06:30 +02:00
// setting the "X-Amz-Copy-Source" to allow copying the content of previously uploaded object.
2016-07-06 23:00:29 +02:00
request . Header . Set ( "X-Amz-Copy-Source" , url . QueryEscape ( "/" + bucketName + "/" + objectName ) )
2016-10-25 22:34:14 +02:00
if s . signer == signerV4 {
err = signRequestV4 ( request , s . accessKey , s . secretKey )
} else {
err = signRequestV2 ( request , s . accessKey , s . secretKey )
}
2016-02-27 12:04:52 +01:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
// the content is expected to have the content of previous disk.
2016-02-27 12:04:52 +01:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// creating HTTP request to fetch the previously uploaded object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName2 ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-02-27 12:04:52 +01:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// executing the HTTP request.
2016-02-27 12:04:52 +01:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// validating the response status code.
2016-02-27 12:04:52 +01:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// reading the response body.
// response body is expected to have the copied content of the first uploaded object.
2016-02-27 12:04:52 +01:00
object , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
c . Assert ( string ( object ) , Equals , "hello world" )
}
2016-06-29 11:30:36 +02:00
// TestPutObject - Tests successful put object request.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestPutObject ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// content for new object upload.
2015-07-12 21:40:38 +02:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
objectName := "testObject"
// creating HTTP request for object upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2016-06-29 11:30:36 +02:00
c . Assert ( err , IsNil )
// execute the HTTP request for object upload.
response , err = client . Do ( request )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2015-07-12 21:40:38 +02:00
2016-06-29 11:30:36 +02:00
// fetch the object back and verify its contents.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-29 11:30:36 +02:00
c . Assert ( err , IsNil )
// execute the HTTP request to fetch the object.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02: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" ) ) )
2016-07-24 07:51:12 +02:00
2015-07-12 21:40:38 +02:00
}
2016-06-29 11:30:36 +02:00
// TestListBuckets - Make request for listing of all buckets.
// XML response is parsed.
// Its success verifies the format of the response.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestListBuckets ( c * C ) {
2016-06-29 11:30:36 +02:00
// create HTTP request for listing buckets.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "GET" , getListBucketURL ( s . endPoint ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to list buckets.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2015-09-19 09:52:01 +02:00
var results ListBucketsResponse
2016-06-29 11:30:36 +02:00
// parse the list bucket response.
2015-07-12 21:40:38 +02:00
decoder := xml . NewDecoder ( response . Body )
err = decoder . Decode ( & results )
2016-07-27 20:57:08 +02:00
// validating that the xml-decoding/parsing was successful.
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
}
2016-07-05 10:04:50 +02:00
// This tests validate if PUT handler can successfully detect signature mismatch.
func ( s * TestSuiteCommon ) TestValidateSignature ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-07-05 10:04:50 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-07-05 10:04:50 +02:00
// Execute the HTTP request to create bucket.
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
objName := "test-object"
// Body is on purpose set to nil so that we get payload generated for empty bytes.
// Create new HTTP request with incorrect secretKey to generate an incorrect signature.
secretKey := s . secretKey + "a"
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objName ) , 0 , nil , s . accessKey , secretKey , s . signer )
2016-07-05 10:04:50 +02:00
c . Assert ( err , IsNil )
response , err = client . Do ( request )
c . Assert ( err , IsNil )
verifyError ( c , response , "SignatureDoesNotMatch" , "The request signature we calculated does not match the signature you provided. Check your key and signing method." , http . StatusForbidden )
}
// This tests validate if PUT handler can successfully detect SHA256 mismatch.
func ( s * TestSuiteCommon ) TestSHA256Mismatch ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-07-05 10:04:50 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-07-05 10:04:50 +02:00
// Execute the HTTP request to create bucket.
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
objName := "test-object"
// Body is on purpose set to nil so that we get payload generated for empty bytes.
// Create new HTTP request with incorrect secretKey to generate an incorrect signature.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objName ) , 0 , nil , s . accessKey , s . secretKey , s . signer )
if s . signer == signerV4 {
c . Assert ( request . Header . Get ( "x-amz-content-sha256" ) , Equals , "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" )
}
2016-07-05 10:04:50 +02:00
// Set the body to generate signature mismatch.
2017-01-21 01:33:01 +01:00
helloReader := bytes . NewReader ( [ ] byte ( "Hello, World" ) )
request . ContentLength = helloReader . Size ( )
request . Body = ioutil . NopCloser ( helloReader )
2016-07-05 10:04:50 +02:00
c . Assert ( err , IsNil )
// execute the HTTP request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-10-25 22:34:14 +02:00
if s . signer == signerV4 {
verifyError ( c , response , "XAmzContentSHA256Mismatch" , "The provided 'x-amz-content-sha256' header does not match what was computed." , http . StatusBadRequest )
}
2016-07-05 10:04:50 +02:00
}
2017-01-17 02:05:00 +01:00
// TestPutObjectLongName - Validates the error response
// on an attempt to upload an object with long name.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestPutObjectLongName ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-13 11:53:09 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-07-05 10:04:50 +02:00
// Execute the HTTP request to create bucket.
2016-06-13 11:53:09 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-07-05 10:04:50 +02:00
// Content for the object to be uploaded.
2016-06-13 11:53:09 +02:00
buffer := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// make long object name.
2016-06-13 11:53:09 +02:00
longObjName := fmt . Sprintf ( "%0255d/%0255d/%0255d" , 1 , 1 , 1 )
2016-06-29 11:30:36 +02:00
// create new HTTP request to insert the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , longObjName ) ,
int64 ( buffer . Len ( ) ) , buffer , s . accessKey , s . secretKey , s . signer )
2016-06-13 11:53:09 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2016-06-13 11:53:09 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// make long object name.
2016-06-13 11:53:09 +02:00
longObjName = fmt . Sprintf ( "%0256d" , 1 )
2016-07-05 10:04:50 +02:00
buffer = bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , longObjName ) ,
int64 ( buffer . Len ( ) ) , buffer , s . accessKey , s . secretKey , s . signer )
2016-06-13 11:53:09 +02:00
c . Assert ( err , IsNil )
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-07-10 02:11:08 +02:00
verifyError ( c , response , "XMinioInvalidObjectName" , "Object name contains unsupported characters. Unsupported characters are `^*|\\\"" , http . StatusBadRequest )
2016-06-13 11:53:09 +02:00
}
2016-06-29 11:30:36 +02:00
// TestNotBeAbleToCreateObjectInNonexistentBucket - Validates the error response
// on an attempt to upload an object into a non-existent bucket.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestNotBeAbleToCreateObjectInNonexistentBucket ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// content of the object to be uploaded.
2015-07-12 21:40:38 +02:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// preparing for upload by generating the upload URL.
objectName := "test-object"
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// Execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Assert the response error message.
2016-07-05 10:06:30 +02:00
verifyError ( c , response , "NoSuchBucket" , "The specified bucket does not exist" , http . StatusNotFound )
2015-07-12 21:40:38 +02:00
}
2016-06-29 11:30:36 +02: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).
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestHeadOnObjectLastModified ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// preparing for object upload.
objectName := "test-object"
// content for the object to be uploaded.
2015-07-12 21:40:38 +02:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// obtaining URL for uploading the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// executing the HTTP request to download the object.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// make HTTP request to obtain object info.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// verify the status of the HTTP response.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-02-29 03:10:37 +01:00
2016-06-29 11:30:36 +02:00
// retrive the info of last modification time of the object from the response header.
2016-02-29 03:10:37 +01:00
lastModified := response . Header . Get ( "Last-Modified" )
2016-06-29 11:30:36 +02:00
// Parse it into time.Time structure.
2016-02-29 03:10:37 +01:00
t , err := time . Parse ( http . TimeFormat , lastModified )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// make HTTP request to obtain object info.
2016-07-05 10:06:30 +02:00
// But this time set the "If-Modified-Since" header to be 10 minute more than the actual
2016-06-29 11:30:36 +02:00
// last modified time of the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-02-29 03:10:37 +01:00
c . Assert ( err , IsNil )
2016-07-05 10:06:30 +02:00
request . Header . Set ( "If-Modified-Since" , t . Add ( 10 * time . Minute ) . UTC ( ) . Format ( http . TimeFormat ) )
2016-02-29 03:10:37 +01:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-07-05 10:06:30 +02: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-29 03:10:37 +01:00
c . Assert ( response . StatusCode , Equals , http . StatusNotModified )
2016-06-29 11:30:36 +02: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.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-02-29 03:10:37 +01:00
c . Assert ( err , IsNil )
2016-07-05 10:06:30 +02:00
request . Header . Set ( "If-Unmodified-Since" , t . Add ( - 10 * time . Minute ) . UTC ( ) . Format ( http . TimeFormat ) )
2016-02-29 03:10:37 +01:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusPreconditionFailed )
2015-07-12 21:40:38 +02:00
}
2016-06-29 11:30:36 +02:00
// TestHeadOnBucket - Validates response for HEAD on the bucket.
// HEAD request on the bucket validates the existence of the bucket.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestHeadOnBucket ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getHEADBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// make HEAD request on the bucket.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "HEAD" , getHEADBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Asserting the response status for expected value of http.StatusOK.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
}
2016-06-29 11:30:36 +02: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.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestContentTypePersists ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-07-05 10:06:30 +02:00
// Uploading a new object with Content-Type "image/png".
2016-06-29 11:30:36 +02:00
// content for the object to be uploaded.
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
objectName := "test-object.png"
// constructing HTTP request for object upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-07-05 10:06:30 +02:00
request . Header . Set ( "Content-Type" , "image/png" )
2016-10-25 22:34:14 +02:00
if s . signer == signerV2 {
err = signRequestV2 ( request , s . accessKey , s . secretKey )
c . Assert ( err , IsNil )
}
2015-07-12 21:40:38 +02:00
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request for object upload.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// Fetching the object info using HEAD request for the object which was uploaded above.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Verify if the Content-Type header is set during the object persists.
2016-06-17 06:42:02 +02:00
c . Assert ( response . Header . Get ( "Content-Type" ) , Equals , "image/png" )
2015-07-12 21:40:38 +02:00
2016-06-29 11:30:36 +02:00
// Fetching the object itself and then verify the Content-Type header.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// Execute the HTTP to fetch the object.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// Verify if the Content-Type header is set during the object persists.
2016-06-17 06:42:02 +02:00
c . Assert ( response . Header . Get ( "Content-Type" ) , Equals , "image/png" )
2015-07-12 21:40:38 +02:00
2016-06-29 11:30:36 +02:00
// Uploading a new object with Content-Type "application/json".
objectName = "test-object.json"
2015-07-12 21:40:38 +02:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-07-05 10:06:30 +02:00
// setting the request header to be application/json.
request . Header . Set ( "Content-Type" , "application/json" )
2016-10-25 22:34:14 +02:00
if s . signer == signerV2 {
err = signRequestV2 ( request , s . accessKey , s . secretKey )
c . Assert ( err , IsNil )
}
2015-07-12 21:40:38 +02:00
2016-06-29 11:30:36 +02:00
// Execute the HTTP request to upload the object.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// Obtain the info of the object which was uploaded above using HEAD request.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "HEAD" , getHeadObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Assert if the content-type header set during the object upload persists.
2016-06-17 06:42:02 +02:00
c . Assert ( response . Header . Get ( "Content-Type" ) , Equals , "application/json" )
2015-07-12 21:40:38 +02:00
2016-06-29 11:30:36 +02:00
// Fetch the object and assert whether the Content-Type header persists.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Assert if the content-type header set during the object upload persists.
2016-06-17 06:42:02 +02:00
c . Assert ( response . Header . Get ( "Content-Type" ) , Equals , "application/json" )
2015-07-12 21:40:38 +02:00
}
2016-06-29 11:30:36 +02: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.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestPartialContent ( c * C ) {
2016-07-05 10:06:30 +02:00
bucketName := getRandomBucketName ( )
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
buffer1 := bytes . NewReader ( [ ] byte ( "Hello World" ) )
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , "bar" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
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 10:34:20 +02:00
// Prepare request
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , "bar" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
request . Header . Add ( "Range" , "bytes=6-7" )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
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-08-12 20:28:27 +02:00
// TestListObjectsHandler - Setting valid parameters to List Objects
// and then asserting the response with the expected one.
func ( s * TestSuiteCommon ) TestListObjectsHandler ( c * C ) {
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-08-12 20:28:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-08-12 20:28:27 +02:00
// execute the HTTP request to create bucket.
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
buffer1 := bytes . NewReader ( [ ] byte ( "Hello World" ) )
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , "bar" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2016-08-12 20:28:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-08-12 20:28:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
// create listObjectsV1 request with valid parameters
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getListObjectsV1URL ( s . endPoint , bucketName , "1000" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-08-12 20:28:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-08-12 20:28:27 +02:00
// execute the HTTP request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
getContent , err := ioutil . ReadAll ( response . Body )
2016-09-02 08:10:50 +02:00
c . Assert ( err , IsNil )
2016-08-12 20:28:27 +02:00
c . Assert ( strings . Contains ( string ( getContent ) , "<Key>bar</Key>" ) , Equals , true )
// create listObjectsV2 request with valid parameters
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getListObjectsV2URL ( s . endPoint , bucketName , "1000" , "" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-08-12 20:28:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-08-12 20:28:27 +02:00
// execute the HTTP request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
getContent , err = ioutil . ReadAll ( response . Body )
2016-09-02 08:10:50 +02:00
c . Assert ( err , IsNil )
2016-08-12 20:28:27 +02:00
c . Assert ( strings . Contains ( string ( getContent ) , "<Key>bar</Key>" ) , Equals , true )
2016-09-10 19:44:38 +02:00
c . Assert ( strings . Contains ( string ( getContent ) , "<Owner><ID></ID><DisplayName></DisplayName></Owner>" ) , Equals , true )
// create listObjectsV2 request with valid parameters and fetch-owner activated
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getListObjectsV2URL ( s . endPoint , bucketName , "1000" , "true" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-09-10 19:44:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-09-10 19:44:38 +02:00
// execute the HTTP request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
getContent , err = ioutil . ReadAll ( response . Body )
2016-09-22 08:03:54 +02:00
c . Assert ( err , IsNil )
2016-09-10 19:44:38 +02:00
c . Assert ( strings . Contains ( string ( getContent ) , "<Key>bar</Key>" ) , Equals , true )
c . Assert ( strings . Contains ( string ( getContent ) , "<Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner>" ) , Equals , true )
2016-08-12 20:28:27 +02:00
}
2016-06-29 11:30:36 +02:00
// TestListObjectsHandlerErrors - Setting invalid parameters to List Objects
// and then asserting the error response with the expected one.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestListObjectsHandlerErrors ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2015-07-17 02:32:33 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-07-17 21:32:05 +02:00
// create listObjectsV1 request with invalid value of max-keys parameter. max-keys is set to -2.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getListObjectsV1URL ( s . endPoint , bucketName , "-2" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-17 02:32:33 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2015-07-17 02:32:33 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// validating the error response.
2016-07-05 10:06:30 +02:00
verifyError ( c , response , "InvalidArgument" , "Argument maxKeys must be an integer between 0 and 2147483647" , http . StatusBadRequest )
2016-07-17 21:32:05 +02:00
// create listObjectsV2 request with invalid value of max-keys parameter. max-keys is set to -2.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getListObjectsV2URL ( s . endPoint , bucketName , "-2" , "" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-07-17 21:32:05 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-07-17 21:32:05 +02:00
// execute the HTTP request.
response , err = client . Do ( request )
c . Assert ( err , IsNil )
// validating the error response.
verifyError ( c , response , "InvalidArgument" , "Argument maxKeys must be an integer between 0 and 2147483647" , http . StatusBadRequest )
2015-07-12 21:40:38 +02:00
}
2016-06-29 11:30:36 +02:00
// TestPutBucketErrors - request for non valid bucket operation
// and validate it with expected error result.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestPutBucketErrors ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// generating a HTTP request to create bucket.
// using invalid bucket name.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , s . endPoint + "/putbucket-." ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// expected to fail with error message "InvalidBucketName".
2015-07-12 21:40:38 +02:00
verifyError ( c , response , "InvalidBucketName" , "The specified bucket is not valid." , http . StatusBadRequest )
2016-06-29 11:30:36 +02:00
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// make HTTP request to create the same bucket again.
// expected to fail with error message "BucketAlreadyOwnedByYou".
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
verifyError ( c , response , "BucketAlreadyOwnedByYou" , "Your previous request to create the named bucket succeeded and you already own it." ,
http . StatusConflict )
2015-07-12 21:40:38 +02:00
2016-06-29 11:30:36 +02:00
// request for ACL.
// Since Minio server doesn't support ACL's the request is expected to fail with "NotImplemented" error message.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , s . endPoint + "/" + bucketName + "?acl" ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-07-05 10:06:30 +02:00
verifyError ( c , response , "NotImplemented" , "A header you provided implies functionality that is not implemented" , http . StatusNotImplemented )
2015-07-12 21:40:38 +02:00
}
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestGetObjectLarge10MiB ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// form HTTP reqest to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create the bucket.
2016-06-25 12:03:27 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 11:30:36 +02: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 12:03:27 +02: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 11:30:36 +02:00
objectName := "test-big-object"
// create HTTP request for object upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buf . Len ( ) ) , buf , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Assert the status code to verify successful upload.
2016-06-25 12:03:27 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// prepare HTTP requests to download the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to download the object.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// extract the content from response body.
2016-06-25 12:03:27 +02:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Compare putContent and getContent.
2016-06-25 12:03:27 +02:00
c . Assert ( string ( getContent ) , Equals , putContent )
}
2016-06-29 11:30:36 +02:00
// TestGetObjectLarge11MiB - Tests validate fetching of an object of size 11MB.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestGetObjectLarge11MiB ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2016-06-25 12:03:27 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 11:30:36 +02: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 12:03:27 +02: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 ) )
}
2016-11-21 22:51:05 +01:00
putMD5 := getMD5Hash ( buffer . Bytes ( ) )
2016-06-25 12:03:27 +02:00
2016-06-29 11:30:36 +02:00
objectName := "test-11Mb-object"
2016-06-25 12:03:27 +02:00
// Put object
buf := bytes . NewReader ( buffer . Bytes ( ) )
2016-06-29 11:30:36 +02:00
// create HTTP request foe object upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buf . Len ( ) ) , buf , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request for object upload.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// create HTTP request to download the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// fetch the content from response body.
2016-06-25 12:03:27 +02:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Get md5Sum of the response content.
2016-11-21 22:51:05 +01:00
getMD5 := getMD5Hash ( getContent )
2016-06-25 12:03:27 +02:00
2016-06-29 11:30:36 +02:00
// Compare putContent and getContent.
2016-11-21 22:51:05 +01:00
c . Assert ( putMD5 , Equals , getMD5 )
2016-06-25 12:03:27 +02:00
}
// TestGetPartialObjectMisAligned - tests get object partially mis-aligned.
2016-06-29 11:30:36 +02: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.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestGetPartialObjectMisAligned ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create the bucket.
2016-06-25 12:03:27 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 11:30:36 +02: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 12:03:27 +02: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 11:30:36 +02:00
objectName := "test-big-file"
// HTTP request to upload the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buf . Len ( ) ) , buf , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the object.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// test Cases containing data to make partial range requests.
// also has expected response data.
2016-06-25 12:03:27 +02:00
var testCases = [ ] struct {
byteRange string
expectedString string
} {
2016-06-29 11:30:36 +02:00
// request for byte range 10-11.
// expecting the result to contain only putContent[10:12] bytes.
2016-06-25 12:03:27 +02:00
{ "10-11" , putContent [ 10 : 12 ] } ,
2016-06-29 11:30:36 +02:00
// request for object data after the first byte.
2016-06-25 12:03:27 +02:00
{ "1-" , putContent [ 1 : ] } ,
2016-06-29 11:30:36 +02:00
// request for object data after the first byte.
2016-06-25 12:03:27 +02:00
{ "6-" , putContent [ 6 : ] } ,
2016-06-29 11:30:36 +02:00
// request for last 2 bytes of th object.
2016-06-25 12:03:27 +02:00
{ "-2" , putContent [ len ( putContent ) - 2 : ] } ,
2016-06-29 11:30:36 +02:00
// request for last 7 bytes of the object.
2016-06-25 12:03:27 +02:00
{ "-7" , putContent [ len ( putContent ) - 7 : ] } ,
}
for _ , t := range testCases {
2016-06-29 11:30:36 +02:00
// HTTP request to download the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Get partial content based on the byte range set.
2016-06-25 12:03:27 +02:00
request . Header . Add ( "Range" , "bytes=" + t . byteRange )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
2016-06-25 12:03:27 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusPartialContent )
2016-06-29 11:30:36 +02:00
// parse the HTTP response body.
2016-06-25 12:03:27 +02:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Compare putContent and getContent.
2016-06-25 12:03:27 +02:00
c . Assert ( string ( getContent ) , Equals , t . expectedString )
}
}
2016-06-29 11:30:36 +02:00
// TestGetPartialObjectLarge11MiB - Test validates partial content request for a 11MiB object.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestGetPartialObjectLarge11MiB ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create the bucket.
2016-06-25 12:03:27 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 11:30:36 +02: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 12:03:27 +02: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 11:30:36 +02:00
objectName := "test-large-11Mb-object"
2016-06-25 12:03:27 +02:00
buf := bytes . NewReader ( [ ] byte ( putContent ) )
2016-06-29 11:30:36 +02:00
// HTTP request to upload the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buf . Len ( ) ) , buf , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the object.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// HTTP request to download the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
// This range spans into first two blocks.
request . Header . Add ( "Range" , "bytes=10485750-10485769" )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
2016-06-25 12:03:27 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusPartialContent )
2016-06-29 11:30:36 +02:00
// read the downloaded content from the response body.
2016-06-25 12:03:27 +02:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Compare putContent and getContent.
2016-06-25 12:03:27 +02:00
c . Assert ( string ( getContent ) , Equals , putContent [ 10485750 : 10485770 ] )
}
2016-06-29 11:30:36 +02:00
// TestGetPartialObjectLarge11MiB - Test validates partial content request for a 10MiB object.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestGetPartialObjectLarge10MiB ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2016-06-25 12:03:27 +02:00
response , err := client . Do ( request )
2016-06-29 11:30:36 +02:00
// expecting the error to be nil.
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// expecting the HTTP response status code to 200 OK.
2016-06-25 12:03:27 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
var buffer bytes . Buffer
2016-06-29 11:30:36 +02: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 12:03:27 +02: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 11:30:36 +02:00
putContent := buffer . String ( )
2016-06-25 12:03:27 +02:00
buf := bytes . NewReader ( [ ] byte ( putContent ) )
2016-06-29 11:30:36 +02:00
objectName := "test-big-10Mb-file"
// HTTP request to upload the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buf . Len ( ) ) , buf , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the object.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-07-27 20:57:08 +02:00
// verify whether upload was successful.
2016-06-25 12:03:27 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// HTTP request to download the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-06-25 12:03:27 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Get partial content based on the byte range set.
2016-06-25 12:03:27 +02:00
request . Header . Add ( "Range" , "bytes=2048-2058" )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to download the partila content.
2016-06-25 12:03:27 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
2016-06-25 12:03:27 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusPartialContent )
2016-06-29 11:30:36 +02:00
// read the downloaded content from the response body.
2016-06-25 12:03:27 +02:00
getContent , err := ioutil . ReadAll ( response . Body )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Compare putContent and getContent.
2016-06-25 12:03:27 +02:00
c . Assert ( string ( getContent ) , Equals , putContent [ 2048 : 2059 ] )
}
2016-06-29 11:30:36 +02:00
// TestGetObjectErrors - Tests validate error response for invalid object operations.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestGetObjectErrors ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02: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"
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
verifyError ( c , response , "NoSuchKey" , "The specified key does not exist." , http . StatusNotFound )
2016-06-29 11:30:36 +02:00
// request to download an object, but an invalid bucket name is set.
2016-11-17 01:23:22 +01:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , "getobjecterrors-." , objectName ) ,
2016-10-25 22:34:14 +02:00
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// expected to fail with "InvalidBucketName".
2015-07-12 21:40:38 +02:00
verifyError ( c , response , "InvalidBucketName" , "The specified bucket is not valid." , http . StatusBadRequest )
}
2016-06-29 11:30:36 +02:00
// TestGetObjectRangeErrors - Validate error response when object is fetched with incorrect byte range value.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestGetObjectRangeErrors ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// content for the object to be uploaded.
2015-07-12 21:40:38 +02:00
buffer1 := bytes . NewReader ( [ ] byte ( "Hello World" ) )
2016-06-29 11:30:36 +02:00
objectName := "test-object"
// HTTP request to upload the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the object.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-07-27 20:57:08 +02:00
// verify whether upload was successful.
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// HTTP request to download the object.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getGetObjectURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-07-05 10:06:30 +02:00
// Invalid byte range set.
2016-07-06 21:50:24 +02:00
request . Header . Add ( "Range" , "bytes=-0" )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// expected to fail with "InvalidRange" error message.
2016-07-05 10:06:30 +02:00
verifyError ( c , response , "InvalidRange" , "The requested range is not satisfiable" , http . StatusRequestedRangeNotSatisfiable )
2015-07-12 21:40:38 +02:00
}
2016-06-29 11:30:36 +02:00
// TestObjectMultipartAbort - Test validates abortion of a multipart upload after uploading 2 parts.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestObjectMultipartAbort ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2015-07-12 21:40:38 +02:00
2016-06-29 11:30:36 +02:00
objectName := "test-multipart-object"
2016-07-22 00:00:11 +02:00
// 1. Initiate 2 uploads for the same object
// 2. Upload 2 parts for the second upload
// 3. Abort the second upload.
// 4. Abort the first upload.
// This will test abort upload when there are more than one upload IDs
// and the case where there is only one upload ID.
2016-06-29 11:30:36 +02:00
// construct HTTP request to initiate a NewMultipart upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request initiating the new multipart upload.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
2016-09-02 08:10:50 +02:00
c . Assert ( err , IsNil )
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// parse the response body and obtain the new upload ID.
2015-07-12 21:40:38 +02:00
decoder := xml . NewDecoder ( response . Body )
2015-09-19 09:52:01 +02:00
newResponse := & InitiateMultipartUploadResponse { }
2015-07-12 21:40:38 +02:00
2016-07-22 00:00:11 +02:00
err = decoder . Decode ( newResponse )
c . Assert ( err , IsNil )
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
// construct HTTP request to initiate a NewMultipart upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-07-22 00:00:11 +02:00
c . Assert ( err , IsNil )
// execute the HTTP request initiating the new multipart upload.
response , err = client . Do ( request )
2016-09-02 08:10:50 +02:00
c . Assert ( err , IsNil )
2016-07-22 00:00:11 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
// parse the response body and obtain the new upload ID.
decoder = xml . NewDecoder ( response . Body )
newResponse = & InitiateMultipartUploadResponse { }
2015-07-12 21:40:38 +02:00
err = decoder . Decode ( newResponse )
c . Assert ( err , IsNil )
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
2016-06-29 11:30:36 +02:00
// uploadID to be used for rest of the multipart operations on the object.
2015-07-12 21:40:38 +02:00
uploadID := newResponse . UploadID
2016-06-29 11:30:36 +02:00
// content for the part to be uploaded.
2015-07-12 21:40:38 +02:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// HTTP request for the part to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "1" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the first part.
2015-07-12 21:40:38 +02:00
response1 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response1 . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// content for the second part to be uploaded.
2015-07-12 21:40:38 +02:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// HTTP request for the second part to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "2" ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the second part.
2015-07-12 21:40:38 +02:00
response2 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response2 . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// HTTP request for aborting the multipart upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "DELETE" , getAbortMultipartUploadURL ( s . endPoint , bucketName , objectName , uploadID ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request to abort the multipart upload.
2015-07-12 21:40:38 +02:00
response3 , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// expecting the response status code to be http.StatusNoContent.
// The assertion validates the success of Abort Multipart operation.
2015-07-12 21:40:38 +02:00
c . Assert ( response3 . StatusCode , Equals , http . StatusNoContent )
}
2016-06-29 11:30:36 +02:00
// TestBucketMultipartList - Initiates a NewMultipart upload, uploads parts and validates listing of the parts.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestBucketMultipartList ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) , 0 ,
nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , 200 )
2016-06-29 11:30:36 +02:00
objectName := "test-multipart-object"
// construct HTTP request to initiate a NewMultipart upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request initiating the new multipart upload.
2015-07-12 21:40:38 +02: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-31 01:15:28 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// expecting the response status code to be http.StatusOK(200 OK) .
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// parse the response body and obtain the new upload ID.
2015-07-12 21:40:38 +02:00
decoder := xml . NewDecoder ( response . Body )
2015-09-19 09:52:01 +02:00
newResponse := & InitiateMultipartUploadResponse { }
2015-07-12 21:40:38 +02:00
err = decoder . Decode ( newResponse )
c . Assert ( err , IsNil )
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
2016-06-29 11:30:36 +02:00
// uploadID to be used for rest of the multipart operations on the object.
2015-07-12 21:40:38 +02:00
uploadID := newResponse . UploadID
2016-06-29 11:30:36 +02:00
// content for the part to be uploaded.
2015-07-12 21:40:38 +02:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// HTTP request for the part to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "1" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the first part.
2015-07-12 21:40:38 +02:00
response1 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response1 . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// content for the second part to be uploaded.
2015-07-12 21:40:38 +02:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// HTTP request for the second part to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "2" ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the second part.
2015-07-12 21:40:38 +02:00
response2 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response2 . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// HTTP request to ListMultipart Uploads.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getListMultipartURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2015-07-12 21:40:38 +02:00
response3 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response3 . StatusCode , Equals , http . StatusOK )
2016-03-21 09:06:07 +01: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 07:44:43 +01: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 11:30:36 +02:00
// parse the response body.
2015-07-12 21:40:38 +02:00
decoder = xml . NewDecoder ( response3 . Body )
2016-03-20 07:44:43 +01:00
newResponse3 := & listMultipartUploadsResponse { }
2015-07-12 21:40:38 +02:00
err = decoder . Decode ( newResponse3 )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02: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 21:40:38 +02:00
}
2016-06-29 11:30:36 +02:00
// TestValidateObjectMultipartUploadID - Test Initiates a new multipart upload and validates the uploadID.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestValidateObjectMultipartUploadID ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-01-26 23:57:46 +01:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2016-01-26 23:57:46 +01:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , 200 )
2016-06-29 11:30:36 +02:00
objectName := "directory1/directory2/object"
// construct HTTP request to initiate a NewMultipart upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-01-26 23:57:46 +01:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request initiating the new multipart upload.
2016-01-26 23:57:46 +01:00
response , err = client . Do ( request )
2016-04-13 20:32:47 +02:00
c . Assert ( err , IsNil )
2016-01-26 23:57:46 +01:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// parse the response body and obtain the new upload ID.
2016-01-26 23:57:46 +01:00
decoder := xml . NewDecoder ( response . Body )
newResponse := & InitiateMultipartUploadResponse { }
err = decoder . Decode ( newResponse )
2016-06-29 11:30:36 +02:00
// expecting the decoding error to be nil.
2016-01-26 23:57:46 +01:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Verifying for Upload ID value to be greater than 0.
2016-01-26 23:57:46 +01:00
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
}
2016-06-29 11:30:36 +02:00
// TestObjectMultipartListError - Initiates a NewMultipart upload, uploads parts and validates
// error response for an incorrect max-parts parameter .
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestObjectMultipartListError ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , 200 )
2016-06-29 11:30:36 +02:00
objectName := "test-multipart-object"
// construct HTTP request to initiate a NewMultipart upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request initiating the new multipart upload.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
2016-09-02 08:10:50 +02:00
c . Assert ( err , IsNil )
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// parse the response body and obtain the new upload ID.
2015-07-12 21:40:38 +02:00
decoder := xml . NewDecoder ( response . Body )
2015-09-19 09:52:01 +02:00
newResponse := & InitiateMultipartUploadResponse { }
2015-07-12 21:40:38 +02:00
err = decoder . Decode ( newResponse )
c . Assert ( err , IsNil )
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
2016-06-29 11:30:36 +02:00
// uploadID to be used for rest of the multipart operations on the object.
2015-07-12 21:40:38 +02:00
uploadID := newResponse . UploadID
2016-06-29 11:30:36 +02:00
// content for the part to be uploaded.
2015-07-12 21:40:38 +02:00
buffer1 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// HTTP request for the part to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "1" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the first part.
2015-07-12 21:40:38 +02:00
response1 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response1 . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// content for the second part to be uploaded.
2015-07-12 21:40:38 +02:00
buffer2 := bytes . NewReader ( [ ] byte ( "hello world" ) )
2016-06-29 11:30:36 +02:00
// HTTP request for the second part to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "2" ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the second part.
2015-07-12 21:40:38 +02:00
response2 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response2 . StatusCode , Equals , http . StatusOK )
2016-08-12 20:28:27 +02:00
// HTTP request to ListMultipart Uploads.
// max-keys is set to valid value of 1
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getListMultipartURLWithParams ( s . endPoint , bucketName , objectName , uploadID , "1" , "" , "" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-08-12 20:28:27 +02:00
c . Assert ( err , IsNil )
// execute the HTTP request.
response3 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response3 . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// HTTP request to ListMultipart Uploads.
// max-keys is set to invalid value of -2.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "GET" , getListMultipartURLWithParams ( s . endPoint , bucketName , objectName , uploadID , "-2" , "" , "" ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-17 02:32:33 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// execute the HTTP request.
2015-07-17 02:32:33 +02:00
response4 , err := client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Since max-keys parameter in the ListMultipart request set to invalid value of -2,
// its expected to fail with error message "InvalidArgument".
2016-07-05 10:06:30 +02:00
verifyError ( c , response4 , "InvalidArgument" , "Argument max-parts must be an integer between 0 and 2147483647" , http . StatusBadRequest )
2015-07-12 21:40:38 +02:00
}
2016-06-29 11:30:36 +02: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.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestObjectValidMD5 ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2016-05-12 01:13:37 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2016-05-12 01:13:37 +02: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 11:30:36 +02:00
// content for the object to be uploaded.
2016-11-23 03:18:22 +01:00
data := bytes . Repeat ( [ ] byte ( "0123456789abcdef" ) , 5 * humanize . MiByte / 16 )
2016-06-29 11:30:36 +02:00
// calculate md5Sum of the data.
2016-11-21 22:51:05 +01:00
md5SumBase64 := getMD5HashBase64 ( data )
2016-05-12 01:13:37 +02:00
buffer1 := bytes . NewReader ( data )
2016-06-29 11:30:36 +02:00
objectName := "test-1-object"
// HTTP request for the object to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2016-05-12 01:13:37 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// set the Content-Md5 to be the hash to content.
2016-11-21 22:51:05 +01:00
request . Header . Set ( "Content-Md5" , md5SumBase64 )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-05-12 01:13:37 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-07-05 10:04:50 +02:00
// expecting a successful upload.
2016-05-12 01:13:37 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
objectName = "test-2-object"
2016-05-12 01:13:37 +02:00
buffer1 = bytes . NewReader ( data )
2016-06-29 11:30:36 +02:00
// HTTP request for the object to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPutObjectURL ( s . endPoint , bucketName , objectName ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2016-05-12 01:13:37 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// set Content-Md5 to invalid value.
2016-07-05 10:04:50 +02:00
request . Header . Set ( "Content-Md5" , "kvLTlMrX9NpYDQlEIFlnDA==" )
// expecting a failure during upload.
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-05-12 01:13:37 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Since Content-Md5 header was wrong, expecting to fail with "SignatureDoesNotMatch" error.
2016-06-21 21:10:18 +02: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-12 01:13:37 +02:00
}
2016-06-29 11:30:36 +02:00
// TestObjectMultipart - Initiates a NewMultipart upload, uploads 2 parts,
// completes the multipart upload and validates the status of the operation.
2016-07-04 22:18:41 +02:00
func ( s * TestSuiteCommon ) TestObjectMultipart ( c * C ) {
2016-06-29 11:30:36 +02:00
// generate a random bucket name.
bucketName := getRandomBucketName ( )
// HTTP request to create the bucket.
2016-10-25 22:34:14 +02:00
request , err := newTestSignedRequest ( "PUT" , getMakeBucketURL ( s . endPoint , bucketName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client := http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to create bucket.
2015-07-12 21:40:38 +02:00
response , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response . StatusCode , Equals , 200 )
2016-06-29 11:30:36 +02:00
objectName := "test-multipart-object"
// construct HTTP request to initiate a NewMultipart upload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "POST" , getNewMultipartURL ( s . endPoint , bucketName , objectName ) ,
0 , nil , s . accessKey , s . secretKey , s . signer )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request initiating the new multipart upload.
2015-07-12 21:40:38 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// expecting the response status code to be http.StatusOK(200 OK).
2015-07-12 21:40:38 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// parse the response body and obtain the new upload ID.
2015-07-12 21:40:38 +02:00
decoder := xml . NewDecoder ( response . Body )
2015-09-19 09:52:01 +02:00
newResponse := & InitiateMultipartUploadResponse { }
2015-07-12 21:40:38 +02:00
err = decoder . Decode ( newResponse )
c . Assert ( err , IsNil )
c . Assert ( len ( newResponse . UploadID ) > 0 , Equals , true )
2016-06-29 11:30:36 +02:00
// uploadID to be used for rest of the multipart operations on the object.
2015-07-12 21:40:38 +02:00
uploadID := newResponse . UploadID
2016-06-29 11:30:36 +02:00
// content for the part to be uploaded.
2016-05-09 08:49:49 +02:00
// Create a byte array of 5MB.
2016-11-23 03:18:22 +01:00
data := bytes . Repeat ( [ ] byte ( "0123456789abcdef" ) , 5 * humanize . MiByte / 16 )
2016-06-29 11:30:36 +02:00
// calculate md5Sum of the data.
2016-11-21 22:51:05 +01:00
md5SumBase64 := getMD5HashBase64 ( data )
2016-02-06 05:05:56 +01:00
2016-05-09 08:49:49 +02:00
buffer1 := bytes . NewReader ( data )
2016-06-29 11:30:36 +02:00
// HTTP request for the part to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "1" ) ,
int64 ( buffer1 . Len ( ) ) , buffer1 , s . accessKey , s . secretKey , s . signer )
2016-06-29 11:30:36 +02:00
// set the Content-Md5 header to the base64 encoding the md5Sum of the content.
2016-11-21 22:51:05 +01:00
request . Header . Set ( "Content-Md5" , md5SumBase64 )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the first part.
2015-07-12 21:40:38 +02:00
response1 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response1 . StatusCode , Equals , http . StatusOK )
2016-06-29 11:30:36 +02:00
// content for the second part to be uploaded.
// Create a byte array of 1 byte.
2016-05-09 08:49:49 +02:00
data = [ ] byte ( "0" )
2016-06-29 11:30:36 +02:00
// calculate md5Sum of the data.
2016-11-21 22:51:05 +01:00
md5SumBase64 = getMD5HashBase64 ( data )
2016-05-09 08:49:49 +02:00
buffer2 := bytes . NewReader ( data )
2016-06-29 11:30:36 +02:00
// HTTP request for the second part to be uploaded.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "PUT" , getPartUploadURL ( s . endPoint , bucketName , objectName , uploadID , "2" ) ,
int64 ( buffer2 . Len ( ) ) , buffer2 , s . accessKey , s . secretKey , s . signer )
2016-06-29 11:30:36 +02:00
// set the Content-Md5 header to the base64 encoding the md5Sum of the content.
2016-11-21 22:51:05 +01:00
request . Header . Set ( "Content-Md5" , md5SumBase64 )
2015-07-12 21:40:38 +02:00
c . Assert ( err , IsNil )
2016-10-26 11:30:31 +02:00
client = http . Client { Transport : s . transport }
2016-06-29 11:30:36 +02:00
// execute the HTTP request to upload the second part.
2015-07-12 21:40:38 +02:00
response2 , err := client . Do ( request )
c . Assert ( err , IsNil )
c . Assert ( response2 . StatusCode , Equals , http . StatusOK )
2016-02-06 05:05:56 +01: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 10:34:20 +02:00
completeUploads := & completeMultipartUpload {
Parts : [ ] completePart {
2015-07-12 21:40:38 +02:00
{
PartNumber : 1 ,
ETag : response1 . Header . Get ( "ETag" ) ,
} ,
{
PartNumber : 2 ,
ETag : response2 . Header . Get ( "ETag" ) ,
} ,
} ,
}
completeBytes , err := xml . Marshal ( completeUploads )
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Indicating that all parts are uploaded and initiating completeMultipartUpload.
2016-10-25 22:34:14 +02:00
request , err = newTestSignedRequest ( "POST" , getCompleteMultipartUploadURL ( s . endPoint , bucketName , objectName , uploadID ) ,
int64 ( len ( completeBytes ) ) , bytes . NewReader ( completeBytes ) , s . accessKey , s . secretKey , s . signer )
2016-06-20 15:18:47 +02:00
c . Assert ( err , IsNil )
2016-06-29 11:30:36 +02:00
// Execute the complete multipart request.
2016-06-20 15:18:47 +02:00
response , err = client . Do ( request )
c . Assert ( err , IsNil )
2016-07-27 20:57:08 +02:00
// verify whether complete multipart was successful.
2016-06-20 15:18:47 +02:00
c . Assert ( response . StatusCode , Equals , http . StatusOK )
2016-11-10 16:41:02 +01:00
var parts [ ] completePart
for _ , part := range completeUploads . Parts {
2017-03-16 04:48:49 +01:00
part . ETag = canonicalizeETag ( part . ETag )
2016-11-10 16:41:02 +01:00
parts = append ( parts , part )
}
etag , err := getCompleteMultipartMD5 ( parts )
c . Assert ( err , IsNil )
2017-03-16 04:48:49 +01:00
c . Assert ( canonicalizeETag ( response . Header . Get ( "Etag" ) ) , Equals , etag )
2016-06-20 15:18:47 +02:00
}