From 0fd2fc8915b9d3d414c989022d48d7ae690e55a1 Mon Sep 17 00:00:00 2001 From: Fynn Date: Mon, 13 Mar 2023 22:01:46 +0800 Subject: [PATCH] add more test --- e2e/tests/permission_test.go | 12 ++++++++++++ x/storage/keeper/permission.go | 4 ++-- x/storage/keeper/query.go | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/e2e/tests/permission_test.go b/e2e/tests/permission_test.go index c4982bf76..130310942 100644 --- a/e2e/tests/permission_test.go +++ b/e2e/tests/permission_test.go @@ -7,6 +7,7 @@ import ( "github.com/bnb-chain/greenfield/e2e/core" storageutil "github.com/bnb-chain/greenfield/testutil/storage" types2 "github.com/bnb-chain/greenfield/types" + "github.com/bnb-chain/greenfield/types/resource" "github.com/bnb-chain/greenfield/x/permission/types" storagetypes "github.com/bnb-chain/greenfield/x/storage/types" ) @@ -81,7 +82,18 @@ func (s *StorageTestSuite) TestDeleteBucketPermission() { s.T().Logf("resp: %s, rep %s", verifyPermReq.String(), verifyPermResp.String()) s.Require().NoError(err) s.Require().Equal(verifyPermResp.Effect, types.EFFECT_ALLOW) + + // Query bucket proxy + grn := types2.NewBucketGRN(bucketName) + queryPolicyForAccountReq := storagetypes.QueryPolicyForAccountRequest{Resource: grn.String(), + PrincipalAddress: user[1].GetAddr().String()} + queryPolicyForAccountResp, err := s.Client.QueryPolicyForAccount(ctx, &queryPolicyForAccountReq) + s.Require().NoError(err) + s.Require().Equal(queryPolicyForAccountResp.Policy.ResourceType, resource.RESOURCE_TYPE_BUCKET) + s.Require().Equal(queryPolicyForAccountResp.Policy.ResourceId, queryHeadBucketResponse.BucketInfo.Id) + // DeleteBucket msgDeleteBucket := storagetypes.NewMsgDeleteBucket(user[1].GetAddr(), bucketName) s.SendTxBlock(msgDeleteBucket, user[1]) + } diff --git a/x/storage/keeper/permission.go b/x/storage/keeper/permission.go index f8bca8775..99e226d08 100644 --- a/x/storage/keeper/permission.go +++ b/x/storage/keeper/permission.go @@ -141,8 +141,8 @@ func (k Keeper) GetPolicy(ctx sdk.Context, grn *types2.GRN, principal *permtypes return nil, permtypes.ErrInvalidPrincipal } - if found { - return nil, types.ErrNoSuchPolicy + if !found { + return nil, types.ErrNoSuchPolicy.Wrapf("GRN: %s, principal:%s", grn.String(), principal.String()) } return policy, nil } diff --git a/x/storage/keeper/query.go b/x/storage/keeper/query.go index 657794590..9caac0889 100644 --- a/x/storage/keeper/query.go +++ b/x/storage/keeper/query.go @@ -260,7 +260,7 @@ func (k Keeper) QueryPolicyForAccount(goCtx context.Context, req *types.QueryPol policy, err := k.GetPolicy(ctx, &grn, permtypes.NewPrincipalWithAccount(principalAcc)) if err != nil { - return nil, types.ErrNoSuchPolicy + return nil, err } return &types.QueryPolicyForAccountResponse{Policy: policy}, nil @@ -287,7 +287,7 @@ func (k Keeper) QueryPolicyForGroup(goCtx context.Context, req *types.QueryPolic policy, err := k.GetPolicy(ctx, &grn, permtypes.NewPrincipalWithGroup(id)) if err != nil { - return nil, types.ErrNoSuchPolicy + return nil, err } return &types.QueryPolicyForGroupResponse{Policy: policy}, nil }