-
Notifications
You must be signed in to change notification settings - Fork 522
Enforce default code permissions #850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,6 +183,84 @@ func TestCreateWithParamPermissions(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // ensure that the user cannot set the code instantiate permission to something more permissive | ||
| // than the default | ||
| func TestEnforceValidPermissionsOnCreate(t *testing.T) { | ||
| ctx, keepers := CreateTestInput(t, false, SupportedFeatures) | ||
| keeper := keepers.WasmKeeper | ||
| contractKeeper := keepers.ContractKeeper | ||
|
|
||
| deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) | ||
| creator := keepers.Faucet.NewFundedAccount(ctx, deposit...) | ||
| other := keepers.Faucet.NewFundedAccount(ctx, deposit...) | ||
|
|
||
| onlyCreator := types.AccessTypeOnlyAddress.With(creator) | ||
| onlyOther := types.AccessTypeOnlyAddress.With(other) | ||
|
|
||
| specs := map[string]struct { | ||
| defaultPermssion types.AccessType | ||
ethanfrey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| requestedPermission *types.AccessConfig | ||
| // grantedPermission is set iff no error | ||
| grantedPermission types.AccessConfig | ||
| // expError is nil iff the request is allowed | ||
| expError *sdkerrors.Error | ||
| }{ | ||
| "override everybody": { | ||
| defaultPermssion: types.AccessTypeEverybody, | ||
| requestedPermission: &onlyCreator, | ||
| grantedPermission: onlyCreator, | ||
| }, | ||
| "default to everybody": { | ||
| defaultPermssion: types.AccessTypeEverybody, | ||
| requestedPermission: nil, | ||
| grantedPermission: types.AccessConfig{Permission: types.AccessTypeEverybody}, | ||
| }, | ||
| "explicitly set everybody": { | ||
| defaultPermssion: types.AccessTypeEverybody, | ||
| requestedPermission: &types.AccessConfig{Permission: types.AccessTypeEverybody}, | ||
| grantedPermission: types.AccessConfig{Permission: types.AccessTypeEverybody}, | ||
| }, | ||
| "cannot override nobody": { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 very important test |
||
| defaultPermssion: types.AccessTypeNobody, | ||
| requestedPermission: &onlyCreator, | ||
| expError: sdkerrors.ErrUnauthorized, | ||
| }, | ||
| "default to nobody": { | ||
| defaultPermssion: types.AccessTypeNobody, | ||
| requestedPermission: nil, | ||
| grantedPermission: types.AccessConfig{Permission: types.AccessTypeNobody}, | ||
| }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you don't have a case where requestedPermission < defaultPermission .
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do... that is what "override everyone" tests (request more restrictive) I can add more, but these cover the general cases, and the actual compare is heavily tested elsewhere. If you have a concrete default/requested I should add, let me know. I will just add one for equals |
||
| "only defaults to code creator": { | ||
| defaultPermssion: types.AccessTypeOnlyAddress, | ||
| requestedPermission: nil, | ||
| grantedPermission: onlyCreator, | ||
| }, | ||
| "can explicitly set to code creator": { | ||
| defaultPermssion: types.AccessTypeOnlyAddress, | ||
| requestedPermission: &onlyCreator, | ||
| grantedPermission: onlyCreator, | ||
| }, | ||
| "cannot override which address in only": { | ||
| defaultPermssion: types.AccessTypeOnlyAddress, | ||
| requestedPermission: &onlyOther, | ||
| expError: sdkerrors.ErrUnauthorized, | ||
| }, | ||
| } | ||
| for msg, spec := range specs { | ||
| t.Run(msg, func(t *testing.T) { | ||
| params := types.DefaultParams() | ||
| params.InstantiateDefaultPermission = spec.defaultPermssion | ||
| keeper.SetParams(ctx, params) | ||
| codeID, err := contractKeeper.Create(ctx, creator, hackatomWasm, spec.requestedPermission) | ||
| require.True(t, spec.expError.Is(err), err) | ||
| if spec.expError == nil { | ||
| codeInfo := keeper.GetCodeInfo(ctx, codeID) | ||
| require.Equal(t, codeInfo.InstantiateConfig, spec.grantedPermission) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestCreateDuplicate(t *testing.T) { | ||
| ctx, keepers := CreateTestInput(t, false, SupportedFeatures) | ||
| keeper := keepers.ContractKeeper | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.