From fef6a6cb36ee1d41b2297036a437e6a978564ffb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 18 Oct 2021 14:32:17 +0300 Subject: [PATCH] [#150] container: check domain owner in `Put` Signed-off-by: Evgenii Stratonikov --- container/container_contract.go | 6 ++++++ tests/container_test.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/container/container_contract.go b/container/container_contract.go index 27e7c17..820145e 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -263,6 +263,12 @@ func checkNiceNameAvailable(nnsContractAddr interop.Hash160, domain string) bool return true } + owner := contract.Call(nnsContractAddr, "ownerOf", + contract.ReadStates|contract.AllowCall, domain).(string) + if string(owner) != string(common.CommitteeAddress()) { + panic("committee must own registered domain") + } + res := contract.Call(nnsContractAddr, "getRecords", contract.ReadStates|contract.AllowCall, domain, 16 /* TXT */) if res != nil { diff --git a/tests/container_test.go b/tests/container_test.go index 36a864e..2c5b58e 100644 --- a/tests/container_test.go +++ b/tests/container_test.go @@ -113,6 +113,18 @@ func TestContainerPut(t *testing.T) { c.value[len(c.value)-1] = 10 c.id = sha256.Sum256(c.value) + t.Run("bad domain owner", func(t *testing.T) { + tx = PrepareInvoke(t, bc, acc, nnsHash, "register", + "baddomain.neofs", acc.Contract.ScriptHash(), + "whateveriwant@world.com", int64(0), int64(0), int64(0), int64(0)) + AddBlockCheckHalt(t, bc, tx) + + putArgs := []interface{}{container, dummySig, dummyPub, dummyToken, "baddomain", "neofs"} + tx = PrepareInvoke(t, bc, acc, h, "putNamed", putArgs...) + AddBlock(t, bc, tx) + CheckFault(t, bc, tx.Hash(), "committee must own registered domain") + }) + tx = PrepareInvoke(t, bc, CommitteeAcc, nnsHash, "register", "second.neofs", CommitteeAcc.Contract.ScriptHash(), "whateveriwant@world.com", int64(0), int64(0), int64(0), int64(0))