2021-04-19 03:41:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Copyright (c) 2015-2021 MinIO, Inc.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This file is part of MinIO Object Storage stack
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This program is free software: you can redistribute it and/or modify
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// it under the terms of the GNU Affero General Public License as published by
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// the Free Software Foundation, either version 3 of the License, or
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// (at your option) any later version.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This program is distributed in the hope that it will be useful
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// but WITHOUT ANY WARRANTY; without even the implied warranty of
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// GNU Affero General Public License for more details.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// You should have received a copy of the GNU Affero General Public License
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 07:23:42 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  cmd  
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"bytes" 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-16 04:27:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"context" 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"testing" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-13 11:04:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Wrapper for calling GetObjectInfo tests for both Erasure multiple disks and single node setup.
  
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								func  TestGetObjectInfo ( t  * testing . T )  {  
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ExecObjectLayerTest ( t ,  testGetObjectInfo ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// Testing GetObjectInfo().
  
						 
					
						
							
								
									
										
										
										
											2016-07-08 06:05:51 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								func  testGetObjectInfo ( obj  ObjectLayer ,  instanceType  string ,  t  TestErrHandler )  {  
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// This bucket is used for testing getObjectInfo operations.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-23 23:46:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  :=  obj . MakeBucket ( context . Background ( ) ,  "test-getobjectinfo" ,  MakeBucketOptions { } ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										t . Fatalf ( "%s : %s" ,  instanceType ,  err . Error ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 00:42:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									opts  :=  ObjectOptions { } 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-09 13:31:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									_ ,  err  =  obj . PutObject ( context . Background ( ) ,  "test-getobjectinfo" ,  "Asia/asiapics.jpg" ,  mustGetPutObjReader ( t ,  bytes . NewBufferString ( "asiapics" ) ,  int64 ( len ( "asiapics" ) ) ,  "" ,  "" ) ,  opts ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										t . Fatalf ( "%s : %s" ,  instanceType ,  err . Error ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 07:38:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Put an empty directory
 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-09 13:31:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									_ ,  err  =  obj . PutObject ( context . Background ( ) ,  "test-getobjectinfo" ,  "Asia/empty-dir/" ,  mustGetPutObjReader ( t ,  bytes . NewBufferString ( "" ) ,  int64 ( len ( "" ) ) ,  "" ,  "" ) ,  opts ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 07:38:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Fatalf ( "%s : %s" ,  instanceType ,  err . Error ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									resultCases  :=  [ ] ObjectInfo { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ObjectInfo -1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ObjectName set to a existing object in the test case (Test case 14).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ Bucket :  "test-getobjectinfo" ,  Name :  "Asia/asiapics.jpg" ,  ContentType :  "image/jpeg" ,  IsDir :  false } , 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 07:38:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ Bucket :  "test-getobjectinfo" ,  Name :  "Asia/empty-dir/" ,  ContentType :  "application/octet-stream" ,  IsDir :  true } , 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									testCases  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										bucketName  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										objectName  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Expected output of GetObjectInfo.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result  ObjectInfo 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										err     error 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Flag indicating whether the test is expected to pass or not.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										shouldPass  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test cases with invalid bucket names ( Test number 1-4 ).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ ".test" ,  "" ,  ObjectInfo { } ,  BucketNameInvalid { Bucket :  ".test" } ,  false } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ "---" ,  "" ,  ObjectInfo { } ,  BucketNameInvalid { Bucket :  "---" } ,  false } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ "ad" ,  "" ,  ObjectInfo { } ,  BucketNameInvalid { Bucket :  "ad" } ,  false } , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-09 13:38:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test cases with valid but non-existing bucket names (Test number 5-6).
 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ "abcdefgh" ,  "abc" ,  ObjectInfo { } ,  BucketNotFound { Bucket :  "abcdefgh" } ,  false } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ "ijklmnop" ,  "efg" ,  ObjectInfo { } ,  BucketNotFound { Bucket :  "ijklmnop" } ,  false } , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-09 13:38:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test cases with valid but non-existing bucket names and invalid object name (Test number 7-8).
 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-08 16:58:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ "test-getobjectinfo" ,  "" ,  ObjectInfo { } ,  ObjectNameInvalid { Bucket :  "test-getobjectinfo" ,  Object :  "" } ,  false } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ "test-getobjectinfo" ,  "" ,  ObjectInfo { } ,  ObjectNameInvalid { Bucket :  "test-getobjectinfo" ,  Object :  "" } ,  false } , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-09 13:38:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Test cases with non-existing object name with existing bucket (Test number 9-11).
 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ "test-getobjectinfo" ,  "Africa" ,  ObjectInfo { } ,  ObjectNotFound { Bucket :  "test-getobjectinfo" ,  Object :  "Africa" } ,  false } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ "test-getobjectinfo" ,  "Antartica" ,  ObjectInfo { } ,  ObjectNotFound { Bucket :  "test-getobjectinfo" ,  Object :  "Antartica" } ,  false } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ "test-getobjectinfo" ,  "Asia/myfile" ,  ObjectInfo { } ,  ObjectNotFound { Bucket :  "test-getobjectinfo" ,  Object :  "Asia/myfile" } ,  false } , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-17 08:20:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Valid case with existing object (Test number 12).
 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ "test-getobjectinfo" ,  "Asia/asiapics.jpg" ,  resultCases [ 0 ] ,  nil ,  true } , 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 07:38:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ "test-getobjectinfo" ,  "Asia/empty-dir/" ,  resultCases [ 1 ] ,  nil ,  true } , 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i ,  testCase  :=  range  testCases  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 00:42:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										result ,  err  :=  obj . GetObjectInfo ( context . Background ( ) ,  testCase . bucketName ,  testCase . objectName ,  opts ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  &&  testCase . shouldPass  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected to pass, but failed with: <ERROR> %s" ,  i + 1 ,  instanceType ,  err . Error ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  ==  nil  &&  ! testCase . shouldPass  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											t . Errorf ( "Test %d: %s: Expected to fail with <ERROR> \"%s\", but passed instead" ,  i + 1 ,  instanceType ,  testCase . err . Error ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Failed as expected, but does it fail for the expected reason.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  &&  ! testCase . shouldPass  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-30 05:24:10 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											if  testCase . err . Error ( )  !=  err . Error ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												t . Errorf ( "Test %d: %s: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead" ,  i + 1 ,  instanceType ,  testCase . err . Error ( ) ,  err . Error ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Test passes as expected, but the output values are verified for correctness here.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  ==  nil  &&  testCase . shouldPass  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  testCase . result . Bucket  !=  result . Bucket  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												t . Fatalf ( "Test %d: %s: Expected Bucket name to be '%s', but found '%s' instead" ,  i + 1 ,  instanceType ,  testCase . result . Bucket ,  result . Bucket ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  testCase . result . Name  !=  result . Name  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												t . Errorf ( "Test %d: %s: Expected Object name to be %s, but instead found it to be %s" ,  i + 1 ,  instanceType ,  testCase . result . Name ,  result . Name ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  testCase . result . ContentType  !=  result . ContentType  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 02:57:04 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												t . Errorf ( "Test %d: %s: Expected Content Type of the object to be %v, but instead found it to be %v" ,  i + 1 ,  instanceType ,  testCase . result . ContentType ,  result . ContentType ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  testCase . result . IsDir  !=  result . IsDir  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-07 03:32:44 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												t . Errorf ( "Test %d: %s: Expected IsDir flag of the object to be %v, but instead found it to be %v" ,  i + 1 ,  instanceType ,  testCase . result . IsDir ,  result . IsDir ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 14:40:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}