[#150] container: check domain owner in Put

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-10-18 14:32:17 +03:00 committed by Alex Vanin
parent 16f3281198
commit fef6a6cb36
2 changed files with 18 additions and 0 deletions

View file

@ -263,6 +263,12 @@ func checkNiceNameAvailable(nnsContractAddr interop.Hash160, domain string) bool
return true 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", res := contract.Call(nnsContractAddr, "getRecords",
contract.ReadStates|contract.AllowCall, domain, 16 /* TXT */) contract.ReadStates|contract.AllowCall, domain, 16 /* TXT */)
if res != nil { if res != nil {

View file

@ -113,6 +113,18 @@ func TestContainerPut(t *testing.T) {
c.value[len(c.value)-1] = 10 c.value[len(c.value)-1] = 10
c.id = sha256.Sum256(c.value) 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", tx = PrepareInvoke(t, bc, CommitteeAcc, nnsHash, "register",
"second.neofs", CommitteeAcc.Contract.ScriptHash(), "second.neofs", CommitteeAcc.Contract.ScriptHash(),
"whateveriwant@world.com", int64(0), int64(0), int64(0), int64(0)) "whateveriwant@world.com", int64(0), int64(0), int64(0), int64(0))