[s3acl] Step1: move s3account.AccountManager into to iam.S3ApiConfiguration (#4859)
* move s3account.AccountManager into to iam.S3ApiConfiguration and switch to Interface https://github.com/seaweedfs/seaweedfs/issues/4519 * fix: test bucket acl default and adjust the variable names * fix: s3 api config test --------- Co-authored-by: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.co> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
c9177c92e5
commit
f8b94cac0e
@@ -2,14 +2,12 @@ package s3api
|
||||
|
||||
import (
|
||||
. "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3account"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
jsonpb "google.golang.org/protobuf/encoding/protojson"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
||||
jsonpb "google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
func TestIdentityListFileFormat(t *testing.T) {
|
||||
@@ -146,11 +144,22 @@ func TestCanDo(t *testing.T) {
|
||||
}
|
||||
|
||||
type LoadS3ApiConfigurationTestCase struct {
|
||||
pbAccount *iam_pb.Account
|
||||
pbIdent *iam_pb.Identity
|
||||
expectIdent *Identity
|
||||
}
|
||||
|
||||
func TestLoadS3ApiConfiguration(t *testing.T) {
|
||||
specifiedAccount := Account{
|
||||
Id: "specifiedAccountID",
|
||||
DisplayName: "specifiedAccountName",
|
||||
EmailAddress: "specifiedAccounEmail@example.com",
|
||||
}
|
||||
pbSpecifiedAccount := iam_pb.Account{
|
||||
Id: "specifiedAccountID",
|
||||
DisplayName: "specifiedAccountName",
|
||||
EmailAddress: "specifiedAccounEmail@example.com",
|
||||
}
|
||||
testCases := map[string]*LoadS3ApiConfigurationTestCase{
|
||||
"notSpecifyAccountId": {
|
||||
pbIdent: &iam_pb.Identity{
|
||||
@@ -167,8 +176,8 @@ func TestLoadS3ApiConfiguration(t *testing.T) {
|
||||
},
|
||||
},
|
||||
expectIdent: &Identity{
|
||||
Name: "notSpecifyAccountId",
|
||||
AccountId: s3account.AccountAdmin.Id,
|
||||
Name: "notSpecifyAccountId",
|
||||
Account: &AccountAdmin,
|
||||
Actions: []Action{
|
||||
"Read",
|
||||
"Write",
|
||||
@@ -182,17 +191,18 @@ func TestLoadS3ApiConfiguration(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"specifiedAccountID": {
|
||||
pbAccount: &pbSpecifiedAccount,
|
||||
pbIdent: &iam_pb.Identity{
|
||||
Name: "specifiedAccountID",
|
||||
AccountId: "specifiedAccountID",
|
||||
Name: "specifiedAccountID",
|
||||
Account: &pbSpecifiedAccount,
|
||||
Actions: []string{
|
||||
"Read",
|
||||
"Write",
|
||||
},
|
||||
},
|
||||
expectIdent: &Identity{
|
||||
Name: "specifiedAccountID",
|
||||
AccountId: "specifiedAccountID",
|
||||
Name: "specifiedAccountID",
|
||||
Account: &specifiedAccount,
|
||||
Actions: []Action{
|
||||
"Read",
|
||||
"Write",
|
||||
@@ -208,8 +218,8 @@ func TestLoadS3ApiConfiguration(t *testing.T) {
|
||||
},
|
||||
},
|
||||
expectIdent: &Identity{
|
||||
Name: "anonymous",
|
||||
AccountId: "anonymous",
|
||||
Name: "anonymous",
|
||||
Account: &AccountAnonymous,
|
||||
Actions: []Action{
|
||||
"Read",
|
||||
"Write",
|
||||
@@ -223,6 +233,9 @@ func TestLoadS3ApiConfiguration(t *testing.T) {
|
||||
}
|
||||
for _, v := range testCases {
|
||||
config.Identities = append(config.Identities, v.pbIdent)
|
||||
if v.pbAccount != nil {
|
||||
config.Accounts = append(config.Accounts, v.pbAccount)
|
||||
}
|
||||
}
|
||||
|
||||
iam := IdentityAccessManagement{}
|
||||
@@ -234,7 +247,7 @@ func TestLoadS3ApiConfiguration(t *testing.T) {
|
||||
for _, ident := range iam.identities {
|
||||
tc := testCases[ident.Name]
|
||||
if !reflect.DeepEqual(ident, tc.expectIdent) {
|
||||
t.Error("not expect")
|
||||
t.Errorf("not expect for ident name %s", ident.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user