@ -246,6 +246,7 @@ func testPostPolicyBucketHandler(obj ObjectLayer, instanceType string, t TestErr
}
}
}
}
region := "us-east-1"
// Test cases for signature-V4.
// Test cases for signature-V4.
testCasesV4BadData := [ ] struct {
testCasesV4BadData := [ ] struct {
objectName string
objectName string
@ -330,7 +331,7 @@ func testPostPolicyBucketHandler(obj ObjectLayer, instanceType string, t TestErr
testCase . policy = fmt . Sprintf ( testCase . policy , testCase . dates ... )
testCase . policy = fmt . Sprintf ( testCase . policy , testCase . dates ... )
req , perr := newPostRequestV4Generic ( "" , bucketName , testCase . objectName , testCase . data , testCase . accessKey ,
req , perr := newPostRequestV4Generic ( "" , bucketName , testCase . objectName , testCase . data , testCase . accessKey ,
testCase . secretKey , curTime , [ ] byte ( testCase . policy ) , nil , testCase . corruptedBase64 , testCase . corruptedMultipart )
testCase . secretKey , region , curTime , [ ] byte ( testCase . policy ) , nil , testCase . corruptedBase64 , testCase . corruptedMultipart )
if perr != nil {
if perr != nil {
t . Fatalf ( "Test %d: %s: Failed to create HTTP request for PostPolicyHandler: <ERROR> %v" , i + 1 , instanceType , perr )
t . Fatalf ( "Test %d: %s: Failed to create HTTP request for PostPolicyHandler: <ERROR> %v" , i + 1 , instanceType , perr )
}
}
@ -473,9 +474,10 @@ func testPostPolicyBucketHandlerRedirect(obj ObjectLayer, instanceType string, t
// Generate the final policy document
// Generate the final policy document
policy = fmt . Sprintf ( policy , dates ... )
policy = fmt . Sprintf ( policy , dates ... )
region := "us-east-1"
// Create a new POST request with success_action_redirect field specified
// Create a new POST request with success_action_redirect field specified
req , perr := newPostRequestV4Generic ( "" , bucketName , keyName , [ ] byte ( "objData" ) ,
req , perr := newPostRequestV4Generic ( "" , bucketName , keyName , [ ] byte ( "objData" ) ,
credentials . AccessKey , credentials . SecretKey , curTime ,
credentials . AccessKey , credentials . SecretKey , region , curTime ,
[ ] byte ( policy ) , map [ string ] string { "success_action_redirect" : redirectURL . String ( ) } , false , false )
[ ] byte ( policy ) , map [ string ] string { "success_action_redirect" : redirectURL . String ( ) } , false , false )
if perr != nil {
if perr != nil {
@ -565,11 +567,11 @@ func newPostRequestV2(endPoint, bucketName, objectName string, accessKey, secret
return req , nil
return req , nil
}
}
func buildGenericPolicy ( t time . Time , accessKey , bucketName , objectName string , contentLengthRange bool ) [ ] byte {
func buildGenericPolicy ( t time . Time , accessKey , region , bucketName , objectName string , contentLengthRange bool ) [ ] byte {
// Expire the request five minutes from now.
// Expire the request five minutes from now.
expirationTime := t . Add ( time . Minute * 5 )
expirationTime := t . Add ( time . Minute * 5 )
credStr := getCredentialString ( accessKey , se rverConfig . GetR egion( ) , t )
credStr := getCredentialString ( accessKey , region , t )
// Create a new post policy.
// Create a new post policy.
policy := newPostPolicyBytesV4 ( credStr , bucketName , objectName , expirationTime )
policy := newPostPolicyBytesV4 ( credStr , bucketName , objectName , expirationTime )
if contentLengthRange {
if contentLengthRange {
@ -578,10 +580,10 @@ func buildGenericPolicy(t time.Time, accessKey, bucketName, objectName string, c
return policy
return policy
}
}
func newPostRequestV4Generic ( endPoint , bucketName , objectName string , objData [ ] byte , accessKey , secretKey string ,
func newPostRequestV4Generic ( endPoint , bucketName , objectName string , objData [ ] byte , accessKey , secretKey string , region string ,
t time . Time , policy [ ] byte , addFormData map [ string ] string , corruptedB64 bool , corruptedMultipart bool ) ( * http . Request , error ) {
t time . Time , policy [ ] byte , addFormData map [ string ] string , corruptedB64 bool , corruptedMultipart bool ) ( * http . Request , error ) {
// Get the user credential.
// Get the user credential.
credStr := getCredentialString ( accessKey , se rverConfig . GetR egion( ) , t )
credStr := getCredentialString ( accessKey , region , t )
// Only need the encoding.
// Only need the encoding.
encodedPolicy := base64 . StdEncoding . EncodeToString ( policy )
encodedPolicy := base64 . StdEncoding . EncodeToString ( policy )
@ -591,7 +593,7 @@ func newPostRequestV4Generic(endPoint, bucketName, objectName string, objData []
}
}
// Presign with V4 signature based on the policy.
// Presign with V4 signature based on the policy.
signature := postPresignSignatureV4 ( encodedPolicy , t , secretKey , se rverConfig . GetR egion( ) )
signature := postPresignSignatureV4 ( encodedPolicy , t , secretKey , region )
formData := map [ string ] string {
formData := map [ string ] string {
"bucket" : bucketName ,
"bucket" : bucketName ,
@ -645,12 +647,14 @@ func newPostRequestV4Generic(endPoint, bucketName, objectName string, objData []
func newPostRequestV4WithContentLength ( endPoint , bucketName , objectName string , objData [ ] byte , accessKey , secretKey string ) ( * http . Request , error ) {
func newPostRequestV4WithContentLength ( endPoint , bucketName , objectName string , objData [ ] byte , accessKey , secretKey string ) ( * http . Request , error ) {
t := UTCNow ( )
t := UTCNow ( )
policy := buildGenericPolicy ( t , accessKey , bucketName , objectName , true )
region := "us-east-1"
return newPostRequestV4Generic ( endPoint , bucketName , objectName , objData , accessKey , secretKey , t , policy , nil , false , false )
policy := buildGenericPolicy ( t , accessKey , region , bucketName , objectName , true )
return newPostRequestV4Generic ( endPoint , bucketName , objectName , objData , accessKey , secretKey , region , t , policy , nil , false , false )
}
}
func newPostRequestV4 ( endPoint , bucketName , objectName string , objData [ ] byte , accessKey , secretKey string ) ( * http . Request , error ) {
func newPostRequestV4 ( endPoint , bucketName , objectName string , objData [ ] byte , accessKey , secretKey string ) ( * http . Request , error ) {
t := UTCNow ( )
t := UTCNow ( )
policy := buildGenericPolicy ( t , accessKey , bucketName , objectName , false )
region := "us-east-1"
return newPostRequestV4Generic ( endPoint , bucketName , objectName , objData , accessKey , secretKey , t , policy , nil , false , false )
policy := buildGenericPolicy ( t , accessKey , region , bucketName , objectName , false )
return newPostRequestV4Generic ( endPoint , bucketName , objectName , objData , accessKey , secretKey , region , t , policy , nil , false , false )
}
}