2021-07-21 11:59:46 +00:00
package handler
import (
2022-11-09 14:25:02 +00:00
"bytes"
2021-07-21 11:59:46 +00:00
"encoding/hex"
2022-11-09 14:25:02 +00:00
"encoding/json"
2024-03-05 06:56:12 +00:00
"encoding/xml"
2021-07-21 11:59:46 +00:00
"net/http"
2023-06-30 09:03:55 +00:00
"net/http/httptest"
2021-07-21 11:59:46 +00:00
"testing"
2023-03-07 14:38:08 +00:00
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
2024-09-27 09:18:41 +00:00
apierr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
2023-07-05 14:05:45 +00:00
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
2023-03-07 14:38:08 +00:00
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
2023-12-08 07:44:13 +00:00
engineiam "git.frostfs.info/TrueCloudLab/policy-engine/iam"
2024-02-12 14:29:36 +00:00
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
2021-07-21 11:59:46 +00:00
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/stretchr/testify/require"
)
2024-03-19 13:56:32 +00:00
func TestPutObjectACLErrorAPE ( t * testing . T ) {
2024-02-12 14:29:36 +00:00
hc := prepareHandlerContext ( t )
bktName , objName := "bucket-for-acl-ape" , "object"
info := createBucket ( hc , bktName )
2024-09-27 09:18:41 +00:00
putObjectWithHeadersAssertS3Error ( hc , bktName , objName , map [ string ] string { api . AmzACL : basicACLPublic } , apierr . ErrAccessControlListNotSupported )
2024-03-19 13:56:32 +00:00
putObjectWithHeaders ( hc , bktName , objName , map [ string ] string { api . AmzACL : basicACLPrivate } ) // only `private` canned acl is allowed, that is actually ignored
putObjectWithHeaders ( hc , bktName , objName , nil )
2024-02-12 14:29:36 +00:00
2024-03-19 13:56:32 +00:00
aclBody := & AccessControlPolicy { }
2024-09-27 09:18:41 +00:00
putObjectACLAssertS3Error ( hc , bktName , objName , info . Box , nil , aclBody , apierr . ErrAccessControlListNotSupported )
2024-03-19 13:56:32 +00:00
aclRes := getObjectACL ( hc , bktName , objName )
checkPrivateACL ( t , aclRes , info . Key . PublicKey ( ) )
}
func TestCreateObjectACLErrorAPE ( t * testing . T ) {
hc := prepareHandlerContext ( t )
bktName , objName , objNameCopy := "bucket-for-acl-ape" , "object" , "copy"
createBucket ( hc , bktName )
putObject ( hc , bktName , objName )
copyObject ( hc , bktName , objName , objNameCopy , CopyMeta { Headers : map [ string ] string { api . AmzACL : basicACLPublic } } , http . StatusBadRequest )
copyObject ( hc , bktName , objName , objNameCopy , CopyMeta { Headers : map [ string ] string { api . AmzACL : basicACLPrivate } } , http . StatusOK )
2024-09-27 09:18:41 +00:00
createMultipartUploadAssertS3Error ( hc , bktName , objName , map [ string ] string { api . AmzACL : basicACLPublic } , apierr . ErrAccessControlListNotSupported )
2024-03-19 13:56:32 +00:00
createMultipartUpload ( hc , bktName , objName , map [ string ] string { api . AmzACL : basicACLPrivate } )
}
func TestBucketACLAPE ( t * testing . T ) {
2024-02-12 14:29:36 +00:00
hc := prepareHandlerContext ( t )
bktName := "bucket-for-acl-ape"
info := createBucket ( hc , bktName )
2024-03-19 13:56:32 +00:00
aclBody := & AccessControlPolicy { }
2024-09-27 09:18:41 +00:00
putBucketACLAssertS3Error ( hc , bktName , info . Box , nil , aclBody , apierr . ErrAccessControlListNotSupported )
2024-03-19 13:56:32 +00:00
2024-02-12 14:29:36 +00:00
aclRes := getBucketACL ( hc , bktName )
2024-03-19 13:56:32 +00:00
checkPrivateACL ( t , aclRes , info . Key . PublicKey ( ) )
2024-02-12 14:29:36 +00:00
putBucketACL ( hc , bktName , info . Box , map [ string ] string { api . AmzACL : basicACLPrivate } )
aclRes = getBucketACL ( hc , bktName )
2024-03-19 13:56:32 +00:00
checkPrivateACL ( t , aclRes , info . Key . PublicKey ( ) )
2024-02-12 14:29:36 +00:00
putBucketACL ( hc , bktName , info . Box , map [ string ] string { api . AmzACL : basicACLReadOnly } )
aclRes = getBucketACL ( hc , bktName )
2024-03-19 13:56:32 +00:00
checkPublicReadACL ( t , aclRes , info . Key . PublicKey ( ) )
2024-02-12 14:29:36 +00:00
putBucketACL ( hc , bktName , info . Box , map [ string ] string { api . AmzACL : basicACLPublic } )
aclRes = getBucketACL ( hc , bktName )
2024-03-19 13:56:32 +00:00
checkPublicReadWriteACL ( t , aclRes , info . Key . PublicKey ( ) )
2024-02-12 14:29:36 +00:00
}
2024-03-19 13:56:32 +00:00
func checkPrivateACL ( t * testing . T , aclRes * AccessControlPolicy , ownerKey * keys . PublicKey ) {
2024-06-18 08:20:08 +00:00
checkACLOwner ( t , aclRes , ownerKey )
2024-02-12 14:29:36 +00:00
}
2024-03-19 13:56:32 +00:00
func checkPublicReadACL ( t * testing . T , aclRes * AccessControlPolicy , ownerKey * keys . PublicKey ) {
2024-06-18 08:20:08 +00:00
checkACLOwner ( t , aclRes , ownerKey )
2024-02-12 14:29:36 +00:00
2024-06-18 08:20:08 +00:00
require . Equal ( t , allUsersGroup , aclRes . AccessControlList [ 0 ] . Grantee . URI )
require . Equal ( t , aclRead , aclRes . AccessControlList [ 0 ] . Permission )
2024-02-12 14:29:36 +00:00
}
2024-03-19 13:56:32 +00:00
func checkPublicReadWriteACL ( t * testing . T , aclRes * AccessControlPolicy , ownerKey * keys . PublicKey ) {
2024-06-18 08:20:08 +00:00
checkACLOwner ( t , aclRes , ownerKey )
2024-02-12 14:29:36 +00:00
2024-06-18 08:20:08 +00:00
require . Equal ( t , allUsersGroup , aclRes . AccessControlList [ 0 ] . Grantee . URI )
require . Equal ( t , aclWrite , aclRes . AccessControlList [ 0 ] . Permission )
2024-02-12 14:29:36 +00:00
2024-06-18 08:20:08 +00:00
require . Equal ( t , allUsersGroup , aclRes . AccessControlList [ 1 ] . Grantee . URI )
require . Equal ( t , aclRead , aclRes . AccessControlList [ 1 ] . Permission )
2024-02-12 14:29:36 +00:00
}
2024-06-18 08:20:08 +00:00
func checkACLOwner ( t * testing . T , aclRes * AccessControlPolicy , ownerKey * keys . PublicKey ) {
2024-02-12 14:29:36 +00:00
ownerIDStr := hex . EncodeToString ( ownerKey . Bytes ( ) )
ownerNameStr := ownerKey . Address ( )
require . Equal ( t , ownerIDStr , aclRes . Owner . ID )
require . Equal ( t , ownerNameStr , aclRes . Owner . DisplayName )
}
2022-11-09 14:25:02 +00:00
func TestBucketPolicy ( t * testing . T ) {
hc := prepareHandlerContext ( t )
bktName := "bucket-for-policy"
2023-12-08 07:44:13 +00:00
createTestBucket ( hc , bktName )
2022-11-09 14:25:02 +00:00
2024-09-27 09:18:41 +00:00
getBucketPolicy ( hc , bktName , apierr . ErrNoSuchBucketPolicy )
2022-11-09 14:25:02 +00:00
2023-12-08 07:44:13 +00:00
newPolicy := engineiam . Policy {
2024-04-01 09:51:05 +00:00
Version : "2012-10-17" ,
2023-12-08 07:44:13 +00:00
Statement : [ ] engineiam . Statement { {
Principal : map [ engineiam . PrincipalType ] [ ] string { engineiam . Wildcard : { } } ,
Effect : engineiam . DenyEffect ,
Action : engineiam . Action { "s3:PutObject" } ,
Resource : engineiam . Resource { "arn:aws:s3:::test/*" } ,
2022-11-09 14:25:02 +00:00
} } ,
}
2024-09-27 09:18:41 +00:00
putBucketPolicy ( hc , bktName , newPolicy , apierr . ErrMalformedPolicy )
2022-11-09 14:25:02 +00:00
2023-12-08 07:44:13 +00:00
newPolicy . Statement [ 0 ] . Resource [ 0 ] = arnAwsPrefix + bktName + "/*"
putBucketPolicy ( hc , bktName , newPolicy )
2022-11-09 14:25:02 +00:00
2023-12-08 07:44:13 +00:00
bktPolicy := getBucketPolicy ( hc , bktName )
require . Equal ( t , newPolicy , bktPolicy )
2022-11-09 14:25:02 +00:00
}
2024-03-05 06:56:12 +00:00
func TestBucketPolicyStatus ( t * testing . T ) {
hc := prepareHandlerContext ( t )
bktName := "bucket-for-policy"
createTestBucket ( hc , bktName )
2024-09-27 09:18:41 +00:00
getBucketPolicy ( hc , bktName , apierr . ErrNoSuchBucketPolicy )
2024-03-05 06:56:12 +00:00
newPolicy := engineiam . Policy {
2024-04-01 09:51:05 +00:00
Version : "2012-10-17" ,
2024-03-05 06:56:12 +00:00
Statement : [ ] engineiam . Statement { {
NotPrincipal : engineiam . Principal { engineiam . Wildcard : { } } ,
Effect : engineiam . AllowEffect ,
Action : engineiam . Action { "s3:PutObject" } ,
Resource : engineiam . Resource { arnAwsPrefix + bktName + "/*" } ,
} } ,
}
2024-09-27 09:18:41 +00:00
putBucketPolicy ( hc , bktName , newPolicy , apierr . ErrMalformedPolicyNotPrincipal )
2024-03-05 06:56:12 +00:00
newPolicy . Statement [ 0 ] . NotPrincipal = nil
newPolicy . Statement [ 0 ] . Principal = map [ engineiam . PrincipalType ] [ ] string { engineiam . Wildcard : { } }
putBucketPolicy ( hc , bktName , newPolicy )
bktPolicyStatus := getBucketPolicyStatus ( hc , bktName )
require . True ( t , PolicyStatusIsPublicTrue == bktPolicyStatus . IsPublic )
key , err := keys . NewPrivateKey ( )
require . NoError ( t , err )
hc . Handler ( ) . frostfsid . ( * frostfsidMock ) . data [ "devenv" ] = key . PublicKey ( )
newPolicy . Statement [ 0 ] . Principal = map [ engineiam . PrincipalType ] [ ] string { engineiam . AWSPrincipalType : { "arn:aws:iam:::user/devenv" } }
putBucketPolicy ( hc , bktName , newPolicy )
bktPolicyStatus = getBucketPolicyStatus ( hc , bktName )
require . True ( t , PolicyStatusIsPublicFalse == bktPolicyStatus . IsPublic )
}
2024-04-09 14:16:12 +00:00
func TestDeleteBucketWithPolicy ( t * testing . T ) {
hc := prepareHandlerContext ( t )
bktName := "bucket-for-policy"
2024-04-10 12:53:36 +00:00
bi := createTestBucket ( hc , bktName )
2024-04-09 14:16:12 +00:00
newPolicy := engineiam . Policy {
Version : "2012-10-17" ,
Statement : [ ] engineiam . Statement { {
Principal : map [ engineiam . PrincipalType ] [ ] string { engineiam . Wildcard : { } } ,
Effect : engineiam . AllowEffect ,
Action : engineiam . Action { "s3:PutObject" } ,
Resource : engineiam . Resource { "arn:aws:s3:::bucket-for-policy/*" } ,
} } ,
}
putBucketPolicy ( hc , bktName , newPolicy )
require . Len ( t , hc . h . ape . ( * apeMock ) . policyMap , 1 )
2024-04-10 12:53:36 +00:00
require . Len ( t , hc . h . ape . ( * apeMock ) . chainMap [ engine . ContainerTarget ( bi . CID . EncodeToString ( ) ) ] , 4 )
2024-04-09 14:16:12 +00:00
deleteBucket ( t , hc , bktName , http . StatusNoContent )
require . Empty ( t , hc . h . ape . ( * apeMock ) . policyMap )
2024-04-10 12:53:36 +00:00
chains , err := hc . h . ape . ( * apeMock ) . ListChains ( engine . ContainerTarget ( bi . CID . EncodeToString ( ) ) )
2024-04-09 14:16:12 +00:00
require . NoError ( t , err )
require . Empty ( t , chains )
}
2023-02-17 12:52:52 +00:00
func TestPutBucketPolicy ( t * testing . T ) {
bktPolicy := `
{
"Version" : "2012-10-17" ,
"Statement" : [ {
2023-12-08 07:44:13 +00:00
"Principal" : "*" ,
2023-02-17 12:52:52 +00:00
"Effect" : "Deny" ,
"Action" : "s3:GetObject" ,
"Resource" : "arn:aws:s3:::bucket-for-policy/*"
} ]
}
`
hc := prepareHandlerContext ( t )
bktName := "bucket-for-policy"
2023-12-08 07:44:13 +00:00
createTestBucket ( hc , bktName )
2023-02-17 12:52:52 +00:00
w , r := prepareTestPayloadRequest ( hc , bktName , "" , bytes . NewReader ( [ ] byte ( bktPolicy ) ) )
hc . Handler ( ) . PutBucketPolicyHandler ( w , r )
assertStatus ( hc . t , w , http . StatusOK )
}
2024-09-27 09:18:41 +00:00
func getBucketPolicy ( hc * handlerContext , bktName string , errCode ... apierr . ErrorCode ) engineiam . Policy {
2022-11-09 14:25:02 +00:00
w , r := prepareTestRequest ( hc , bktName , "" , nil )
hc . Handler ( ) . GetBucketPolicyHandler ( w , r )
2023-12-08 07:44:13 +00:00
var policy engineiam . Policy
if len ( errCode ) == 0 {
assertStatus ( hc . t , w , http . StatusOK )
err := json . NewDecoder ( w . Result ( ) . Body ) . Decode ( & policy )
require . NoError ( hc . t , err )
} else {
2024-09-27 09:18:41 +00:00
assertS3Error ( hc . t , w , apierr . GetAPIError ( errCode [ 0 ] ) )
2023-12-08 07:44:13 +00:00
}
2022-11-09 14:25:02 +00:00
return policy
}
2024-09-27 09:18:41 +00:00
func getBucketPolicyStatus ( hc * handlerContext , bktName string , errCode ... apierr . ErrorCode ) PolicyStatus {
2024-03-05 06:56:12 +00:00
w , r := prepareTestRequest ( hc , bktName , "" , nil )
hc . Handler ( ) . GetBucketPolicyStatusHandler ( w , r )
var policyStatus PolicyStatus
if len ( errCode ) == 0 {
assertStatus ( hc . t , w , http . StatusOK )
err := xml . NewDecoder ( w . Result ( ) . Body ) . Decode ( & policyStatus )
require . NoError ( hc . t , err )
} else {
2024-09-27 09:18:41 +00:00
assertS3Error ( hc . t , w , apierr . GetAPIError ( errCode [ 0 ] ) )
2024-03-05 06:56:12 +00:00
}
return policyStatus
}
2024-09-27 09:18:41 +00:00
func putBucketPolicy ( hc * handlerContext , bktName string , bktPolicy engineiam . Policy , errCode ... apierr . ErrorCode ) {
2022-11-09 14:25:02 +00:00
body , err := json . Marshal ( bktPolicy )
require . NoError ( hc . t , err )
w , r := prepareTestPayloadRequest ( hc , bktName , "" , bytes . NewReader ( body ) )
hc . Handler ( ) . PutBucketPolicyHandler ( w , r )
2023-12-08 07:44:13 +00:00
if len ( errCode ) == 0 {
assertStatus ( hc . t , w , http . StatusOK )
} else {
2024-09-27 09:18:41 +00:00
assertS3Error ( hc . t , w , apierr . GetAPIError ( errCode [ 0 ] ) )
2023-12-08 07:44:13 +00:00
}
2022-09-06 07:43:04 +00:00
}
2022-11-09 14:25:02 +00:00
func createAccessBox ( t * testing . T ) ( * accessbox . Box , * keys . PrivateKey ) {
2022-09-06 07:43:04 +00:00
key , err := keys . NewPrivateKey ( )
require . NoError ( t , err )
var bearerToken bearer . Token
err = bearerToken . Sign ( key . PrivateKey )
require . NoError ( t , err )
tok := new ( session . Container )
2024-05-28 12:50:34 +00:00
tok . ForVerb ( session . VerbContainerPut )
2023-06-30 09:03:55 +00:00
err = tok . Sign ( key . PrivateKey )
require . NoError ( t , err )
2022-09-06 07:43:04 +00:00
box := & accessbox . Box {
Gate : & accessbox . GateData {
2024-05-28 12:50:34 +00:00
SessionTokens : [ ] * session . Container { tok } ,
2022-09-06 07:43:04 +00:00
BearerToken : & bearerToken ,
} ,
}
2022-11-09 14:25:02 +00:00
return box , key
2022-09-06 07:43:04 +00:00
}
2024-02-12 14:29:36 +00:00
type createBucketInfo struct {
BktInfo * data . BucketInfo
Box * accessbox . Box
Key * keys . PrivateKey
}
func createBucket ( hc * handlerContext , bktName string ) * createBucketInfo {
box , key := createAccessBox ( hc . t )
2024-02-12 12:28:55 +00:00
2023-06-30 09:03:55 +00:00
w := createBucketBase ( hc , bktName , box )
2024-02-12 12:28:55 +00:00
assertStatus ( hc . t , w , http . StatusOK )
2022-09-06 07:43:04 +00:00
2023-06-30 09:03:55 +00:00
bktInfo , err := hc . Layer ( ) . GetBucketInfo ( hc . Context ( ) , bktName )
2024-02-12 12:28:55 +00:00
require . NoError ( hc . t , err )
2024-02-12 14:29:36 +00:00
return & createBucketInfo {
BktInfo : bktInfo ,
Box : box ,
Key : key ,
}
2024-02-12 12:28:55 +00:00
}
2024-09-27 09:18:41 +00:00
func createBucketAssertS3Error ( hc * handlerContext , bktName string , box * accessbox . Box , code apierr . ErrorCode ) {
2023-06-30 09:03:55 +00:00
w := createBucketBase ( hc , bktName , box )
2024-09-27 09:18:41 +00:00
assertS3Error ( hc . t , w , apierr . GetAPIError ( code ) )
2023-06-30 09:03:55 +00:00
}
func createBucketBase ( hc * handlerContext , bktName string , box * accessbox . Box ) * httptest . ResponseRecorder {
w , r := prepareTestRequest ( hc , bktName , "" , nil )
2024-04-16 08:20:35 +00:00
ctx := middleware . SetBox ( r . Context ( ) , & middleware . Box { AccessBox : box } )
2023-06-30 09:03:55 +00:00
r = r . WithContext ( ctx )
hc . Handler ( ) . CreateBucketHandler ( w , r )
return w
}
2024-02-12 14:29:36 +00:00
func putBucketACL ( hc * handlerContext , bktName string , box * accessbox . Box , header map [ string ] string ) {
w := putBucketACLBase ( hc , bktName , box , header , nil )
assertStatus ( hc . t , w , http . StatusOK )
}
2024-09-27 09:18:41 +00:00
func putBucketACLAssertS3Error ( hc * handlerContext , bktName string , box * accessbox . Box , header map [ string ] string , body * AccessControlPolicy , code apierr . ErrorCode ) {
2024-02-12 14:29:36 +00:00
w := putBucketACLBase ( hc , bktName , box , header , body )
2024-09-27 09:18:41 +00:00
assertS3Error ( hc . t , w , apierr . GetAPIError ( code ) )
2024-02-12 14:29:36 +00:00
}
func putBucketACLBase ( hc * handlerContext , bktName string , box * accessbox . Box , header map [ string ] string , body * AccessControlPolicy ) * httptest . ResponseRecorder {
w , r := prepareTestRequest ( hc , bktName , "" , body )
2022-09-06 07:43:04 +00:00
for key , val := range header {
r . Header . Set ( key , val )
}
2024-04-16 08:20:35 +00:00
ctx := middleware . SetBox ( r . Context ( ) , & middleware . Box { AccessBox : box } )
2022-09-06 07:43:04 +00:00
r = r . WithContext ( ctx )
2024-02-12 14:29:36 +00:00
hc . Handler ( ) . PutBucketACLHandler ( w , r )
return w
}
func getBucketACL ( hc * handlerContext , bktName string ) * AccessControlPolicy {
w := getBucketACLBase ( hc , bktName )
assertStatus ( hc . t , w , http . StatusOK )
res := & AccessControlPolicy { }
parseTestResponse ( hc . t , w , res )
return res
}
func getBucketACLBase ( hc * handlerContext , bktName string ) * httptest . ResponseRecorder {
w , r := prepareTestRequest ( hc , bktName , "" , nil )
hc . Handler ( ) . GetBucketACLHandler ( w , r )
return w
}
2024-09-27 09:18:41 +00:00
func putObjectACLAssertS3Error ( hc * handlerContext , bktName , objName string , box * accessbox . Box , header map [ string ] string , body * AccessControlPolicy , code apierr . ErrorCode ) {
2024-02-12 14:29:36 +00:00
w := putObjectACLBase ( hc , bktName , objName , box , header , body )
2024-09-27 09:18:41 +00:00
assertS3Error ( hc . t , w , apierr . GetAPIError ( code ) )
2024-02-12 14:29:36 +00:00
}
func putObjectACLBase ( hc * handlerContext , bktName , objName string , box * accessbox . Box , header map [ string ] string , body * AccessControlPolicy ) * httptest . ResponseRecorder {
w , r := prepareTestRequest ( hc , bktName , objName , body )
for key , val := range header {
r . Header . Set ( key , val )
}
2024-04-16 08:20:35 +00:00
ctx := middleware . SetBox ( r . Context ( ) , & middleware . Box { AccessBox : box } )
2024-02-12 14:29:36 +00:00
r = r . WithContext ( ctx )
hc . Handler ( ) . PutObjectACLHandler ( w , r )
return w
}
2024-03-19 13:56:32 +00:00
func getObjectACL ( hc * handlerContext , bktName , objName string ) * AccessControlPolicy {
2024-02-12 14:29:36 +00:00
w := getObjectACLBase ( hc , bktName , objName )
2024-03-19 13:56:32 +00:00
assertStatus ( hc . t , w , http . StatusOK )
res := & AccessControlPolicy { }
parseTestResponse ( hc . t , w , res )
return res
2024-02-12 14:29:36 +00:00
}
func getObjectACLBase ( hc * handlerContext , bktName , objName string ) * httptest . ResponseRecorder {
w , r := prepareTestRequest ( hc , bktName , objName , nil )
hc . Handler ( ) . GetObjectACLHandler ( w , r )
return w
2022-09-06 07:43:04 +00:00
}
2024-03-19 13:56:32 +00:00
func putObjectWithHeaders ( hc * handlerContext , bktName , objName string , headers map [ string ] string ) http . Header {
w := putObjectWithHeadersBase ( hc , bktName , objName , headers , nil , nil )
assertStatus ( hc . t , w , http . StatusOK )
return w . Header ( )
}
2024-09-27 09:18:41 +00:00
func putObjectWithHeadersAssertS3Error ( hc * handlerContext , bktName , objName string , headers map [ string ] string , code apierr . ErrorCode ) {
2024-03-19 13:56:32 +00:00
w := putObjectWithHeadersBase ( hc , bktName , objName , headers , nil , nil )
2024-09-27 09:18:41 +00:00
assertS3Error ( hc . t , w , apierr . GetAPIError ( code ) )
2024-03-19 13:56:32 +00:00
}
func putObjectWithHeadersBase ( hc * handlerContext , bktName , objName string , headers map [ string ] string , box * accessbox . Box , data [ ] byte ) * httptest . ResponseRecorder {
body := bytes . NewReader ( data )
w , r := prepareTestPayloadRequest ( hc , bktName , objName , body )
for k , v := range headers {
r . Header . Set ( k , v )
}
2024-04-16 08:20:35 +00:00
ctx := middleware . SetBox ( r . Context ( ) , & middleware . Box { AccessBox : box } )
2024-03-19 13:56:32 +00:00
r = r . WithContext ( ctx )
hc . Handler ( ) . PutObjectHandler ( w , r )
return w
}