2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/ *  
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  MinIO  Cloud  Storage ,  ( C )  2016 ,  2017 ,  2018  MinIO ,  Inc . 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Licensed  under  the  Apache  License ,  Version  2.0  ( the  "License" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  you  may  not  use  this  file  except  in  compliance  with  the  License . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  You  may  obtain  a  copy  of  the  License  at 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *      http : //www.apache.org/licenses/LICENSE-2.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Unless  required  by  applicable  law  or  agreed  to  in  writing ,  software 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  distributed  under  the  License  is  distributed  on  an  "AS IS"  BASIS , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  WITHOUT  WARRANTIES  OR  CONDITIONS  OF  ANY  KIND ,  either  express  or  implied . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  See  the  License  for  the  specific  language  governing  permissions  and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  limitations  under  the  License . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								package  cmd  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"bytes" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"encoding/xml" 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"fmt" 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"io/ioutil" 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"net/http" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"net/http/httptest" 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"strconv" 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"testing" 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-01 02:54:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/minio/minio/pkg/auth" 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Wrapper for calling RemoveBucket HTTP handler tests for both Erasure multiple disks and single node setup.
  
						 
					
						
							
								
									
										
										
										
											2020-03-28 12:52:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestRemoveBucketHandler ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExecObjectLayerAPITest ( t ,  testRemoveBucketHandler ,  [ ] string { "RemoveBucket" } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  testRemoveBucketHandler ( obj  ObjectLayer ,  instanceType ,  bucketName  string ,  apiRouter  http . Handler ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									credentials  auth . Credentials ,  t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-10 00:30:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									_ ,  err  :=  obj . PutObject ( GlobalContext ,  bucketName ,  "test-object" ,  mustGetPutObjReader ( t ,  bytes . NewBuffer ( [ ] byte { } ) ,  int64 ( 0 ) ,  "" ,  "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ) ,  ObjectOptions { } ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-28 12:52:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// if object upload fails stop the test.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Fatalf ( "Error uploading object: <ERROR> %v" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// initialize httptest Recorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									rec  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// construct HTTP request for DELETE bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									req ,  err  :=  newTestSignedRequestV4 ( http . MethodDelete ,  getBucketLocationURL ( "" ,  bucketName ) ,  0 ,  nil ,  credentials . AccessKey ,  credentials . SecretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-28 12:52:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Fatalf ( "Test %s: Failed to create HTTP request for RemoveBucketHandler: <ERROR> %v" ,  instanceType ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									apiRouter . ServeHTTP ( rec ,  req ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  rec . Code  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  http . StatusOK ,  http . StatusCreated ,  http . StatusAccepted ,  http . StatusNoContent : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Fatalf ( "Test %v: expected failure, but succeeded with %v" ,  instanceType ,  rec . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Verify response of the V2 signed HTTP request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// initialize HTTP NewRecorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									recV2  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// construct HTTP request for DELETE bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									reqV2 ,  err  :=  newTestSignedRequestV2 ( http . MethodDelete ,  getBucketLocationURL ( "" ,  bucketName ) ,  0 ,  nil ,  credentials . AccessKey ,  credentials . SecretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-28 12:52:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Fatalf ( "Test %s: Failed to create HTTP request for RemoveBucketHandler: <ERROR> %v" ,  instanceType ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									apiRouter . ServeHTTP ( recV2 ,  reqV2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  recV2 . Code  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  http . StatusOK ,  http . StatusCreated ,  http . StatusAccepted ,  http . StatusNoContent : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Fatalf ( "Test %v: expected failure, but succeeded with %v" ,  instanceType ,  recV2 . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Wrapper for calling GetBucketPolicy HTTP handler tests for both Erasure multiple disks and single node setup.
  
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								func  TestGetBucketLocationHandler ( t  * testing . T )  {  
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExecObjectLayerAPITest ( t ,  testGetBucketLocationHandler ,  [ ] string { "GetBucketLocation" } ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  testGetBucketLocationHandler ( obj  ObjectLayer ,  instanceType ,  bucketName  string ,  apiRouter  http . Handler ,  
						 
					
						
							
								
									
										
										
										
											2017-11-01 02:54:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									credentials  auth . Credentials ,  t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 05:28:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// test cases with sample input and expected output.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									testCases  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										bucketName  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										accessKey   string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										secretKey   string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// expected Response.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedRespStatus  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										locationResponse    [ ] byte 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										errorResponse       APIErrorResponse 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										shouldPass          bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test case - 1.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// Tests for authenticated request and proper response.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											bucketName :          bucketName , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											locationResponse :  [ ] byte ( ` < ? xml  version = "1.0"  encoding = "UTF-8" ? > 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< LocationConstraint  xmlns = "http://s3.amazonaws.com/doc/2006-03-01/" > < / LocationConstraint > ` ) ,  
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											errorResponse :  APIErrorResponse { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											shouldPass :     true , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test case - 2.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Tests for signature mismatch error.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											bucketName :          bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											accessKey :           "abcd" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           "abcd" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											locationResponse :    [ ] byte ( "" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											errorResponse :  APIErrorResponse { 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-07 03:08:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Resource :  SlashSeparator  +  bucketName  +  SlashSeparator , 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-24 11:07:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Code :      "InvalidAccessKeyId" , 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-22 00:09:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Message :   "The Access Key Id you provided does not exist in our records." , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											shouldPass :  false , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i ,  testCase  :=  range  testCases  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  i  !=  1  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// initialize httptest Recorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										rec  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// construct HTTP request for Get bucket location.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										req ,  err  :=  newTestSignedRequestV4 ( http . MethodGet ,  getBucketLocationURL ( "" ,  testCase . bucketName ) ,  0 ,  nil ,  testCase . accessKey ,  testCase . secretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Failed to create HTTP request for GetBucketLocationHandler: <ERROR> %v" ,  i + 1 ,  instanceType ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										apiRouter . ServeHTTP ( rec ,  req ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  rec . Code  !=  testCase . expectedRespStatus  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the response status to be `%d`, but instead found `%d`" ,  i + 1 ,  instanceType ,  testCase . expectedRespStatus ,  rec . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ! bytes . Equal ( testCase . locationResponse ,  rec . Body . Bytes ( ) )  &&  testCase . shouldPass  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:59:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the response to be `%s`, but instead found `%s`" ,  i + 1 ,  instanceType ,  string ( testCase . locationResponse ) ,  rec . Body . String ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										errorResponse  :=  APIErrorResponse { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										err  =  xml . Unmarshal ( rec . Body . Bytes ( ) ,  & errorResponse ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  &&  ! testCase . shouldPass  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:59:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Unable to marshal response body %s" ,  i + 1 ,  instanceType ,  rec . Body . String ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errorResponse . Resource  !=  testCase . errorResponse . Resource  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the error resource to be `%s`, but instead found `%s`" ,  i + 1 ,  instanceType ,  testCase . errorResponse . Resource ,  errorResponse . Resource ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errorResponse . Message  !=  testCase . errorResponse . Message  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the error message to be `%s`, but instead found `%s`" ,  i + 1 ,  instanceType ,  testCase . errorResponse . Message ,  errorResponse . Message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errorResponse . Code  !=  testCase . errorResponse . Code  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the error code to be `%s`, but instead found `%s`" ,  i + 1 ,  instanceType ,  testCase . errorResponse . Code ,  errorResponse . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Verify response of the V2 signed HTTP request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// initialize HTTP NewRecorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										recV2  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// construct HTTP request for PUT bucket policy endpoint.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										reqV2 ,  err  :=  newTestSignedRequestV2 ( http . MethodGet ,  getBucketLocationURL ( "" ,  testCase . bucketName ) ,  0 ,  nil ,  testCase . accessKey ,  testCase . secretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Failed to create HTTP request for PutBucketPolicyHandler: <ERROR> %v" ,  i + 1 ,  instanceType ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										apiRouter . ServeHTTP ( recV2 ,  reqV2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  recV2 . Code  !=  testCase . expectedRespStatus  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the response status to be `%d`, but instead found `%d`" ,  i + 1 ,  instanceType ,  testCase . expectedRespStatus ,  recV2 . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										errorResponse  =  APIErrorResponse { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										err  =  xml . Unmarshal ( recV2 . Body . Bytes ( ) ,  & errorResponse ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  &&  ! testCase . shouldPass  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:59:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Unable to marshal response body %s" ,  i + 1 ,  instanceType ,  recV2 . Body . String ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errorResponse . Resource  !=  testCase . errorResponse . Resource  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the error resource to be `%s`, but instead found `%s`" ,  i + 1 ,  instanceType ,  testCase . errorResponse . Resource ,  errorResponse . Resource ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errorResponse . Message  !=  testCase . errorResponse . Message  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the error message to be `%s`, but instead found `%s`" ,  i + 1 ,  instanceType ,  testCase . errorResponse . Message ,  errorResponse . Message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  errorResponse . Code  !=  testCase . errorResponse . Code  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the error code to be `%s`, but instead found `%s`" ,  i + 1 ,  instanceType ,  testCase . errorResponse . Code ,  errorResponse . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Test for Anonymous/unsigned http request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// ListBucketsHandler doesn't support bucket policies, setting the policies shouldn't make any difference.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									anonReq ,  err  :=  newTestRequest ( http . MethodGet ,  getBucketLocationURL ( "" ,  bucketName ) ,  0 ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t . Fatalf ( "MinIO %s: Failed to create an anonymous request." ,  instanceType ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// ExecObjectLayerAPIAnonTest - Calls the HTTP API handler using the anonymous request, validates the ErrAccessDeniedResponse,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// sets the bucket policy using the policy statement generated from `getReadOnlyBucketStatement` so that the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// unsigned request goes through and its validated again.
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-25 06:53:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExecObjectLayerAPIAnonTest ( t ,  obj ,  "TestGetBucketLocationHandler" ,  bucketName ,  "" ,  instanceType ,  apiRouter ,  anonReq ,  getAnonReadOnlyBucketPolicy ( bucketName ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request for testing when `objectLayer` is set to `nil`.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// There is no need to use an existing bucket and valid input for creating the request
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// since the `objectLayer==nil`  check is performed before any other checks inside the handlers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The only aim is to generate an HTTP request in a way that the relevant/registered end point is evoked/called.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nilBucket  :=  "dummy-bucket" 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nilReq ,  err  :=  newTestRequest ( http . MethodGet ,  getBucketLocationURL ( "" ,  nilBucket ) ,  0 ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t . Errorf ( "MinIO %s: Failed to create HTTP request for testing the response when object Layer is set to `nil`." ,  instanceType ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Executes the object layer set to `nil` test.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// `ExecObjectLayerAPINilTest` manages the operation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExecObjectLayerAPINilTest ( t ,  nilBucket ,  "" ,  instanceType ,  apiRouter ,  nilReq ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Wrapper for calling HeadBucket HTTP handler tests for both Erasure multiple disks and single node setup.
  
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								func  TestHeadBucketHandler ( t  * testing . T )  {  
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExecObjectLayerAPITest ( t ,  testHeadBucketHandler ,  [ ] string { "HeadBucket" } ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  testHeadBucketHandler ( obj  ObjectLayer ,  instanceType ,  bucketName  string ,  apiRouter  http . Handler ,  
						 
					
						
							
								
									
										
										
										
											2017-11-01 02:54:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									credentials  auth . Credentials ,  t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 05:28:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// test cases with sample input and expected output.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									testCases  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										bucketName  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										accessKey   string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										secretKey   string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// expected Response.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedRespStatus  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test case - 1.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// Bucket exists.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucketName :          bucketName , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test case - 2.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// Non-existent bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucketName :          "2333" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusNotFound , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test case - 3.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Testing for signature mismatch error.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// setting invalid acess and secret key.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucketName :          bucketName , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           "abcd" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           "abcd" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i ,  testCase  :=  range  testCases  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// initialize HTTP NewRecorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										rec  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// construct HTTP request for HEAD bucket.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										req ,  err  :=  newTestSignedRequestV4 ( http . MethodHead ,  getHEADBucketURL ( "" ,  testCase . bucketName ) ,  0 ,  nil ,  testCase . accessKey ,  testCase . secretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Failed to create HTTP request for HeadBucketHandler: <ERROR> %v" ,  i + 1 ,  instanceType ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										apiRouter . ServeHTTP ( rec ,  req ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  rec . Code  !=  testCase . expectedRespStatus  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the response status to be `%d`, but instead found `%d`" ,  i + 1 ,  instanceType ,  testCase . expectedRespStatus ,  rec . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Verify response the V2 signed HTTP request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// initialize HTTP NewRecorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										recV2  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// construct HTTP request for PUT bucket policy endpoint.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										reqV2 ,  err  :=  newTestSignedRequestV2 ( http . MethodHead ,  getHEADBucketURL ( "" ,  testCase . bucketName ) ,  0 ,  nil ,  testCase . accessKey ,  testCase . secretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Failed to create HTTP request for PutBucketPolicyHandler: <ERROR> %v" ,  i + 1 ,  instanceType ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										apiRouter . ServeHTTP ( recV2 ,  reqV2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  recV2 . Code  !=  testCase . expectedRespStatus  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the response status to be `%d`, but instead found `%d`" ,  i + 1 ,  instanceType ,  testCase . expectedRespStatus ,  recV2 . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Test for Anonymous/unsigned http request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									anonReq ,  err  :=  newTestRequest ( http . MethodHead ,  getHEADBucketURL ( "" ,  bucketName ) ,  0 ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t . Fatalf ( "MinIO %s: Failed to create an anonymous request for bucket \"%s\": <ERROR> %v" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											instanceType ,  bucketName ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// ExecObjectLayerAPIAnonTest - Calls the HTTP API handler using the anonymous request, validates the ErrAccessDeniedResponse,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// sets the bucket policy using the policy statement generated from `getReadOnlyBucketStatement` so that the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// unsigned request goes through and its validated again.
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-25 06:53:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExecObjectLayerAPIAnonTest ( t ,  obj ,  "TestHeadBucketHandler" ,  bucketName ,  "" ,  instanceType ,  apiRouter ,  anonReq ,  getAnonReadOnlyBucketPolicy ( bucketName ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request for testing when `objectLayer` is set to `nil`.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// There is no need to use an existing bucket and valid input for creating the request
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// since the `objectLayer==nil`  check is performed before any other checks inside the handlers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The only aim is to generate an HTTP request in a way that the relevant/registered end point is evoked/called.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nilBucket  :=  "dummy-bucket" 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nilReq ,  err  :=  newTestRequest ( http . MethodHead ,  getHEADBucketURL ( "" ,  nilBucket ) ,  0 ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t . Errorf ( "MinIO %s: Failed to create HTTP request for testing the response when object Layer is set to `nil`." ,  instanceType ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the object layer set to `nil` test.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// `ExecObjectLayerAPINilTest` manages the operation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExecObjectLayerAPINilTest ( t ,  nilBucket ,  "" ,  instanceType ,  apiRouter ,  nilReq ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-10 01:18:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Wrapper for calling TestListMultipartUploadsHandler tests for both Erasure multiple disks and single node setup.
  
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestListMultipartUploadsHandler ( t  * testing . T )  {  
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExecObjectLayerAPITest ( t ,  testListMultipartUploadsHandler ,  [ ] string { "ListMultipartUploads" } ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// testListMultipartUploadsHandler - Tests validate listing of multipart uploads.
  
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  testListMultipartUploadsHandler ( obj  ObjectLayer ,  instanceType ,  bucketName  string ,  apiRouter  http . Handler ,  
						 
					
						
							
								
									
										
										
										
											2017-11-01 02:54:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									credentials  auth . Credentials ,  t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 05:28:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Collection of non-exhaustive ListMultipartUploads test cases, valid errors
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// and success responses.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									testCases  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Inputs to ListMultipartUploads.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										bucket              string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										prefix              string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										keyMarker           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										uploadIDMarker      string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										delimiter           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										maxUploads          string 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										accessKey           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										secretKey           string 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										expectedRespStatus  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										shouldPass          bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test case - 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Setting invalid bucket name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              ".test" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											prefix :              "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyMarker :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uploadIDMarker :      "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											delimiter :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											maxUploads :          "0" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-24 11:27:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusNotFound , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											shouldPass :          false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 2.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Setting a non-existent bucket.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              "volatile-bucket-1" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											prefix :              "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyMarker :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uploadIDMarker :      "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											delimiter :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											maxUploads :          "0" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusNotFound , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											shouldPass :          false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case -3.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-20 09:42:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Delimiter unsupported, but response is empty.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											prefix :              "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyMarker :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uploadIDMarker :      "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											delimiter :           "-" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											maxUploads :          "0" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-20 09:42:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											shouldPass :          true , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 4.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Setting Invalid prefix and marker combination.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											prefix :              "asia" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyMarker :           "europe-object" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uploadIDMarker :      "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											delimiter :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											maxUploads :          "0" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusNotImplemented , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											shouldPass :          false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 5.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Invalid upload id and marker combination.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											prefix :              "asia" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyMarker :           "asia/europe/" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uploadIDMarker :      "abc" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											delimiter :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											maxUploads :          "0" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusNotImplemented , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											shouldPass :          false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 6.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Setting a negative value to max-uploads paramater, should result in http.StatusBadRequest.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											prefix :              "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyMarker :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uploadIDMarker :      "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											delimiter :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											maxUploads :          "-1" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusBadRequest , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											shouldPass :          false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 7.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Case with right set of parameters,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// should result in success 200OK.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											prefix :              "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyMarker :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uploadIDMarker :      "" , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-07 03:08:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											delimiter :           SlashSeparator , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											maxUploads :          "100" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											shouldPass :          true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 8.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Good case without delimiter.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											prefix :              "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyMarker :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uploadIDMarker :      "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											delimiter :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											maxUploads :          "100" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											shouldPass :          true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 9.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Setting Invalid AccessKey and SecretKey to induce and verify Signature Mismatch error.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											prefix :              "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyMarker :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uploadIDMarker :      "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											delimiter :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											maxUploads :          "100" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											accessKey :           "abcd" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           "abcd" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											shouldPass :          true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i ,  testCase  :=  range  testCases  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// initialize HTTP NewRecorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										rec  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// construct HTTP request for List multipart uploads endpoint.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										u  :=  getListMultipartUploadsURLWithParams ( "" ,  testCase . bucket ,  testCase . prefix ,  testCase . keyMarker ,  testCase . uploadIDMarker ,  testCase . delimiter ,  testCase . maxUploads ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										req ,  gerr  :=  newTestSignedRequestV4 ( http . MethodGet ,  u ,  0 ,  nil ,  testCase . accessKey ,  testCase . secretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  gerr  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Failed to create HTTP request for ListMultipartUploadsHandler: <ERROR> %v" ,  i + 1 ,  instanceType ,  gerr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										apiRouter . ServeHTTP ( rec ,  req ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  rec . Code  !=  testCase . expectedRespStatus  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the response status to be `%d`, but instead found `%d`" ,  i + 1 ,  instanceType ,  testCase . expectedRespStatus ,  rec . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Verify response the V2 signed HTTP request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// initialize HTTP NewRecorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										recV2  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// construct HTTP request for PUT bucket policy endpoint.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// verify response for V2 signed HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										reqV2 ,  err  :=  newTestSignedRequestV2 ( http . MethodGet ,  u ,  0 ,  nil ,  testCase . accessKey ,  testCase . secretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Failed to create HTTP request for PutBucketPolicyHandler: <ERROR> %v" ,  i + 1 ,  instanceType ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										apiRouter . ServeHTTP ( recV2 ,  reqV2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  recV2 . Code  !=  testCase . expectedRespStatus  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the response status to be `%d`, but instead found `%d`" ,  i + 1 ,  instanceType ,  testCase . expectedRespStatus ,  recV2 . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// initialize HTTP NewRecorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									rec  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// construct HTTP request for List multipart uploads endpoint.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									u  :=  getListMultipartUploadsURLWithParams ( "" ,  bucketName ,  "" ,  "" ,  "" ,  "" ,  "" ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									req ,  err  :=  newTestSignedRequestV4 ( http . MethodGet ,  u ,  0 ,  nil ,  "" ,  "" ,  nil )  // Generate an anonymous request.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Fatalf ( "Test %s: Failed to create HTTP request for ListMultipartUploadsHandler: <ERROR> %v" ,  instanceType ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									apiRouter . ServeHTTP ( rec ,  req ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  rec . Code  !=  http . StatusForbidden  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Errorf ( "Test %s: Expected the response status to be `http.StatusForbidden`, but instead found `%d`" ,  instanceType ,  rec . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									url  :=  getListMultipartUploadsURLWithParams ( "" ,  testCases [ 6 ] . bucket ,  testCases [ 6 ] . prefix ,  testCases [ 6 ] . keyMarker , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										testCases [ 6 ] . uploadIDMarker ,  testCases [ 6 ] . delimiter ,  testCases [ 6 ] . maxUploads ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Test for Anonymous/unsigned http request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									anonReq ,  err  :=  newTestRequest ( http . MethodGet ,  url ,  0 ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t . Fatalf ( "MinIO %s: Failed to create an anonymous request for bucket \"%s\": <ERROR> %v" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											instanceType ,  bucketName ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// ExecObjectLayerAPIAnonTest - Calls the HTTP API handler using the anonymous request, validates the ErrAccessDeniedResponse,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// sets the bucket policy using the policy statement generated from `getWriteOnlyBucketStatement` so that the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// unsigned request goes through and its validated again.
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-25 06:53:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExecObjectLayerAPIAnonTest ( t ,  obj ,  "TestListMultipartUploadsHandler" ,  bucketName ,  "" ,  instanceType ,  apiRouter ,  anonReq ,  getAnonWriteOnlyBucketPolicy ( bucketName ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// HTTP request for testing when `objectLayer` is set to `nil`.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// There is no need to use an existing bucket and valid input for creating the request
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// since the `objectLayer==nil`  check is performed before any other checks inside the handlers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The only aim is to generate an HTTP request in a way that the relevant/registered end point is evoked/called.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nilBucket  :=  "dummy-bucket" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									url  =  getListMultipartUploadsURLWithParams ( "" ,  nilBucket ,  "dummy-prefix" ,  testCases [ 6 ] . keyMarker , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										testCases [ 6 ] . uploadIDMarker ,  testCases [ 6 ] . delimiter ,  testCases [ 6 ] . maxUploads ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nilReq ,  err  :=  newTestRequest ( http . MethodGet ,  url ,  0 ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t . Errorf ( "MinIO %s: Failed to create HTTP request for testing the response when object Layer is set to `nil`." ,  instanceType ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the object layer set to `nil` test.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// `ExecObjectLayerAPINilTest` manages the operation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExecObjectLayerAPINilTest ( t ,  nilBucket ,  "" ,  instanceType ,  apiRouter ,  nilReq ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-14 10:00:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Wrapper for calling TestListBucketsHandler tests for both Erasure multiple disks and single node setup.
  
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestListBucketsHandler ( t  * testing . T )  {  
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExecObjectLayerAPITest ( t ,  testListBucketsHandler ,  [ ] string { "ListBuckets" } ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// testListBucketsHandler - Tests validate listing of buckets.
  
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  testListBucketsHandler ( obj  ObjectLayer ,  instanceType ,  bucketName  string ,  apiRouter  http . Handler ,  
						 
					
						
							
								
									
										
										
										
											2017-11-01 02:54:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									credentials  auth . Credentials ,  t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									testCases  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										bucketName          string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										accessKey           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										secretKey           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedRespStatus  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test case - 1.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Validate a good case request succeeds.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucketName :          bucketName , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test case - 2.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case with invalid accessKey to produce and validate Signature MisMatch error.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucketName :          bucketName , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           "abcd" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           "abcd" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i ,  testCase  :=  range  testCases  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// initialize HTTP NewRecorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										rec  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										req ,  lerr  :=  newTestSignedRequestV4 ( http . MethodGet ,  getListBucketURL ( "" ) ,  0 ,  nil ,  testCase . accessKey ,  testCase . secretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  lerr  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Failed to create HTTP request for ListBucketsHandler: <ERROR> %v" ,  i + 1 ,  instanceType ,  lerr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										apiRouter . ServeHTTP ( rec ,  req ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  rec . Code  !=  testCase . expectedRespStatus  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the response status to be `%d`, but instead found `%d`" ,  i + 1 ,  instanceType ,  testCase . expectedRespStatus ,  rec . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Verify response of the V2 signed HTTP request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// initialize HTTP NewRecorder, this records any mutations to response writer inside the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										recV2  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// construct HTTP request for PUT bucket policy endpoint.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// verify response for V2 signed HTTP request.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										reqV2 ,  err  :=  newTestSignedRequestV2 ( http . MethodGet ,  getListBucketURL ( "" ) ,  0 ,  nil ,  testCase . accessKey ,  testCase . secretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 00:25:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d: %s: Failed to create HTTP request for PutBucketPolicyHandler: <ERROR> %v" ,  i + 1 ,  instanceType ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Call the ServeHTTP to execute the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										apiRouter . ServeHTTP ( recV2 ,  reqV2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  recV2 . Code  !=  testCase . expectedRespStatus  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected the response status to be `%d`, but instead found `%d`" ,  i + 1 ,  instanceType ,  testCase . expectedRespStatus ,  recV2 . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Test for Anonymous/unsigned http request.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// ListBucketsHandler doesn't support bucket policies, setting the policies shouldn't make a difference.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									anonReq ,  err  :=  newTestRequest ( http . MethodGet ,  getListBucketURL ( "" ) ,  0 ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t . Fatalf ( "MinIO %s: Failed to create an anonymous request." ,  instanceType ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 00:21:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// ExecObjectLayerAPIAnonTest - Calls the HTTP API handler using the anonymous request, validates the ErrAccessDeniedResponse,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// sets the bucket policy using the policy statement generated from `getWriteOnlyObjectStatement` so that the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// unsigned request goes through and its validated again.
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-25 06:53:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExecObjectLayerAPIAnonTest ( t ,  obj ,  "ListBucketsHandler" ,  "" ,  "" ,  instanceType ,  apiRouter ,  anonReq ,  getAnonWriteOnlyBucketPolicy ( "*" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request for testing when `objectLayer` is set to `nil`.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// There is no need to use an existing bucket and valid input for creating the request
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// since the `objectLayer==nil`  check is performed before any other checks inside the handlers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The only aim is to generate an HTTP request in a way that the relevant/registered end point is evoked/called.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nilReq ,  err  :=  newTestRequest ( http . MethodGet ,  getListBucketURL ( "" ) ,  0 ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t . Errorf ( "MinIO %s: Failed to create HTTP request for testing the response when object Layer is set to `nil`." ,  instanceType ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-11 15:00:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the object layer set to `nil` test.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// `ExecObjectLayerAPINilTest` manages the operation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExecObjectLayerAPINilTest ( t ,  "" ,  "" ,  instanceType ,  apiRouter ,  nilReq ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 14:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Wrapper for calling DeleteMultipleObjects HTTP handler tests for both Erasure multiple disks and single node setup.
  
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestAPIDeleteMultipleObjectsHandler ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExecObjectLayerAPITest ( t ,  testAPIDeleteMultipleObjectsHandler ,  [ ] string { "DeleteMultipleObjects" } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  testAPIDeleteMultipleObjectsHandler ( obj  ObjectLayer ,  instanceType ,  bucketName  string ,  apiRouter  http . Handler ,  
						 
					
						
							
								
									
										
										
										
											2017-11-01 02:54:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									credentials  auth . Credentials ,  t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  err  error 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									contentBytes  :=  [ ] byte ( "hello" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									sha256sum  :=  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  objectNames  [ ] string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i  :=  0 ;  i  <  10 ;  i ++  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										objectName  :=  "test-object-"  +  strconv . Itoa ( i ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// uploading the object.
 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-10 00:30:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										_ ,  err  =  obj . PutObject ( GlobalContext ,  bucketName ,  objectName ,  mustGetPutObjReader ( t ,  bytes . NewBuffer ( contentBytes ) ,  int64 ( len ( contentBytes ) ) ,  "" ,  sha256sum ) ,  ObjectOptions { } ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// if object upload fails stop the test.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Fatalf ( "Put Object %d:  Error uploading object: <ERROR> %v" ,  i ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// object used for the test.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										objectNames  =  append ( objectNames ,  objectName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getObjectToDeleteList  :=  func ( objectNames  [ ] string )  ( objectList  [ ] ObjectToDelete )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  objectName  :=  range  objectNames  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											objectList  =  append ( objectList ,  ObjectToDelete { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ObjectName :  objectName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  objectList 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									getDeleteErrorList  :=  func ( objects  [ ] ObjectToDelete )  ( deleteErrorList  [ ] DeleteError )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 03:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  obj  :=  range  objects  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											deleteErrorList  =  append ( deleteErrorList ,  DeleteError { 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-12 17:25:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Code :     errorCodes [ ErrAccessDenied ] . Code , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Message :  errorCodes [ ErrAccessDenied ] . Description , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 03:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Key :      obj . ObjectName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  deleteErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									requestList  :=  [ ] DeleteObjectsRequest { 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ Quiet :  false ,  Objects :  getObjectToDeleteList ( objectNames [ : 5 ] ) } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ Quiet :  true ,  Objects :  getObjectToDeleteList ( objectNames [ 5 : ] ) } , 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// generate multi objects delete response.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									successRequest0  :=  encodeResponse ( requestList [ 0 ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									deletedObjects  :=  make ( [ ] DeletedObject ,  len ( requestList [ 0 ] . Objects ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i  :=  range  requestList [ 0 ] . Objects  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										deletedObjects [ i ]  =  DeletedObject { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ObjectName :  requestList [ 0 ] . Objects [ i ] . ObjectName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									successResponse0  :=  generateMultiDeleteResponse ( requestList [ 0 ] . Quiet ,  deletedObjects ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									encodedSuccessResponse0  :=  encodeResponse ( successResponse0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									successRequest1  :=  encodeResponse ( requestList [ 1 ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									deletedObjects  =  make ( [ ] DeletedObject ,  len ( requestList [ 1 ] . Objects ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i  :=  range  requestList [ 0 ] . Objects  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										deletedObjects [ i ]  =  DeletedObject { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ObjectName :  requestList [ 1 ] . Objects [ i ] . ObjectName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									successResponse1  :=  generateMultiDeleteResponse ( requestList [ 1 ] . Quiet ,  deletedObjects ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									encodedSuccessResponse1  :=  encodeResponse ( successResponse1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// generate multi objects delete response for errors.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// errorRequest := encodeResponse(requestList[1])
 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									errorResponse  :=  generateMultiDeleteResponse ( requestList [ 1 ] . Quiet ,  deletedObjects ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									encodedErrorResponse  :=  encodeResponse ( errorResponse ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 03:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									anonRequest  :=  encodeResponse ( requestList [ 0 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									anonResponse  :=  generateMultiDeleteResponse ( requestList [ 0 ] . Quiet ,  nil ,  getDeleteErrorList ( requestList [ 0 ] . Objects ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									encodedAnonResponse  :=  encodeResponse ( anonResponse ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									testCases  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										bucket              string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										objects             [ ] byte 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										accessKey           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										secretKey           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedContent     [ ] byte 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedRespStatus  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Delete objects with invalid access key.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											objects :             successRequest0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											accessKey :           "Invalid-AccessID" , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedContent :     nil , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 2.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Delete valid objects with quiet flag off.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											objects :             successRequest0 , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedContent :     encodedSuccessResponse0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 3.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Delete valid objects with quiet flag on.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											objects :             successRequest1 , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedContent :     encodedSuccessResponse1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test case - 4.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Delete previously deleted objects.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											objects :             successRequest1 , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-27 02:21:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											accessKey :           credentials . AccessKey , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           credentials . SecretKey , 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedContent :     encodedErrorResponse , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 03:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test case - 5.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Anonymous user access denied response
 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Currently anonymous users cannot delete multiple objects in MinIO server
 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 03:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bucket :              bucketName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											objects :             anonRequest , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											accessKey :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											secretKey :           "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedContent :     encodedAnonResponse , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedRespStatus :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i ,  testCase  :=  range  testCases  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  req  * http . Request 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  actualContent  [ ] byte 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 03:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Generate a signed or anonymous request based on the testCase
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  testCase . accessKey  !=  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											req ,  err  =  newTestSignedRequestV4 ( http . MethodPost ,  getDeleteMultipleObjectsURL ( "" ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-21 10:22:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												int64 ( len ( testCase . objects ) ) ,  bytes . NewReader ( testCase . objects ) ,  testCase . accessKey ,  testCase . secretKey ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 03:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											req ,  err  =  newTestRequest ( http . MethodPost ,  getDeleteMultipleObjectsURL ( "" ,  bucketName ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 03:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												int64 ( len ( testCase . objects ) ) ,  bytes . NewReader ( testCase . objects ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											t . Fatalf ( "Failed to create HTTP request for DeleteMultipleObjects: <ERROR> %v" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										rec  :=  httptest . NewRecorder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Call the ServeHTTP to executes the registered handler.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										apiRouter . ServeHTTP ( rec ,  req ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Assert the response code with the expected status.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  rec . Code  !=  testCase . expectedRespStatus  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-14 03:25:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: MinIO %s: Expected the response status to be `%d`, but instead found `%d`" ,  i + 1 ,  instanceType ,  testCase . expectedRespStatus ,  rec . Code ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// read the response body.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										actualContent ,  err  =  ioutil . ReadAll ( rec . Body ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t . Fatalf ( "Test %d : MinIO %s: Failed parsing response body: <ERROR> %v" ,  i + 1 ,  instanceType ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Verify whether the bucket obtained object is same as the one created.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  testCase . expectedContent  !=  nil  &&  ! bytes . Equal ( testCase . expectedContent ,  actualContent )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											fmt . Println ( string ( testCase . expectedContent ) ,  string ( actualContent ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t . Errorf ( "Test %d : MinIO %s: Object content differs from expected value." ,  i + 1 ,  instanceType ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// HTTP request to test the case of `objectLayer` being set to `nil`.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// There is no need to use an existing bucket or valid input for creating the request,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// since the `objectLayer==nil`  check is performed before any other checks inside the handlers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The only aim is to generate an HTTP request in a way that the relevant/registered end point is evoked/called.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Indicating that all parts are uploaded and initiating completeMultipartUpload.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nilBucket  :=  "dummy-bucket" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nilObject  :=  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 03:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nilReq ,  err  :=  newTestSignedRequestV4 ( http . MethodPost ,  getDeleteMultipleObjectsURL ( "" ,  nilBucket ) ,  0 ,  nil ,  "" ,  "" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-10 02:39:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t . Errorf ( "MinIO %s: Failed to create HTTP request for testing the response when object Layer is set to `nil`." ,  instanceType ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-17 01:46:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// execute the object layer set to `nil` test.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// `ExecObjectLayerAPINilTest` manages the operation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExecObjectLayerAPINilTest ( t ,  nilBucket ,  nilObject ,  instanceType ,  apiRouter ,  nilReq ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}