2021-04-19 03:41:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Copyright (c) 2015-2021 MinIO, Inc.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This file is part of MinIO Object Storage stack
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This program is free software: you can redistribute it and/or modify
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// it under the terms of the GNU Affero General Public License as published by
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// the Free Software Foundation, either version 3 of the License, or
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// (at your option) any later version.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This program is distributed in the hope that it will be useful
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// but WITHOUT ANY WARRANTY; without even the implied warranty of
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// GNU Affero General Public License for more details.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// You should have received a copy of the GNU Affero General Public License
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 07:23:42 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  cmd  
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"bytes" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-04 23:16:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"context" 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 03:10:18 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"encoding/xml" 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-13 17:53:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"fmt" 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"io" 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"math/rand" 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 03:10:18 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"net/http" 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 05:00:29 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"net/url" 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"reflect" 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-08 07:12:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"regexp" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-24 08:04:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"runtime" 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"strings" 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-08 11:07:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"sync" 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"testing" 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-21 03:44:44 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"time" 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/dustin/go-humanize" 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-28 00:03:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/minio/minio-go/v7/pkg/set" 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-02 05:59:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									xhttp  "github.com/minio/minio/internal/http" 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-05 03:57:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/minio/pkg/v2/policy" 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-31 01:58:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// API suite container common to both ErasureSD and Erasure.
  
						 
					
						
							
								
									
										
										
										
											2016-07-05 04:18:41 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								type  TestSuiteCommon  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									serverType  string 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 03:10:18 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									testServer  TestServer 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									endPoint    string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									accessKey   string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									secretKey   string 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									signer      signerType 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 17:30:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									secure      bool 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									client      * http . Client 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  check  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									* testing . T 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									testType  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-10-26 17:30:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Assert - checks if gotValue is same as expectedValue, if not fails the test.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( c  * check )  Assert ( gotValue  interface { } ,  expectedValue  interface { } )  {  
						 
					
						
							
								
									
										
										
										
											2023-01-04 00:16:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Helper ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ! reflect . DeepEqual ( gotValue ,  expectedValue )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 00:16:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Fatalf ( "Test %s expected %v, got %v" ,  c . testType ,  expectedValue ,  gotValue ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  verifyError ( c  * check ,  response  * http . Response ,  code ,  description  string ,  statusCode  int )  {  
						 
					
						
							
								
									
										
										
										
											2023-01-04 00:16:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Helper ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									data ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 07:41:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									errorResponse  :=  APIErrorResponse { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									err  =  xml . Unmarshal ( data ,  & errorResponse ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( errorResponse . Code ,  code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( errorResponse . Message ,  description ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  statusCode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  runAllTests ( suite  * TestSuiteCommon ,  c  * check )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . SetUpSuite ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-28 00:03:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									suite . TestCors ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 10:43:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									suite . TestObjectDir ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									suite . TestBucketPolicy ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestDeleteBucket ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestDeleteBucketNotEmpty ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestDeleteMultipleObjects ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestDeleteObject ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestNonExistentBucket ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestEmptyObject ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestBucket ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestObjectGetAnonymous ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestMultipleObjects ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestHeader ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestPutBucket ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestCopyObject ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestPutObject ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestListBuckets ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestValidateSignature ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestSHA256Mismatch ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestPutObjectLongName ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestNotBeAbleToCreateObjectInNonexistentBucket ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestHeadOnObjectLastModified ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestHeadOnBucket ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestContentTypePersists ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestPartialContent ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestListObjectsHandler ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-08 07:12:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									suite . TestListObjectVersionsOutputOrderHandler ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									suite . TestListObjectsHandlerErrors ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestPutBucketErrors ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestGetObjectLarge10MiB ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestGetObjectLarge11MiB ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestGetPartialObjectMisAligned ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestGetPartialObjectLarge11MiB ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestGetPartialObjectLarge10MiB ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestGetObjectErrors ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestGetObjectRangeErrors ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestObjectMultipartAbort ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestBucketMultipartList ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestValidateObjectMultipartUploadID ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestObjectMultipartListError ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestObjectValidMD5 ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TestObjectMultipart ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . TearDownSuite ( c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  TestServerSuite ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									testCases  :=  [ ] * TestSuiteCommon { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-31 01:58:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Init and run test on ErasureSD backend with signature v4.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ serverType :  "ErasureSD" ,  signer :  signerV4 } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Init and run test on ErasureSD backend with signature v2.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ serverType :  "ErasureSD" ,  signer :  signerV2 } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Init and run test on ErasureSD backend, with tls enabled.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ serverType :  "ErasureSD" ,  signer :  signerV4 ,  secure :  true } , 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Init and run test on Erasure backend.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ serverType :  "Erasure" ,  signer :  signerV4 } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Init and run test on ErasureSet backend.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ serverType :  "ErasureSet" ,  signer :  signerV4 } , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-07 17:33:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									globalServerCtxt . StrictS3Compat  =  true 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-16 09:45:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  i ,  testCase  :=  range  testCases  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( fmt . Sprintf ( "Test: %d, ServerType: %s" ,  i + 1 ,  testCase . serverType ) ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											runAllTests ( testCase ,  & check { t ,  testCase . serverType } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 07:41:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 03:10:18 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// Setting up the test suite.
  
						 
					
						
							
								
									
										
										
										
											2021-10-22 16:33:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Starting the Test server with temporary backend.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  SetUpSuite ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-10-26 17:30:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  s . secure  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-11 23:18:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										cert ,  key ,  err  :=  generateTLSCertKey ( "127.0.0.1" ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-11 23:18:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s . testServer  =  StartTestTLSServer ( c ,  s . serverType ,  cert ,  key ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 17:30:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s . testServer  =  StartTestServer ( c ,  s . serverType ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . client  =  s . testServer . Server . Client ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									s . endPoint  =  s . testServer . Server . URL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . accessKey  =  s . testServer . AccessKey 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . secretKey  =  s . testServer . SecretKey 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-04 23:16:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  RestartTestServer ( c  * check )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Shutdown.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . testServer . cancel ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . testServer . Server . Close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . testServer . Obj . Shutdown ( context . Background ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Restart.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ctx ,  cancel  :=  context . WithCancel ( context . Background ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . testServer . cancel  =  cancel 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . testServer  =  initTestServerWithBackend ( ctx ,  c ,  s . testServer ,  s . testServer . Obj ,  s . testServer . rawDiskPaths ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  s . secure  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s . testServer . Server . StartTLS ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s . testServer . Server . Start ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . client  =  s . testServer . Server . Client ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . endPoint  =  s . testServer . Server . URL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TearDownSuite ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-22 03:10:18 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									s . testServer . Stop ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-20 21:18:47 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestBucketSQSNotificationWebHook ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2017-01-10 06:22:10 +08: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:webhook</Queue></QueueConfiguration></NotificationConfiguration> ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// generate a random bucket Name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 06:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 06:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 06:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 06:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutNotificationURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 06:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( len ( bucketNotificationBuf ) ) ,  bytes . NewReader ( [ ] byte ( bucketNotificationBuf ) ) ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 06:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 06:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 06:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "InvalidArgument" ,  "A specified destination ARN does not exist or is not well-formed. Verify the destination ARN." ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-28 00:03:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestCors ( c  * check )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									expectedMap  :=  http . Header { } 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 07:58:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									expectedMap . Set ( "Access-Control-Allow-Credentials" ,  "true" ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-03 11:41:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									expectedMap . Set ( "Access-Control-Allow-Origin" ,  "http://foobar.com" ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-28 00:03:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									expectedMap [ "Access-Control-Expose-Headers" ]  =  [ ] string { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Date" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Etag" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Server" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Connection" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Accept-Ranges" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Content-Range" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Content-Encoding" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Content-Length" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Content-Type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Content-Disposition" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Last-Modified" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Content-Language" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Cache-Control" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Retry-After" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"X-Amz-Bucket-Region" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"Expires" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"X-Amz*" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"X-Amz*" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										"*" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 07:58:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									expectedMap . Set ( "Vary" ,  "Origin" ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-28 00:03:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									req ,  _  :=  http . NewRequest ( http . MethodOptions ,  s . endPoint ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 07:58:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									req . Header . Set ( "Origin" ,  "http://foobar.com" ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-28 00:03:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  s . client . Do ( req ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Fatal ( err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  k  :=  range  expectedMap  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  v ,  ok  :=  res . Header [ k ] ;  ! ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											c . Errorf ( "Expected key %s missing from %v" ,  k ,  res . Header ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedSet  :=  set . CreateStringSet ( expectedMap [ k ] ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											gotSet  :=  set . CreateStringSet ( strings . Split ( v [ 0 ] ,  ", " ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ! expectedSet . Equals ( gotSet )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												c . Errorf ( "Expected value %v, got %v" ,  strings . Join ( expectedMap [ k ] ,  ", " ) ,  v ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestObjectDir ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  "my-object-directory/" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getHeadObjectURL ( s . endPoint ,  bucketName ,  "my-object-directory/" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 10:43:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  "my-object-directory/" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 10:43:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodDelete ,  getDeleteObjectURL ( s . endPoint ,  bucketName ,  "my-object-directory/" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 05:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusNoContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestBucketSQSNotificationAMQP ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-09-17 18:19:39 +08: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.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-17 18:19:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-17 18:19:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-17 18:19:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutNotificationURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( len ( bucketNotificationBuf ) ) ,  bytes . NewReader ( [ ] byte ( bucketNotificationBuf ) ) ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-17 18:19:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-17 18:19:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-17 18:19:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									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 17:30:36 +08: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.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestBucketPolicy ( c  * check )  {  
						 
					
						
							
								
									
										
										
											
												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-16 01:38:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Sample bucket policy.
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-25 06:53:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bucketPolicyBuf  :=  ` { "Version":"2012-10-17","Statement":[ { "Action":["s3:GetBucketLocation","s3:ListBucket"],"Effect":"Allow","Principal": { "AWS":["*"]},"Resource":["arn:aws:s3:::%s"]}, { "Action":["s3:GetObject"],"Effect":"Allow","Principal": { "AWS":["*"]},"Resource":["arn:aws:s3:::%s/this*"]}]} ` 
							 
						 
					
						
							
								
									
										
										
											
												bucketpolicy: Improve bucket policy validation, avoid nested rules.
Bucket policy validation is more stricter now, to avoid nested
rules. The reason to do this is keep the rules simpler and more
meaningful avoiding conflicts.
This patch implements stricter checks.
Example policy to be generally avoided.
```
{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Action": [
				"s3:GetObject",
				"s3:DeleteObject"
			],
			"Effect": "Allow",
			"Principal": {
				"AWS": [
					"*"
				]
			},
			"Resource": [
				"arn:aws:s3:::jarjarbing/*"
			]
		},
		{
			"Action": [
				"s3:GetObject",
				"s3:DeleteObject"
			],
			"Effect": "Deny",
			"Principal": {
				"AWS": [
					"*"
				]
			},
			"Resource": [
				"arn:aws:s3:::jarjarbing/restic/key/*"
			]
		}
	]
}
```
											 
										 
										
											2016-03-16 01:38:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
											
												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-16 01:38:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 01:28:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Put a new bucket policy.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutPolicyURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( len ( bucketPolicyStr ) ) ,  bytes . NewReader ( [ ] byte ( bucketPolicyStr ) ) ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusNoContent ) 
							 
						 
					
						
							
								
									
										
										
											
												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-16 01:38:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Fetch the uploaded policy.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetPolicyURL ( s . endPoint ,  bucketName ) ,  0 ,  nil , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
											
												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-16 01:38:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
											
												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-16 01:38:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bucketPolicyReadBuf ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-04 09:43:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Verify if downloaded policy matches with previously uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-05 03:57:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									expectedPolicy ,  err  :=  policy . ParseBucketPolicyConfig ( strings . NewReader ( bucketPolicyStr ) ,  bucketName ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-25 06:53:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-05 03:57:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									gotPolicy ,  err  :=  policy . ParseBucketPolicyConfig ( bytes . NewReader ( bucketPolicyReadBuf ) ,  bucketName ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-25 06:53:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( reflect . DeepEqual ( expectedPolicy ,  gotPolicy ) ,  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-16 01:38:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Delete policy.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodDelete ,  getDeletePolicyURL ( s . endPoint ,  bucketName ) ,  0 ,  nil , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
											
												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-16 01:38:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusNoContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-03 07:58:10 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Verify if the policy was indeed deleted.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetPolicyURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-03 07:58:10 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  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-16 01:38:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestDeleteBucket - validates DELETE bucket operation.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestDeleteBucket ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 05:08:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 02:26:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// construct request to delete the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodDelete ,  getDeleteBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 02:26:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Assert the response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusNoContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 05:08:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestDeleteBucketNotEmpty - Validates the operation during an attempt to delete a non-empty bucket.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestDeleteBucketNotEmpty ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-05 16:35:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-05 16:35:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate http request for an object upload.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// "test-object" is the object name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-object" 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-05 16:35:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the request to complete object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the status code of the response.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-05 16:35:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// constructing http request to delete the bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// making an attempt to delete an non-empty bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// expected to fail.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodDelete ,  getDeleteBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-05 16:35:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusConflict ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-05 16:35:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestListenNotificationHandler ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									req ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( req ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									invalidBucket  :=  "Invalid\\Bucket" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tooByte  :=  bytes . Repeat ( [ ] byte ( "a" ) ,  1025 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tooBigPrefix  :=  string ( tooByte ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									validEvents  :=  [ ] string { "s3:ObjectCreated:*" ,  "s3:ObjectRemoved:*" } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									invalidEvents  :=  [ ] string { "invalidEvent" } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									req ,  err  =  newTestSignedRequest ( http . MethodGet , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										getListenNotificationURL ( s . endPoint ,  invalidBucket ,  [ ] string { } ,  [ ] string { } ,  [ ] string { } ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( req ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "InvalidBucketName" ,  "The specified bucket is not valid." ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									req ,  err  =  newTestSignedRequest ( http . MethodGet , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										getListenNotificationURL ( s . endPoint ,  bucketName ,  [ ] string { } ,  [ ] string { } ,  invalidEvents ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( req ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "InvalidArgument" ,  "A specified event is not supported for notifications." ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									req ,  err  =  newTestSignedRequest ( http . MethodGet , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										getListenNotificationURL ( s . endPoint ,  bucketName ,  [ ] string { tooBigPrefix } ,  [ ] string { } ,  validEvents ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( req ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "InvalidArgument" ,  "Size of filter rule value cannot exceed 1024 bytes in UTF-8 representation" ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									req ,  err  =  newTestSignedBadSHARequest ( http . MethodGet , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										getListenNotificationURL ( s . endPoint ,  bucketName ,  [ ] string { } ,  [ ] string { } ,  validEvents ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-22 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( req ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08: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 13:56:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-04 09:43:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Test deletes multiple objects and verifies server response.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestDeleteMultipleObjects ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									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 ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// execute the http request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// assert the status of http response.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Append all objects.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										delObjReq . Objects  =  append ( delObjReq . Objects ,  ObjectToDelete { 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-03 17:28:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ObjectV :  ObjectV { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ObjectName :  objName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Marshal delete request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									deleteReqBytes ,  err  :=  xml . Marshal ( delObjReq ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Delete list of objects.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPost ,  getMultiDeleteObjectURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( len ( deleteReqBytes ) ) ,  bytes . NewReader ( deleteReqBytes ) ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-03 01:15:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									deleteResp  :=  DeleteObjectsResponse { } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									delRespBytes ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  =  xml . Unmarshal ( delRespBytes ,  & deleteResp ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  i  :=  0 ;  i  <  10 ;  i ++  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 02:49:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// All the objects should be under deleted list (including non-existent object)
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( deleteResp . DeletedObjects [ i ] ,  DeletedObject { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ObjectName :  delObjReq . Objects [ i ] . ObjectName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											VersionID :   delObjReq . Objects [ i ] . VersionID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( len ( deleteResp . Errors ) ,  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Attempt second time results should be same, NoSuchKey for objects not found
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// shouldn't be set.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPost ,  getMultiDeleteObjectURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( len ( deleteReqBytes ) ) ,  bytes . NewReader ( deleteReqBytes ) ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									deleteResp  =  DeleteObjectsResponse { } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									delRespBytes ,  err  =  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  =  xml . Unmarshal ( delRespBytes ,  & deleteResp ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 14:55:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( len ( deleteResp . DeletedObjects ) ,  len ( delObjReq . Objects ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  i  :=  0 ;  i  <  10 ;  i ++  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( deleteResp . DeletedObjects [ i ] ,  DeletedObject { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ObjectName :  delObjReq . Objects [ i ] . ObjectName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											VersionID :   delObjReq . Objects [ i ] . VersionID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( len ( deleteResp . Errors ) ,  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-02 16:59:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-05-15 06:47:19 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// Tests delete object responses and success.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestDeleteObject ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 02:26:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 02:26:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "prefix/myobject" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// obtain http request to upload object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// object Name contains a prefix.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 02:26:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the http request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the status of http response.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 02:26:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-30 10:43:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// object name was "prefix/myobject", an attempt to delete "prefix"
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-17 13:18:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Should not delete "prefix/myobject"
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodDelete ,  getDeleteObjectURL ( s . endPoint ,  bucketName ,  "prefix" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusNoContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-17 13:18:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// create http request to HEAD on the object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// this helps to validate the existence of the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getHeadObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Assert the HTTP response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// create HTTP request to delete the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodDelete ,  getDeleteObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the http request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusNoContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-15 06:47:19 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Delete of non-existent data should return success.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodDelete ,  getDeleteObjectURL ( s . endPoint ,  bucketName ,  "prefix/myobject1" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the http request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the http response status.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusNoContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 05:08:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestNonExistentBucket - Asserts response for HEAD on non-existent bucket.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestNonExistentBucket ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodHead ,  getHEADBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the http request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Assert the response.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusNotFound ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestEmptyObject - Asserts the response for operation on a 0 byte object.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestEmptyObject ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the http request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// construct http request for uploading the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the upload request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the http response.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// make HTTP request to fetch the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the http request to fetch object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  buffer  bytes . Buffer 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// extract the body of the response.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									responseBody ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the http response body content.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( true ,  bytes . Equal ( responseBody ,  buffer . Bytes ( ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestBucket ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// Tests get anonymous object.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestObjectGetAnonymous ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									buffer  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the make bucket http request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the response http status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  :=  "testObject" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// create HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer . Len ( ) ) ,  buffer ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the HTTP response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// initiate anonymous HTTP request to fetch the object which does not exist. We need to return AccessDenied.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Get ( getGetObjectURL ( s . endPoint ,  bucketName ,  objectName + ".1" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// 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.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Get ( getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-11 11:10:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the http response status code.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "AccessDenied" ,  "Access Denied." ,  http . StatusForbidden ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestMultipleObjects - Validates upload and fetching of multiple object into the bucket.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestMultipleObjects ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// constructing HTTP request to fetch a non-existent object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// expected to fail, error response asserted for expected error values later.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  :=  "testObject" 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Asserting the error response with the expected values.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "NoSuchKey" ,  "The specified key does not exist." ,  http . StatusNotFound ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  =  "testObject1" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// content for the object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "hello one" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// create HTTP request for the object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the returned values.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// create HTTP request to fetch the object which was uploaded above.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert whether 200 OK response status is obtained.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// extract the response body.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									responseBody ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the content body for the expected object data.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( true ,  bytes . Equal ( responseBody ,  [ ] byte ( "hello one" ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// data for new object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer2  :=  bytes . NewReader ( [ ] byte ( "hello two" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  =  "testObject2" 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer2 . Len ( ) ) ,  buffer2 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the response status code for expected value 200 OK.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// fetch the object which was uploaded above.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to fetch the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// assert the response status code for expected value 200 OK.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// verify response data
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									responseBody ,  err  =  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( true ,  bytes . Equal ( responseBody ,  [ ] byte ( "hello two" ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// data for new object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer3  :=  bytes . NewReader ( [ ] byte ( "hello three" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  =  "testObject3" 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer3 . Len ( ) ) ,  buffer3 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// verify the response code with the expected value of 200 OK.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// fetch the object which was uploaded above.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// verify object.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									responseBody ,  err  =  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( true ,  bytes . Equal ( responseBody ,  [ ] byte ( "hello three" ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestHeader - Validates the error response for an attempt to fetch non-existent object.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestHeader ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// obtain HTTP request to fetch an object from non-existent bucket/object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  "testObject" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// asserting for the expected error response.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "NoSuchBucket" ,  "The specified bucket does not exist" ,  http . StatusNotFound ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestPutBucket ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-04 09:43:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Block 1: Testing for racy access
 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-08 11:07:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// 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 17:45:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  i  :=  0 ;  i  <  testConcurrencyLevel ;  i ++  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-08 11:07:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										wg . Add ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										go  func ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											defer  wg . Done ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-08 11:07:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-12 15:26:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-24 00:44:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												c . Errorf ( "Put bucket Failed: <ERROR> %s" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-12 15:26:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-08 11:07:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											defer  response . Body . Close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									wg . Wait ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									bucketName  =  getRandomBucketName ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 01:28:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Block 2: testing for correctness of the functionality
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-08 11:07:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									response . Body . Close ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestCopyObject - Validates copy object.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// The following is the test flow.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 1. Create bucket.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 2. Insert Object.
  
						 
					
						
							
								
									
										
										
										
											2016-10-04 15:09:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 3. Use "X-Amz-Copy-Source" header to copy the previously created object.
  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// 4. Validate the content of copied object.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestCopyObject ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-27 19:04:52 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-27 19:04:52 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-04 15:09:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// content for the object to be created.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-27 19:04:52 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "testObject" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// create HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									request . Header . Set ( "Content-Type" ,  "application/json" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  s . signer  ==  signerV2  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										err  =  signRequestV2 ( request ,  s . accessKey ,  s . secretKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-27 19:04:52 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName2  :=  "testObject2" 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-17 10:24:23 +08: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.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName2 ) ,  0 ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// setting the "X-Amz-Copy-Source" to allow copying the content of previously uploaded object.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-07 03:08:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Header . Set ( "X-Amz-Copy-Source" ,  url . QueryEscape ( SlashSeparator + bucketName + SlashSeparator + objectName ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  s . signer  ==  signerV4  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										err  =  signRequestV4 ( request ,  s . accessKey ,  s . secretKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										err  =  signRequestV2 ( request ,  s . accessKey ,  s . secretKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// the content is expected to have the content of previous disk.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-27 19:04:52 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// creating HTTP request to fetch the previously uploaded object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName2 ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// executing the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// validating the response status code.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// reading the response body.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// response body is expected to have the copied content of the first uploaded object.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									object ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( string ( object ) ,  "hello world" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-27 19:04:52 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestPutObject -  Tests successful put object request.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestPutObject ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for new object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "testObject" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// creating HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// fetch the object back and verify its contents.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to fetch the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . ContentLength ,  int64 ( len ( [ ] byte ( "hello world" ) ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									var  buffer2  bytes . Buffer 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-21 12:55:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// retrieve the contents of response body.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									n ,  err  :=  io . Copy ( & buffer2 ,  response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( n ,  int64 ( len ( [ ] byte ( "hello world" ) ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// asserted the contents of the fetched object with the expected result.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( true ,  bytes . Equal ( buffer2 . Bytes ( ) ,  [ ] byte ( "hello world" ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-24 13:51:12 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 10:51:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Test the response when object name ends with a slash.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// This is a special case with size as '0' and object ends with
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// a slash separator, we treat it like a valid operation and
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// return success.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response Etag headers should contain Md5Sum of empty string.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  =  "objectwith/" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// create HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 10:51:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  s . signer  ==  signerV2  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 10:51:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										err  =  signRequestV2 ( request ,  s . accessKey ,  s . secretKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 10:51:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// execute the HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 10:51:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// The response Etag header should contain Md5sum of an empty string.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-03 13:34:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . Header . Get ( xhttp . ETag ) ,  "\"" + emptyETag + "\"" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestListBuckets - Make request for listing of all buckets.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// XML response is parsed.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Its success verifies the format of the response.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestListBuckets ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2017-10-04 01:34:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to list buckets.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-04 01:34:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// create HTTP request for listing buckets.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getListBucketURL ( s . endPoint ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-04 01:34:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-04 01:34:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to list buckets.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-04 01:34:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-19 15:52:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									var  results  ListBucketsResponse 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// parse the list bucket response.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									decoder  :=  xml . NewDecoder ( response . Body ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									err  =  decoder . Decode ( & results ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-28 02:57:08 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// validating that the xml-decoding/parsing was successful.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-04 01:34:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Fetch the bucket created above
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  createdBucket  Bucket 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  b  :=  range  results . Buckets . Buckets  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  b . Name  ==  bucketName  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											createdBucket  =  b 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( createdBucket . Name  !=  "" ,  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-04 01:34:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Parse the bucket modtime
 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-26 07:51:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									creationTime ,  err  :=  time . Parse ( iso8601TimeFormat ,  createdBucket . CreationDate ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-04 01:34:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Check if bucket modtime is consistent (not less than current time and not late more than 5 minutes)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									timeNow  :=  time . Now ( ) . UTC ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( creationTime . Before ( timeNow ) ,  true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( timeNow . Sub ( creationTime )  <  time . Minute * 5 ,  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// This tests validate if PUT handler can successfully detect signature mismatch.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestValidateSignature ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									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" 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objName ) ,  0 ,  nil ,  s . accessKey ,  secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08: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 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This tests validate if PUT handler can successfully detect SHA256 mismatch.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestSHA256Mismatch ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									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.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objName ) ,  0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  s . signer  ==  signerV4  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( request . Header . Get ( "x-amz-content-sha256" ) ,  "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Set the body to generate signature mismatch.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-21 08:33:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									helloReader  :=  bytes . NewReader ( [ ] byte ( "Hello, World" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									request . ContentLength  =  helloReader . Size ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Body  =  io . NopCloser ( helloReader ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08: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 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-17 09:05:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// TestPutObjectLongName - Validates the error response
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// on an attempt to upload an object with long name.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestPutObjectLongName ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-13 17:53:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Content for the object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-13 17:53:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// make long object name.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-13 17:53:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									longObjName  :=  fmt . Sprintf ( "%0255d/%0255d/%0255d" ,  1 ,  1 ,  1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-02 02:00:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  IsDocker ( )  ||  IsKubernetes ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										longObjName  =  fmt . Sprintf ( "%0242d/%0242d/%0242d" ,  1 ,  1 ,  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// create new HTTP request to insert the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  longObjName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer . Len ( ) ) ,  buffer ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-12 12:38:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 01:28:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// make long object name.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-12 12:38:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									longObjName  =  fmt . Sprintf ( "%0255d/%0255d/%0255d/%0255d/%0255d" ,  1 ,  1 ,  1 ,  1 ,  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  IsDocker ( )  ||  IsKubernetes ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										longObjName  =  fmt . Sprintf ( "%0242d/%0242d/%0242d/%0242d/%0242d" ,  1 ,  1 ,  1 ,  1 ,  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// create new HTTP request to insert the object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									buffer  =  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  longObjName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-12 12:38:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer . Len ( ) ) ,  buffer ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-12 12:38:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "KeyTooLongError" ,  "Your key is too long" ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-10 04:58:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// make object name as unsupported
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-13 17:53:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									longObjName  =  fmt . Sprintf ( "%0256d" ,  1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer  =  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  longObjName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer . Len ( ) ) ,  buffer ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-13 17:53:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-25 09:13:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "XMinioInvalidObjectName" ,  "Object name contains unsupported characters." ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-13 17:53:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestNotBeAbleToCreateObjectInNonexistentBucket - Validates the error response
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// on an attempt to upload an object into a non-existent bucket.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestNotBeAbleToCreateObjectInNonexistentBucket ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// content of the object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// preparing for upload by generating the upload URL.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-object" 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Assert the response error message.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "NoSuchBucket" ,  "The specified bucket does not exist" ,  http . StatusNotFound ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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).
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestHeadOnObjectLastModified ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// preparing for object upload.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// content for the object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// obtaining URL for uploading the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// executing the HTTP request to download the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// make HTTP request to obtain object info.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getHeadObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// verify the status of the HTTP response.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-29 10:10:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-21 12:55:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// retrieve the info of last modification time of the object from the response header.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-29 10:10:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									lastModified  :=  response . Header . Get ( "Last-Modified" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Parse it into time.Time structure.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-29 10:10:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									t ,  err  :=  time . Parse ( http . TimeFormat ,  lastModified ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-29 10:10:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// make HTTP request to obtain object info.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// But this time set the "If-Modified-Since" header to be 10 minute more than the actual
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// last modified time of the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getHeadObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									request . Header . Set ( "If-Modified-Since" ,  t . Add ( 10 * time . Minute ) . UTC ( ) . Format ( http . TimeFormat ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08: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.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusNotModified ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-29 10:10:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getHeadObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									request . Header . Set ( "If-Unmodified-Since" ,  t . Add ( - 10 * time . Minute ) . UTC ( ) . Format ( http . TimeFormat ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusPreconditionFailed ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 03:34:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// make HTTP request to obtain object info.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// But this time set a date with unrecognized format to the "If-Modified-Since" header
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getHeadObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 03:34:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 03:34:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Header . Set ( "If-Unmodified-Since" ,  "Mon, 02 Jan 2006 15:04:05 +00:00" ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 03:34:57 +08: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.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestHeadOnBucket - Validates response for HEAD on the bucket.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// HEAD request on the bucket validates the existence of the bucket.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestHeadOnBucket ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getHEADBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// make HEAD request on the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getHEADBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Asserting the response status for expected value of http.StatusOK.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestContentTypePersists ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Uploading a new object with Content-Type "image/png".
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the object to be uploaded.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-object.png" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// constructing HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									request . Header . Set ( "Content-Type" ,  "image/png" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  s . signer  ==  signerV2  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										err  =  signRequestV2 ( request ,  s . accessKey ,  s . secretKey ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Fetching the object info using HEAD request for the object which was uploaded above.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getHeadObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Verify if the Content-Type header is set during the object persists.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . Header . Get ( "Content-Type" ) ,  "image/png" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Fetching the object itself and then verify the Content-Type header.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Execute the HTTP to fetch the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Verify if the Content-Type header is set during the object persists.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . Header . Get ( "Content-Type" ) ,  "image/png" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Uploading a new object with Content-Type  "application/json".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  =  "test-object.json" 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer2  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer2 . Len ( ) ) ,  buffer2 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// setting the request header to be application/json.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									request . Header . Set ( "Content-Type" ,  "application/json" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  s . signer  ==  signerV2  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										err  =  signRequestV2 ( request ,  s . accessKey ,  s . secretKey ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Execute the HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Obtain the info of the object which was uploaded above using HEAD request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodHead ,  getHeadObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Assert if the content-type header set during the object upload persists.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . Header . Get ( "Content-Type" ) ,  "application/json" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Fetch the object and assert whether the Content-Type header persists.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Assert if the content-type header set during the object upload persists.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . Header . Get ( "Content-Type" ) ,  "application/json" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestPartialContent ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "Hello World" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  "bar" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
											
												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 16:34:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Prepare request
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  "bar" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 07:58:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Header . Set ( "Range" ,  "bytes=6-7" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusPartialContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									partialObject ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( string ( partialObject ) ,  "Wo" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestListObjectsHandler - Setting valid parameters to List Objects
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// and then asserting the response with the expected one.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestListObjectsHandler ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  objectName  :=  range  [ ] string { "foo bar 1" ,  "foo bar 2" }  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										buffer  :=  bytes . NewReader ( [ ] byte ( "Hello World" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											int64 ( buffer . Len ( ) ) ,  buffer ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-11 01:44:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-03 01:15:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									testCases  :=  [ ] struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										getURL           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedStrings  [ ] string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ getListObjectsV1URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "" ) ,  [ ] string { "<Key>foo bar 1</Key>" ,  "<Key>foo bar 2</Key>" } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ getListObjectsV1URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "url" ) ,  [ ] string { "<Key>foo+bar+1</Key>" ,  "<Key>foo+bar+2</Key>" } } , 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-03 01:15:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											getListObjectsV2URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "" ,  "" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											[ ] string { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo bar 1</Key>" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo bar 2</Key>" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-03 01:15:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											getListObjectsV2URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "true" ,  "" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											[ ] string { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo bar 1</Key>" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo bar 2</Key>" , 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-10 04:58:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												fmt . Sprintf ( "<Owner><ID>%s</ID><DisplayName>minio</DisplayName></Owner>" ,  globalMinioDefaultOwnerID ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ getListObjectsV2URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "" ,  "url" ) ,  [ ] string { "<Key>foo+bar+1</Key>" ,  "<Key>foo+bar+2</Key>" } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-11 01:44:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-24 08:04:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  testCase  :=  range  testCases  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// create listObjectsV1 request with valid parameters
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										request ,  err  =  newTestSignedRequest ( http . MethodGet ,  testCase . getURL ,  0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// execute the HTTP request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										getContent ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-24 08:04:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  _ ,  expectedStr  :=  range  testCase . expectedStrings  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											c . Assert ( strings . Contains ( string ( getContent ) ,  expectedStr ) ,  true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-08 07:12:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// TestListObjectVersionsHandler - checks the order of <Version>
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// and <DeleteMarker> XML tags in a version listing
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestListObjectVersionsOutputOrderHandler ( c  * check )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									makeBucketRequest ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( makeBucketRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									enableVersioningBody  :=  [ ] byte ( "<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									enableVersioningBucketRequest ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getBucketVersioningConfigURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										int64 ( len ( enableVersioningBody ) ) ,  bytes . NewReader ( enableVersioningBody ) ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( enableVersioningBucketRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  objectName  :=  range  [ ] string { "file.1" ,  "file.2" }  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										buffer  :=  bytes . NewReader ( [ ] byte ( "testcontent" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										putRequest ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											int64 ( buffer . Len ( ) ) ,  buffer ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										response ,  err  =  s . client . Do ( putRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										delRequest ,  err  :=  newTestSignedRequest ( http . MethodDelete ,  getDeleteObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										response ,  err  =  s . client . Do ( delRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( response . StatusCode ,  http . StatusNoContent ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// create listObjectsV1 request with valid parameters
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodGet ,  getListObjectVersionsURL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									getContent ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									r  :=  regexp . MustCompile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										` <ListVersionsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">.* `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											` <DeleteMarker><Key>file.1</Key>.*<IsLatest>true</IsLatest>.*</DeleteMarker> `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											` <Version><Key>file.1</Key>.*<IsLatest>false</IsLatest>.*</Version> `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											` <DeleteMarker><Key>file.2</Key>.*<IsLatest>true</IsLatest>.*</DeleteMarker> `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											` <Version><Key>file.2</Key>.*<IsLatest>false</IsLatest>.*</Version> `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											` </ListVersionsResult> ` ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( r . MatchString ( string ( getContent ) ) ,  true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-24 08:04:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// TestListObjectsSpecialCharactersHandler - Setting valid parameters to List Objects
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// and then asserting the response with the expected one.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestListObjectsSpecialCharactersHandler ( c  * check )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  runtime . GOOS  ==  globalWindowsOSName  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Skip ( "skip special character test for windows" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  objectName  :=  range  [ ] string { "foo bar 1" ,  "foo bar 2" ,  "foo \x01 bar" }  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										buffer  :=  bytes . NewReader ( [ ] byte ( "Hello World" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											int64 ( buffer . Len ( ) ) ,  buffer ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									testCases  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										getURL           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedStrings  [ ] string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ getListObjectsV1URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "" ) ,  [ ] string { "<Key>foo bar 1</Key>" ,  "<Key>foo bar 2</Key>" ,  "<Key>foo  bar</Key>" } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ getListObjectsV1URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "url" ) ,  [ ] string { "<Key>foo+bar+1</Key>" ,  "<Key>foo+bar+2</Key>" ,  "<Key>foo+%01+bar</Key>" } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											getListObjectsV2URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "" ,  "" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											[ ] string { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo bar 1</Key>" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo bar 2</Key>" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo  bar</Key>" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												fmt . Sprintf ( "<Owner><ID>%s</ID><DisplayName>minio</DisplayName></Owner>" ,  globalMinioDefaultOwnerID ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											getListObjectsV2URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "true" ,  "" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											[ ] string { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo bar 1</Key>" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo bar 2</Key>" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"<Key>foo  bar</Key>" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												fmt . Sprintf ( "<Owner><ID>%s</ID><DisplayName>minio</DisplayName></Owner>" ,  globalMinioDefaultOwnerID ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ getListObjectsV2URL ( s . endPoint ,  bucketName ,  "" ,  "1000" ,  "" ,  "url" ) ,  [ ] string { "<Key>foo+bar+1</Key>" ,  "<Key>foo+bar+2</Key>" ,  "<Key>foo+%01+bar</Key>" } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-28 06:39:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  testCase  :=  range  testCases  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// create listObjectsV1 request with valid parameters
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										request ,  err  =  newTestSignedRequest ( http . MethodGet ,  testCase . getURL ,  0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-22 14:03:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										getContent ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-11 01:44:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 14:14:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  expectedStr  :=  range  testCase . expectedStrings  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											c . Assert ( strings . Contains ( string ( getContent ) ,  expectedStr ) ,  true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestListObjectsHandlerErrors - Setting invalid parameters to List Objects
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// and then asserting the error response with the expected one.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestListObjectsHandlerErrors ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 08:32:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-18 03:32:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// create listObjectsV1 request with invalid value of max-keys parameter. max-keys is set to -2.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getListObjectsV1URL ( s . endPoint ,  bucketName ,  "" ,  "-2" ,  "" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// validating the error response.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "InvalidArgument" ,  "Argument maxKeys must be an integer between 0 and 2147483647" ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-18 03:32:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// create listObjectsV2 request with invalid value of max-keys parameter. max-keys is set to -2.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getListObjectsV2URL ( s . endPoint ,  bucketName ,  "" ,  "-2" ,  "" ,  "" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-18 03:32:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-18 03:32:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// validating the error response.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "InvalidArgument" ,  "Argument maxKeys must be an integer between 0 and 2147483647" ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestPutBucketErrors - request for non valid bucket operation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// and validate it with expected error result.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestPutBucketErrors ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// generating a HTTP request to create bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// using invalid bucket name.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  s . endPoint + "/putbucket-." , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expected to fail with error message "InvalidBucketName".
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "InvalidBucketName" ,  "The specified bucket is not valid." ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// make HTTP request to create the same bucket again.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// expected to fail with error message "BucketAlreadyOwnedByYou".
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "BucketAlreadyOwnedByYou" ,  "Your previous request to create the named bucket succeeded and you already own it." , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										http . StatusConflict ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestGetObjectLarge10MiB ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-04 09:43:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// form HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  buffer  bytes . Buffer 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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 18:03:27 +08: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 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-big-object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// create HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buf . Len ( ) ) ,  buf ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Assert the status code to verify successful upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// prepare HTTP requests to download the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to download the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// extract the content from response body.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getContent ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Compare putContent and getContent.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( string ( getContent ) ,  putContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestGetObjectLarge11MiB - Tests validate fetching of an object of size 11MB.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestGetObjectLarge11MiB ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  buffer  bytes . Buffer 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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 18:03:27 +08: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-22 05:51:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									putMD5  :=  getMD5Hash ( buffer . Bytes ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-11Mb-object" 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Put object
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									buf  :=  bytes . NewReader ( buffer . Bytes ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// create HTTP request foe object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buf . Len ( ) ) ,  buf ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request for object upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// create HTTP request to download the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// fetch the content from response body.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getContent ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-05-15 03:05:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Get etag of the response content.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-22 05:51:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getMD5  :=  getMD5Hash ( getContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Compare putContent and getContent.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( putMD5 ,  getMD5 ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// TestGetPartialObjectMisAligned - tests get object partially mis-aligned.
  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestGetPartialObjectMisAligned ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  buffer  bytes . Buffer 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-03 14:54:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// data to be written into buffer.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									data  :=  "1234567890" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// seed the random number generator once.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									rand . Seed ( 3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// generate a random number between 13 and 200.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									randInt  :=  getRandomRange ( 13 ,  200 ,  - 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// write into buffer till length of the buffer is greater than the generated random number.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i  :=  0 ;  i  <=  randInt ;  i  +=  10  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										buffer . WriteString ( data ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-03 14:54:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// String content which is used for put object range test.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									putBytes  :=  buffer . Bytes ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									putBytes  =  putBytes [ : randInt ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// randomize the order of bytes in the byte array and create a reader.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									putBytes  =  randomizeBytes ( putBytes ,  - 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									buf  :=  bytes . NewReader ( putBytes ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									putContent  :=  string ( putBytes ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-big-file" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buf . Len ( ) ) ,  buf ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// test Cases containing data to make partial range requests.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// also has expected response data.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-03 01:15:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									testCases  :=  [ ] struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										byteRange       string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedString  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// request for byte range 10-11.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// expecting the result to contain only putContent[10:12] bytes.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ "10-11" ,  putContent [ 10 : 12 ] } , 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// request for object data after the first byte.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ "1-" ,  putContent [ 1 : ] } , 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// request for object data after the first byte.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ "6-" ,  putContent [ 6 : ] } , 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-04 09:43:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// request for last 2 bytes of the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ "-2" ,  putContent [ len ( putContent ) - 2 : ] } , 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// request for last 7 bytes of the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ "-7" ,  putContent [ len ( putContent ) - 7 : ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-03 14:54:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									for  _ ,  t  :=  range  testCases  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// HTTP request to download the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// Get partial content based on the byte range set.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 07:58:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										request . Header . Set ( "Range" ,  "bytes=" + t . byteRange ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( response . StatusCode ,  http . StatusPartialContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// parse the HTTP response body.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										getContent ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// Compare putContent and getContent.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										c . Assert ( string ( getContent ) ,  t . expectedString ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestGetPartialObjectLarge11MiB - Test validates partial content request for a 11MiB object.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestGetPartialObjectLarge11MiB ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  buffer  bytes . Buffer 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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 18:03:27 +08: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 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-large-11Mb-object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buf  :=  bytes . NewReader ( [ ] byte ( putContent ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buf . Len ( ) ) ,  buf ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request to download the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// This range spans into first two blocks.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 07:58:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Header . Set ( "Range" ,  "bytes=10485750-10485769" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusPartialContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// read the downloaded content from the response body.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getContent ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Compare putContent and getContent.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( string ( getContent ) ,  putContent [ 10485750 : 10485770 ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestGetPartialObjectLarge11MiB - Test validates partial content request for a 10MiB object.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestGetPartialObjectLarge10MiB ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expecting the error to be nil.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expecting the HTTP response status code to 200 OK.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  buffer  bytes . Buffer 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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 18:03:27 +08: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 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									putContent  :=  buffer . String ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buf  :=  bytes . NewReader ( [ ] byte ( putContent ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-big-10Mb-file" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buf . Len ( ) ) ,  buf ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-28 02:57:08 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// verify whether upload was successful.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request to download the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Get partial content based on the byte range set.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 07:58:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Header . Set ( "Range" ,  "bytes=2048-2058" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-04 09:43:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// execute the HTTP request to download the partial content.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusPartialContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// read the downloaded content from the response body.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 02:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getContent ,  err  :=  io . ReadAll ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Compare putContent and getContent.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( string ( getContent ) ,  putContent [ 2048 : 2059 ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-25 18:03:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestGetObjectErrors - Tests validate error response for invalid object operations.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestGetObjectErrors ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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"
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "NoSuchKey" ,  "The specified key does not exist." ,  http . StatusNotFound ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// request to download an object, but an invalid bucket name is set.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  "getobjecterrors-." ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expected to fail with "InvalidBucketName".
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "InvalidBucketName" ,  "The specified bucket is not valid." ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestGetObjectRangeErrors - Validate error response when object is fetched with incorrect byte range value.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestGetObjectRangeErrors ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "Hello World" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-28 02:57:08 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// verify whether upload was successful.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request to download the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getGetObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Invalid byte range set.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 07:58:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Header . Set ( "Range" ,  "bytes=-0" ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expected to fail with "InvalidRange" error message.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:06:30 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									verifyError ( c ,  response ,  "InvalidRange" ,  "The requested range is not satisfiable" ,  http . StatusRequestedRangeNotSatisfiable ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestObjectMultipartAbort - Test validates abortion of a multipart upload after uploading 2 parts.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestObjectMultipartAbort ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-multipart-object" 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-22 06:00:11 +08: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 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// construct HTTP request to initiate a NewMultipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPost ,  getNewMultipartURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request initiating the new multipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// parse the response body and obtain the new upload ID.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									decoder  :=  xml . NewDecoder ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-19 15:52:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									newResponse  :=  & InitiateMultipartUploadResponse { } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-22 06:00:11 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									err  =  decoder . Decode ( newResponse ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( len ( newResponse . UploadID )  >  0 ,  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-22 06:00:11 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// construct HTTP request to initiate a NewMultipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPost ,  getNewMultipartURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-22 06:00:11 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request initiating the new multipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-22 06:00:11 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// parse the response body and obtain the new upload ID.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									decoder  =  xml . NewDecoder ( response . Body ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									newResponse  =  & InitiateMultipartUploadResponse { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									err  =  decoder . Decode ( newResponse ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( len ( newResponse . UploadID )  >  0 ,  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// uploadID to be used for rest of the multipart operations on the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									uploadID  :=  newResponse . UploadID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for the part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "1" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the first part.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response1 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response1 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the second part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer2  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for the second part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "2" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer2 . Len ( ) ) ,  buffer2 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the second part.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response2 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response2 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for aborting the multipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodDelete ,  getAbortMultipartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to abort the multipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response3 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expecting the response status code to be http.StatusNoContent.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The assertion validates the success of Abort Multipart operation.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response3 . StatusCode ,  http . StatusNoContent ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestBucketMultipartList - Initiates a NewMultipart upload, uploads parts and validates listing of the parts.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestBucketMultipartList ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) ,  0 , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  200 ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-multipart-object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// construct HTTP request to initiate a NewMultipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPost ,  getNewMultipartURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request initiating the new multipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expecting the response status code to be http.StatusOK(200 OK) .
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// parse the response body and obtain the new upload ID.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									decoder  :=  xml . NewDecoder ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-19 15:52:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									newResponse  :=  & InitiateMultipartUploadResponse { } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									err  =  decoder . Decode ( newResponse ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( len ( newResponse . UploadID )  >  0 ,  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// uploadID to be used for rest of the multipart operations on the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									uploadID  :=  newResponse . UploadID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for the part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "1" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the first part.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response1 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response1 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the second part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer2  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for the second part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "2" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer2 . Len ( ) ) ,  buffer2 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the second part.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response2 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response2 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request to ListMultipart Uploads.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getListMultipartURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response3 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response3 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-21 16:06:07 +08: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.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-04 09:43:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// time.Time does not honor xml marshaller, it means that we need
 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-29 07:02:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// to encode/format it before giving it to xml marshaling.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-21 16:06:07 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// This below check adds client side verification to see if its
 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-04 09:43:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// truly parsable.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-21 16:06:07 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-20 14:44:43 +08: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 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// parse the response body.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									decoder  =  xml . NewDecoder ( response3 . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-20 14:44:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									newResponse3  :=  & listMultipartUploadsResponse { } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									err  =  decoder . Decode ( newResponse3 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Assert the bucket name in the response with the expected bucketName.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( newResponse3 . Bucket ,  bucketName ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Assert the bucket name in the response with the expected bucketName.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( newResponse3 . IsTruncated ,  false ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestValidateObjectMultipartUploadID - Test Initiates a new multipart upload and validates the uploadID.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestValidateObjectMultipartUploadID ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-27 06:57:46 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  200 ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-27 06:57:46 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "directory1/directory2/object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// construct HTTP request to initiate a NewMultipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPost ,  getNewMultipartURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request initiating the new multipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-27 06:57:46 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// parse the response body and obtain the new upload ID.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-27 06:57:46 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									decoder  :=  xml . NewDecoder ( response . Body ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									newResponse  :=  & InitiateMultipartUploadResponse { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									err  =  decoder . Decode ( newResponse ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expecting the decoding error to be nil.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Verifying for Upload ID value to be greater than 0.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( len ( newResponse . UploadID )  >  0 ,  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-27 06:57:46 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestObjectMultipartListError - Initiates a NewMultipart upload, uploads parts and validates
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// error response for an incorrect max-parts parameter .
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestObjectMultipartListError ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  200 ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-multipart-object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// construct HTTP request to initiate a NewMultipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPost ,  getNewMultipartURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request initiating the new multipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// parse the response body and obtain the new upload ID.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									decoder  :=  xml . NewDecoder ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-19 15:52:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									newResponse  :=  & InitiateMultipartUploadResponse { } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									err  =  decoder . Decode ( newResponse ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( len ( newResponse . UploadID )  >  0 ,  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// uploadID to be used for rest of the multipart operations on the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									uploadID  :=  newResponse . UploadID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for the part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "1" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the first part.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response1 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response1 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the second part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer2  :=  bytes . NewReader ( [ ] byte ( "hello world" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for the second part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "2" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer2 . Len ( ) ) ,  buffer2 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the second part.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response2 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response2 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to ListMultipart Uploads.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// max-keys is set to valid value of 1
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getListMultipartURLWithParams ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "1" ,  "" ,  "" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response3 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response3 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-13 02:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request to ListMultipart Uploads.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// max-keys is set to invalid value of -2.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodGet ,  getListMultipartURLWithParams ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "-2" ,  "" ,  "" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response4 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Since max-keys parameter in the ListMultipart request set to invalid value of -2,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// its expected to fail with error message "InvalidArgument".
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-28 22:27:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									verifyError ( c ,  response4 ,  "InvalidArgument" ,  "Part number must be an integer between 1 and 10000, inclusive" ,  http . StatusBadRequest ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08: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.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestObjectValidMD5 ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-12 07:13:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  200 ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-12 07:13:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Create a byte array of 5MB.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-23 10:18:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									data  :=  bytes . Repeat ( [ ] byte ( "0123456789abcdef" ) ,  5 * humanize . MiByte / 16 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-15 03:05:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// calculate etag of the data.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									etagBase64  :=  getMD5HashBase64 ( data ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-12 07:13:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( data ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-1-object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request for the object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// set the Content-Md5 to be the hash to content.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-15 03:05:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Header . Set ( "Content-Md5" ,  etagBase64 ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expecting a successful upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  =  "test-2-object" 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-12 07:13:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  =  bytes . NewReader ( data ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for the object to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPutObjectURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// set Content-Md5 to invalid value.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 16:04:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									request . Header . Set ( "Content-Md5" ,  "kvLTlMrX9NpYDQlEIFlnDA==" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// expecting a failure during upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Since Content-Md5 header was wrong, expecting to fail with "SignatureDoesNotMatch" error.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 03:10:18 +08: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 07:13:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// TestObjectMultipart - Initiates a NewMultipart upload, uploads 2 parts,
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// completes the multipart upload and validates the status of the operation.
  
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( s  * TestSuiteCommon )  TestObjectMultipart ( c  * check )  {  
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// generate a random bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bucketName  :=  getRandomBucketName ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to create the bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  :=  newTestSignedRequest ( http . MethodPut ,  getMakeBucketURL ( s . endPoint ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to create bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  200 ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									objectName  :=  "test-multipart-object" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// construct HTTP request to initiate a NewMultipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPost ,  getNewMultipartURL ( s . endPoint ,  bucketName ,  objectName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										0 ,  nil ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request initiating the new multipart upload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// expecting the response status code to be http.StatusOK(200 OK).
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// parse the response body and obtain the new upload ID.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									decoder  :=  xml . NewDecoder ( response . Body ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-19 15:52:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									newResponse  :=  & InitiateMultipartUploadResponse { } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									err  =  decoder . Decode ( newResponse ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( len ( newResponse . UploadID )  >  0 ,  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// uploadID to be used for rest of the multipart operations on the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									uploadID  :=  newResponse . UploadID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-09 14:49:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Create a byte array of 5MB.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-23 10:18:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									data  :=  bytes . Repeat ( [ ] byte ( "0123456789abcdef" ) ,  5 * humanize . MiByte / 16 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-15 03:05:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// calculate etag of the data.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-22 05:51:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									md5SumBase64  :=  getMD5HashBase64 ( data ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-06 12:05:56 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-05-09 14:49:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									buffer1  :=  bytes . NewReader ( data ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for the part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "1" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer1 . Len ( ) ) ,  buffer1 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-15 03:05:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// set the Content-Md5 header to the base64 encoding the etag of the content.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-22 05:51:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Header . Set ( "Content-Md5" ,  md5SumBase64 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the first part.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response1 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response1 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// content for the second part to be uploaded.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Create a byte array of 1 byte.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-09 14:49:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									data  =  [ ] byte ( "0" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-05-15 03:05:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// calculate etag of the data.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-22 05:51:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									md5SumBase64  =  getMD5HashBase64 ( data ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-09 14:49:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									buffer2  :=  bytes . NewReader ( data ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// HTTP request for the second part to be uploaded.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPut ,  getPartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ,  "2" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( buffer2 . Len ( ) ) ,  buffer2 ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-15 03:05:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// set the Content-Md5 header to the base64 encoding the etag of the content.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-22 05:51:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request . Header . Set ( "Content-Md5" ,  md5SumBase64 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// execute the HTTP request to upload the second part.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response2 ,  err  :=  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									c . Assert ( response2 . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-06 12:05:56 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Complete multipart upload
 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-14 16:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									completeUploads  :=  & CompleteMultipartUpload { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Parts :  [ ] CompletePart { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 03:40:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												PartNumber :  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ETag :        response1 . Header . Get ( "ETag" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												PartNumber :  2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ETag :        response2 . Header . Get ( "ETag" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									completeBytes ,  err  :=  xml . Marshal ( completeUploads ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-14 16:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Indicating that all parts are uploaded and initiating CompleteMultipartUpload.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									request ,  err  =  newTestSignedRequest ( http . MethodPost ,  getCompleteMultipartUploadURL ( s . endPoint ,  bucketName ,  objectName ,  uploadID ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 04:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int64 ( len ( completeBytes ) ) ,  bytes . NewReader ( completeBytes ) ,  s . accessKey ,  s . secretKey ,  s . signer ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 17:30:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Execute the complete multipart request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-09 02:28:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									response ,  err  =  s . client . Do ( request ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( err ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-28 02:57:08 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// verify whether complete multipart was successful.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-10 17:14:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( response . StatusCode ,  http . StatusOK ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-14 16:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  parts  [ ] CompletePart 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-10 23:41:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  part  :=  range  completeUploads . Parts  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-16 11:48:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										part . ETag  =  canonicalizeETag ( part . ETag ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-10 23:41:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										parts  =  append ( parts ,  part ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-09 09:35:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									etag  :=  getCompleteMultipartMD5 ( parts ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-03 13:34:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									c . Assert ( canonicalizeETag ( response . Header . Get ( xhttp . ETag ) ) ,  etag ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-20 21:18:47 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}