Skip to content

Commit

Permalink
feature/account: non-superuser domains cannot be flushed (#1208)
Browse files Browse the repository at this point in the history
* bnsd: non-superuser domains cannot be flushed

* Fix aftertest
  • Loading branch information
orkunkl committed Apr 10, 2020
1 parent 6f420b6 commit cf0f7fe
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## HEAD
- `bug`: Fix renew domain handler renews empty string account
- `feature/account`: Accounts in non super user domains cannot be flushed

## 1.0.3
- `bnsd`: include domain grace period in `make protoc` generated files
Expand Down
3 changes: 3 additions & 0 deletions cmd/bnsd/x/account/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,9 @@ func (h *flushDomainHandler) validate(ctx weave.Context, db weave.KVStore, tx we
if err := h.domains.One(db, []byte(msg.Domain), &domain); err != nil {
return nil, errors.Wrap(err, "cannot get domain")
}
if !domain.HasSuperuser {
return nil, errors.Wrap(errors.ErrState, "domains without a superuser cannot be flushed")
}
if !h.auth.HasAddress(ctx, domain.Admin) {
return nil, errors.Wrap(errors.ErrUnauthorized, "only owner can delete accounts")
}
Expand Down
87 changes: 87 additions & 0 deletions cmd/bnsd/x/account/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,93 @@ func TestUseCases(t *testing.T) {
}
},
},
"non-superuser domains cannot be flushed": {
Requests: []Request{
{
Now: now,
Conditions: []weave.Condition{adminCond},
Tx: &weavetest.Tx{
Msg: &RegisterDomainMsg{
Metadata: &weave.Metadata{Schema: 1},
Domain: "wunderland",
Admin: aliceCond.Address(),
HasSuperuser: false,
AccountRenew: 1000,
},
},
BlockHeight: 100,
WantErr: nil,
},
{
Now: now + 1,
Conditions: []weave.Condition{bobCond},
Tx: &weavetest.Tx{
Msg: &RegisterAccountMsg{
Metadata: &weave.Metadata{Schema: 1},
Owner: bobCond.Address(),
Domain: "wunderland",
Name: "bob",
},
},
BlockHeight: 101,
WantErr: nil,
},
{
Now: now + 2,
Conditions: []weave.Condition{charlieCond},
Tx: &weavetest.Tx{
Msg: &RegisterAccountMsg{
Metadata: &weave.Metadata{Schema: 1},
Owner: charlieCond.Address(),
Domain: "wunderland",
Name: "charlie",
},
},
BlockHeight: 102,
WantErr: nil,
},
{
Now: now + 3,
Conditions: []weave.Condition{adminCond},
Tx: &weavetest.Tx{
Msg: &FlushDomainMsg{
Metadata: &weave.Metadata{Schema: 1},
Domain: "wunderland",
},
},
BlockHeight: 103,
WantErr: errors.ErrState,
},
{
Now: now + 4,
Conditions: []weave.Condition{aliceCond},
Tx: &weavetest.Tx{
Msg: &FlushDomainMsg{
Metadata: &weave.Metadata{Schema: 1},
Domain: "wunderland",
},
},
BlockHeight: 104,
WantErr: errors.ErrState,
},
},
AfterTest: func(t *testing.T, db weave.KVStore) {
b := NewDomainBucket()
var d Domain
if err := b.One(db, []byte("wunderland"), &d); err != nil {
t.Fatalf("cannot get wunderland domain: %s", err)
}
a := NewAccountBucket()
var bobAcc Account
if err := a.One(db, accountKey("bob", d.Domain), &bobAcc); err != nil {
t.Fatalf("cannot get account: %s", err)
}
var charlieAcc Account
if err := a.One(db, accountKey("charlie", d.Domain), &charlieAcc); err != nil {
t.Fatalf("cannot get account: %s", err)
}
},
},
}

for testName, tc := range cases {
Expand Down

0 comments on commit cf0f7fe

Please sign in to comment.