mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
don't skip empty value at AssembleEntryWithAcp
(#3855)
* add acl helper functionalities Signed-off-by: changlin.shi <changlin.shi@ly.com> * add tests Signed-off-by: changlin.shi <changlin.shi@ly.com> * remove 0 when create map Signed-off-by: changlin.shi <changlin.shi@ly.com> * delete when empty at `AssembleEntryWithAcp` `PutBucketAcl/PutObjectAcl` allow request with empty grants, `AssembleEntryWithAcp` shouldn't skip empty value Signed-off-by: changlin.shi <changlin.shi@ly.com> Signed-off-by: changlin.shi <changlin.shi@ly.com>
This commit is contained in:
parent
1f7e52c63e
commit
a5b867af69
|
@ -411,6 +411,8 @@ func AssembleEntryWithAcp(objectEntry *filer_pb.Entry, objectOwner string, grant
|
||||||
|
|
||||||
if len(objectOwner) > 0 {
|
if len(objectOwner) > 0 {
|
||||||
objectEntry.Extended[s3_constants.ExtAmzOwnerKey] = []byte(objectOwner)
|
objectEntry.Extended[s3_constants.ExtAmzOwnerKey] = []byte(objectOwner)
|
||||||
|
} else {
|
||||||
|
delete(objectEntry.Extended, s3_constants.ExtAmzOwnerKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(grants) > 0 {
|
if len(grants) > 0 {
|
||||||
|
@ -420,6 +422,8 @@ func AssembleEntryWithAcp(objectEntry *filer_pb.Entry, objectOwner string, grant
|
||||||
return s3err.ErrInvalidRequest
|
return s3err.ErrInvalidRequest
|
||||||
}
|
}
|
||||||
objectEntry.Extended[s3_constants.ExtAmzAclKey] = grantsBytes
|
objectEntry.Extended[s3_constants.ExtAmzAclKey] = grantsBytes
|
||||||
|
} else {
|
||||||
|
delete(objectEntry.Extended, s3_constants.ExtAmzAclKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
return s3err.ErrNone
|
return s3err.ErrNone
|
||||||
|
|
|
@ -487,46 +487,44 @@ func TestDetermineReqGrants(t *testing.T) {
|
||||||
|
|
||||||
func TestAssembleEntryWithAcp(t *testing.T) {
|
func TestAssembleEntryWithAcp(t *testing.T) {
|
||||||
defaultOwner := "admin"
|
defaultOwner := "admin"
|
||||||
{
|
|
||||||
//case1
|
//case1
|
||||||
expectOwner := "accountS"
|
//assemble with non-empty grants
|
||||||
expectGrants := []*s3.Grant{
|
expectOwner := "accountS"
|
||||||
{
|
expectGrants := []*s3.Grant{
|
||||||
Permission: &s3_constants.PermissionRead,
|
{
|
||||||
Grantee: &s3.Grantee{
|
Permission: &s3_constants.PermissionRead,
|
||||||
Type: &s3_constants.GrantTypeGroup,
|
Grantee: &s3.Grantee{
|
||||||
ID: &s3account.AccountAdmin.Id,
|
Type: &s3_constants.GrantTypeGroup,
|
||||||
URI: &s3_constants.GranteeGroupAllUsers,
|
ID: &s3account.AccountAdmin.Id,
|
||||||
},
|
URI: &s3_constants.GranteeGroupAllUsers,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
entry := &filer_pb.Entry{}
|
|
||||||
AssembleEntryWithAcp(entry, expectOwner, expectGrants)
|
|
||||||
|
|
||||||
resultOwner := GetAcpOwner(entry.Extended, defaultOwner)
|
|
||||||
if resultOwner != expectOwner {
|
|
||||||
t.Fatalf("owner not expect")
|
|
||||||
}
|
|
||||||
|
|
||||||
resultGrants := GetAcpGrants(entry.Extended)
|
|
||||||
if !grantsEquals(resultGrants, expectGrants) {
|
|
||||||
t.Fatal("grants not expect")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
entry := &filer_pb.Entry{}
|
||||||
//case2
|
AssembleEntryWithAcp(entry, expectOwner, expectGrants)
|
||||||
entry := &filer_pb.Entry{}
|
|
||||||
AssembleEntryWithAcp(entry, "", nil)
|
|
||||||
|
|
||||||
resultOwner := GetAcpOwner(entry.Extended, defaultOwner)
|
resultOwner := GetAcpOwner(entry.Extended, defaultOwner)
|
||||||
if resultOwner != defaultOwner {
|
if resultOwner != expectOwner {
|
||||||
t.Fatalf("owner not expect")
|
t.Fatalf("owner not expect")
|
||||||
}
|
}
|
||||||
|
|
||||||
resultGrants := GetAcpGrants(entry.Extended)
|
resultGrants := GetAcpGrants(entry.Extended)
|
||||||
if len(resultGrants) != 0 {
|
if !grantsEquals(resultGrants, expectGrants) {
|
||||||
t.Fatal("grants not expect")
|
t.Fatal("grants not expect")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//case2
|
||||||
|
//assemble with empty grants (override)
|
||||||
|
AssembleEntryWithAcp(entry, "", nil)
|
||||||
|
resultOwner = GetAcpOwner(entry.Extended, defaultOwner)
|
||||||
|
if resultOwner != defaultOwner {
|
||||||
|
t.Fatalf("owner not expect")
|
||||||
|
}
|
||||||
|
|
||||||
|
resultGrants = GetAcpGrants(entry.Extended)
|
||||||
|
if len(resultGrants) != 0 {
|
||||||
|
t.Fatal("grants not expect")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue