Skip to content

Commit

Permalink
[nspcc-dev#266] nns: Fix CNAME resolution rules
Browse files Browse the repository at this point in the history
Do not include CNAME to the resulting list if we're looking for another
record type. If it's CNAME than it must be resolved.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Sep 13, 2022
1 parent 0568c51 commit 0f3b928
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion nns/nns_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,6 @@ func resolve(ctx storage.Context, res []string, name string, typ RecordType, red
return res
}

res = append(res, cname)
return resolve(ctx, res, cname, typ, redirect-1)
}

Expand Down
22 changes: 16 additions & 6 deletions tests/nns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,19 +390,29 @@ func TestNNSResolve(t *testing.T) {
c := newNNSInvoker(t, true)

refresh, retry, expire, ttl := int64(101), int64(102), int64(103), int64(104)
c.Invoke(t, true, "register",
"test.com", c.CommitteeHash,
"[email protected]", refresh, retry, expire, ttl)
c.Invoke(t, true, "register", "test.com", c.CommitteeHash, "[email protected]", refresh, retry, expire, ttl)
c.Invoke(t, stackitem.Null{}, "addRecord", "test.com", int64(nns.TXT), "expected result")
c.Invoke(t, stackitem.Null{}, "addRecord", "test.com", int64(nns.CNAME), "alias.com")

c.Invoke(t, stackitem.Null{}, "addRecord",
"test.com", int64(nns.TXT), "expected result")
c.Invoke(t, true, "register", "alias.com", c.CommitteeHash, "[email protected]", refresh, retry, expire, ttl)
c.Invoke(t, stackitem.Null{}, "addRecord", "alias.com", int64(nns.A), "1.2.3.4")
c.Invoke(t, stackitem.Null{}, "addRecord", "alias.com", int64(nns.CNAME), "alias2.com")

c.Invoke(t, true, "register", "alias2.com", c.CommitteeHash, "[email protected]", refresh, retry, expire, ttl)
c.Invoke(t, stackitem.Null{}, "addRecord", "alias2.com", int64(nns.A), "5.6.7.8")

records := stackitem.NewArray([]stackitem.Item{stackitem.Make("expected result")})
c.Invoke(t, records, "resolve", "test.com", int64(nns.TXT))
c.Invoke(t, records, "resolve", "test.com.", int64(nns.TXT))
c.InvokeFail(t, "invalid domain name format", "resolve", "test.com..", int64(nns.TXT))

// Empty result.
c.Invoke(t, stackitem.NewArray([]stackitem.Item{}), "resolve", "test.com", int64(nns.CNAME))
c.Invoke(t, stackitem.NewArray([]stackitem.Item{}), "resolve", "test.com", int64(nns.AAAA))

// Check CNAME is properly resolved and is not included into the result list.
c.Invoke(t, stackitem.NewArray([]stackitem.Item{stackitem.Make("1.2.3.4"), stackitem.Make("5.6.7.8")}), "resolve", "test.com", int64(nns.A))
// And this time it should be properly included without resolution.
c.Invoke(t, stackitem.NewArray([]stackitem.Item{stackitem.Make("alias.com")}), "resolve", "test.com", int64(nns.CNAME))
}

func TestNNSAddRecord(t *testing.T) {
Expand Down

0 comments on commit 0f3b928

Please sign in to comment.