Skip to content

Commit 7d3d5de

Browse files
committed
[#266] nns: fix CNAME resolution rules
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.
1 parent c0e0a7a commit 7d3d5de

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

nns/nns_contract.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,6 @@ func resolve(ctx storage.Context, res []string, name string, typ RecordType, red
902902
return res
903903
}
904904

905-
res = append(res, cname)
906905
return resolve(ctx, res, cname, typ, redirect-1)
907906
}
908907

tests/nns_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,19 +390,29 @@ func TestNNSResolve(t *testing.T) {
390390
c := newNNSInvoker(t, true)
391391

392392
refresh, retry, expire, ttl := int64(101), int64(102), int64(103), int64(104)
393-
c.Invoke(t, true, "register",
394-
"test.com", c.CommitteeHash,
395-
"myemail@nspcc.ru", refresh, retry, expire, ttl)
393+
c.Invoke(t, true, "register", "test.com", c.CommitteeHash, "myemail@nspcc.ru", refresh, retry, expire, ttl)
394+
c.Invoke(t, stackitem.Null{}, "addRecord", "test.com", int64(nns.TXT), "expected result")
395+
c.Invoke(t, stackitem.Null{}, "addRecord", "test.com", int64(nns.CNAME), "alias.com")
396396

397-
c.Invoke(t, stackitem.Null{}, "addRecord",
398-
"test.com", int64(nns.TXT), "expected result")
397+
c.Invoke(t, true, "register", "alias.com", c.CommitteeHash, "myemail@nspcc.ru", refresh, retry, expire, ttl)
398+
c.Invoke(t, stackitem.Null{}, "addRecord", "alias.com", int64(nns.A), "1.2.3.4")
399+
c.Invoke(t, stackitem.Null{}, "addRecord", "alias.com", int64(nns.CNAME), "alias2.com")
400+
401+
c.Invoke(t, true, "register", "alias2.com", c.CommitteeHash, "myemail@nspcc.ru", refresh, retry, expire, ttl)
402+
c.Invoke(t, stackitem.Null{}, "addRecord", "alias2.com", int64(nns.A), "5.6.7.8")
399403

400404
records := stackitem.NewArray([]stackitem.Item{stackitem.Make("expected result")})
401405
c.Invoke(t, records, "resolve", "test.com", int64(nns.TXT))
402406
c.Invoke(t, records, "resolve", "test.com.", int64(nns.TXT))
403407
c.InvokeFail(t, "invalid domain name format", "resolve", "test.com..", int64(nns.TXT))
408+
404409
// Empty result.
405-
c.Invoke(t, stackitem.NewArray([]stackitem.Item{}), "resolve", "test.com", int64(nns.CNAME))
410+
c.Invoke(t, stackitem.NewArray([]stackitem.Item{}), "resolve", "test.com", int64(nns.AAAA))
411+
412+
// Check CNAME is properly resolved and is not included into the result list.
413+
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))
414+
// And this time it should be properly included without resolution.
415+
c.Invoke(t, stackitem.NewArray([]stackitem.Item{stackitem.Make("alias.com")}), "resolve", "test.com", int64(nns.CNAME))
406416
}
407417

408418
func TestNNSAddRecord(t *testing.T) {

0 commit comments

Comments
 (0)