Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnss committed Mar 13, 2023
1 parent 90f6afb commit 0fd2fc8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions e2e/tests/permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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])

}
4 changes: 2 additions & 2 deletions x/storage/keeper/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions x/storage/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 0fd2fc8

Please sign in to comment.