split ExtAcpKey to ExtAmzOwnerKey and ExtAmzAclKey to avoid unn… (#3824)
split `ExtAcpKey` to `ExtAmzOwnerKey` and `ExtAmzAclKey` to avoid unnecessary `json.Unmarshal()` call Signed-off-by: changlin.shi <changlin.shi@ly.com> Signed-off-by: changlin.shi <changlin.shi@ly.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package s3api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/json/jsonutil"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
||||
@@ -26,18 +26,13 @@ var (
|
||||
}
|
||||
|
||||
//good entry
|
||||
goodEntryAcp, _ = jsonutil.BuildJSON(&s3.AccessControlPolicy{
|
||||
Owner: &s3.Owner{
|
||||
DisplayName: &s3account.AccountAdmin.Name,
|
||||
ID: &s3account.AccountAdmin.Id,
|
||||
},
|
||||
Grants: s3_constants.PublicRead,
|
||||
})
|
||||
goodEntry = &filer_pb.Entry{
|
||||
goodEntryAcl, _ = json.Marshal(s3_constants.PublicRead)
|
||||
goodEntry = &filer_pb.Entry{
|
||||
Name: "entryWithValidAcp",
|
||||
Extended: map[string][]byte{
|
||||
s3_constants.ExtOwnershipKey: []byte(s3_constants.OwnershipBucketOwnerEnforced),
|
||||
s3_constants.ExtAcpKey: goodEntryAcp,
|
||||
s3_constants.ExtAmzOwnerKey: []byte(s3account.AccountAdmin.Name),
|
||||
s3_constants.ExtAmzAclKey: goodEntryAcl,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -57,35 +52,28 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
//acp is ""
|
||||
//owner is ""
|
||||
acpEmptyStr = &filer_pb.Entry{
|
||||
Name: "acpEmptyStr",
|
||||
Extended: map[string][]byte{
|
||||
s3_constants.ExtAcpKey: []byte(""),
|
||||
s3_constants.ExtAmzOwnerKey: []byte(""),
|
||||
},
|
||||
}
|
||||
|
||||
//acp is empty object
|
||||
acpEmptyObjectAcp, _ = jsonutil.BuildJSON(&s3.AccessControlPolicy{
|
||||
Owner: nil,
|
||||
Grants: nil,
|
||||
})
|
||||
//owner not exists
|
||||
acpEmptyObject = &filer_pb.Entry{
|
||||
Name: "acpEmptyObject",
|
||||
Extended: map[string][]byte{
|
||||
s3_constants.ExtAcpKey: acpEmptyObjectAcp,
|
||||
s3_constants.ExtAmzOwnerKey: []byte("xxxxx"),
|
||||
},
|
||||
}
|
||||
|
||||
//acp owner is nil
|
||||
acpOwnerNilAcp, _ = jsonutil.BuildJSON(&s3.AccessControlPolicy{
|
||||
Owner: nil,
|
||||
Grants: make([]*s3.Grant, 1),
|
||||
})
|
||||
acpOwnerNil = &filer_pb.Entry{
|
||||
//grants is nil
|
||||
acpOwnerNilAcp, _ = json.Marshal(make([]*s3.Grant, 0))
|
||||
acpOwnerNil = &filer_pb.Entry{
|
||||
Name: "acpOwnerNil",
|
||||
Extended: map[string][]byte{
|
||||
s3_constants.ExtAcpKey: acpOwnerNilAcp,
|
||||
s3_constants.ExtAmzAclKey: acpOwnerNilAcp,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -175,8 +163,14 @@ var tcs = []*BucketMetadataTestCase{
|
||||
}
|
||||
|
||||
func TestBuildBucketMetadata(t *testing.T) {
|
||||
accountManager := &s3account.AccountManager{
|
||||
IdNameMapping: map[string]string{
|
||||
s3account.AccountAdmin.Id: s3account.AccountAdmin.Name,
|
||||
s3account.AccountAnonymous.Id: s3account.AccountAnonymous.Name,
|
||||
},
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
resultBucketMetadata := buildBucketMetadata(tc.filerEntry)
|
||||
resultBucketMetadata := buildBucketMetadata(accountManager, tc.filerEntry)
|
||||
if !reflect.DeepEqual(resultBucketMetadata, tc.expectBucketMetadata) {
|
||||
t.Fatalf("result is unexpect: \nresult: %v, \nexpect: %v", resultBucketMetadata, tc.expectBucketMetadata)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user