Pull request: dnsforward: fix fqdn in some dns rewrites

Updates #2498.
Updates #2533.

Squashed commit of the following:

commit 9eec20ac3bee5a914f61f41a789f87dec63e910d
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Mar 15 16:53:29 2021 +0300

    dnsforward: fix fqdn in some dns rewrites
This commit is contained in:
Ainar Garipov 2021-03-15 17:17:16 +03:00
parent 313fd7107f
commit 75ac1a5346
4 changed files with 11 additions and 11 deletions

View File

@ -23,14 +23,14 @@ func TestServer_FilterDNSRewrite(t *testing.T) {
}
svcbVal := &rules.DNSSVCB{
Params: map[string]string{"alpn": "h3"},
Target: domain,
Target: dns.Fqdn(domain),
Priority: 32,
}
srvVal := &rules.DNSSRV{
Priority: 32,
Weight: 60,
Port: 8080,
Target: domain,
Target: dns.Fqdn(domain),
}
// Helper functions and entities.
@ -113,7 +113,7 @@ func TestServer_FilterDNSRewrite(t *testing.T) {
assert.Equal(t, dns.RcodeSuccess, d.Res.Rcode)
require.Len(t, d.Res.Answer, 1)
assert.Equal(t, domain, d.Res.Answer[0].(*dns.PTR).Ptr)
assert.Equal(t, dns.Fqdn(domain), d.Res.Answer[0].(*dns.PTR).Ptr)
})
t.Run("noerror_txt", func(t *testing.T) {
@ -142,7 +142,7 @@ func TestServer_FilterDNSRewrite(t *testing.T) {
ans, ok := d.Res.Answer[0].(*dns.MX)
require.True(t, ok)
assert.Equal(t, mxVal.Exchange, ans.Mx)
assert.Equal(t, dns.Fqdn(mxVal.Exchange), ans.Mx)
assert.Equal(t, mxVal.Preference, ans.Preference)
})

View File

@ -138,14 +138,14 @@ func (s *Server) genAnswerMX(req *dns.Msg, mx *rules.DNSMX) (ans *dns.MX) {
return &dns.MX{
Hdr: s.hdr(req, dns.TypeMX),
Preference: mx.Preference,
Mx: mx.Exchange,
Mx: dns.Fqdn(mx.Exchange),
}
}
func (s *Server) genAnswerPTR(req *dns.Msg, ptr string) (ans *dns.PTR) {
return &dns.PTR{
Hdr: s.hdr(req, dns.TypePTR),
Ptr: ptr,
Ptr: dns.Fqdn(ptr),
}
}
@ -155,7 +155,7 @@ func (s *Server) genAnswerSRV(req *dns.Msg, srv *rules.DNSSRV) (ans *dns.SRV) {
Priority: srv.Priority,
Weight: srv.Weight,
Port: srv.Port,
Target: srv.Target,
Target: dns.Fqdn(srv.Target),
}
}

View File

@ -137,7 +137,7 @@ func (s *Server) genAnswerSVCB(req *dns.Msg, svcb *rules.DNSSVCB) (ans *dns.SVCB
ans = &dns.SVCB{
Hdr: s.hdr(req, dns.TypeSVCB),
Priority: svcb.Priority,
Target: svcb.Target,
Target: dns.Fqdn(svcb.Target),
}
if len(svcb.Params) == 0 {
return ans

View File

@ -57,7 +57,7 @@ func TestGenAnswerHTTPS_andSVCB(t *testing.T) {
want = &dns.SVCB{
Hdr: s.hdr(req, dns.TypeSVCB),
Priority: prio,
Target: host,
Target: dns.Fqdn(host),
}
if kv == nil {
@ -122,7 +122,7 @@ func TestGenAnswerHTTPS_andSVCB(t *testing.T) {
}, {
svcb: dnssvcb("no-default-alpn", ""),
want: wantsvcb(&dns.SVCBNoDefaultAlpn{}),
name: "no-default-alpn",
name: "no_default_alpn",
}, {
svcb: dnssvcb("port", "8080"),
want: wantsvcb(&dns.SVCBPort{Port: 8080}),
@ -130,7 +130,7 @@ func TestGenAnswerHTTPS_andSVCB(t *testing.T) {
}, {
svcb: dnssvcb("port", "1005008080"),
want: wantsvcb(nil),
name: "port",
name: "bad_port",
}}
for _, tc := range testCases {