Skip to content

Commit

Permalink
Merge pull request #1205 from iov-one/domain-empty-remove
Browse files Browse the repository at this point in the history
bnsd: fix domain renews empty string account
  • Loading branch information
davepuchyr committed Apr 9, 2020
2 parents 0a81763 + d4563f9 commit 86dc3de
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## HEAD
- `bug`: Fix renew domain handler renews empty string account

## 1.0.2
- `feature/account`: A non owner can delete domain after grace period ends
Expand Down
23 changes: 19 additions & 4 deletions cmd/bnsd/x/account/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func RegisterRoutes(r weave.Registry, auth x.Authenticator) {
auth: auth,
})
r.Handle(&RenewDomainMsg{}, &renewDomainHandler{
domains: domains,
auth: auth,
domains: domains,
accounts: accounts,
auth: auth,
})
r.Handle(&DeleteDomainMsg{}, &deleteDomainHandler{
domains: domains,
Expand Down Expand Up @@ -358,8 +359,9 @@ func (it *domainAccountIter) Next() (*Account, error) {
}

type renewDomainHandler struct {
auth x.Authenticator
domains orm.ModelBucket
auth x.Authenticator
domains orm.ModelBucket
accounts orm.ModelBucket
}

func (h *renewDomainHandler) Check(ctx weave.Context, db weave.KVStore, tx weave.Tx) (*weave.CheckResult, error) {
Expand Down Expand Up @@ -396,6 +398,19 @@ func (h *renewDomainHandler) Deliver(ctx weave.Context, db weave.KVStore, tx wea
if _, err := h.domains.Put(db, []byte(msg.Domain), domain); err != nil {
return nil, errors.Wrap(err, "cannot store domain")
}

// update domain's empty account
var acc Account
if err := h.accounts.One(db, accountKey("", msg.Domain), &acc); err != nil {
return nil, errors.Wrap(err, "cannot get empty account entity")
}

// update empty account
acc.ValidUntil = weave.AsUnixTime(nextValidUntil)
if _, err := h.accounts.Put(db, accountKey("", msg.Domain), &acc); err != nil {
return nil, errors.Wrap(err, "cannot store account entity")
}

return &weave.DeliverResult{Data: nil}, nil
}

Expand Down
46 changes: 46 additions & 0 deletions cmd/bnsd/x/account/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2497,6 +2497,52 @@ func TestUseCases(t *testing.T) {
},
},
},
"renew domain handler renews empty account": {
Requests: []Request{
{
Now: now,
Conditions: []weave.Condition{aliceCond},
Tx: &weavetest.Tx{
Msg: &RegisterDomainMsg{
Metadata: &weave.Metadata{Schema: 1},
Domain: "wunderland",
Admin: aliceCond.Address(),
HasSuperuser: true,
AccountRenew: 1000,
},
},
BlockHeight: 100,
WantErr: nil,
},
{
Now: now + 1,
Conditions: []weave.Condition{aliceCond},
Tx: &weavetest.Tx{
Msg: &RenewDomainMsg{
Metadata: &weave.Metadata{Schema: 1},
Domain: "wunderland",
},
},
BlockHeight: 101,
WantErr: nil,
},
},
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 acc Account
if err := a.One(db, accountKey("", d.Domain), &acc); err != nil {
t.Fatalf("cannot get wunderland empty account: %s", err)
}
if got, want := acc.ValidUntil, d.ValidUntil; want != got {
t.Fatalf("want valid till %s, got %s", want, got)
}
},
},
}

for testName, tc := range cases {
Expand Down

0 comments on commit 86dc3de

Please sign in to comment.