mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 04:55:33 +03:00
Pull request: dnsfilter: improve cname rewrite validation
Merge in DNS/adguard-home from 2492-dnsrw-host to master
Closes #2492.
Squashed commit of the following:
commit 7128ed15de86c926ea4cff9fd8d3d3821657254f
Merge: e678c64e6 338209f32
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Mon Dec 28 18:42:25 2020 +0300
Merge branch 'master' into 2492-dnsrw-host
commit e678c64e656ccf69c6818e9165ff1451f7c8fde6
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Mon Dec 28 18:04:52 2020 +0300
dnsfilter: improve cname rewrite validation
This commit is contained in:
parent
338209f32b
commit
93ffed7809
3 changed files with 37 additions and 36 deletions
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.14
|
||||||
require (
|
require (
|
||||||
github.com/AdguardTeam/dnsproxy v0.33.7
|
github.com/AdguardTeam/dnsproxy v0.33.7
|
||||||
github.com/AdguardTeam/golibs v0.4.4
|
github.com/AdguardTeam/golibs v0.4.4
|
||||||
github.com/AdguardTeam/urlfilter v0.14.1
|
github.com/AdguardTeam/urlfilter v0.14.2
|
||||||
github.com/NYTimes/gziphandler v1.1.1
|
github.com/NYTimes/gziphandler v1.1.1
|
||||||
github.com/ameshkov/dnscrypt/v2 v2.0.1
|
github.com/ameshkov/dnscrypt/v2 v2.0.1
|
||||||
github.com/fsnotify/fsnotify v1.4.9
|
github.com/fsnotify/fsnotify v1.4.9
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -26,8 +26,8 @@ github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKU
|
||||||
github.com/AdguardTeam/golibs v0.4.4 h1:cM9UySQiYFW79zo5XRwnaIWVzfW4eNXmZktMrWbthpw=
|
github.com/AdguardTeam/golibs v0.4.4 h1:cM9UySQiYFW79zo5XRwnaIWVzfW4eNXmZktMrWbthpw=
|
||||||
github.com/AdguardTeam/golibs v0.4.4/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
|
github.com/AdguardTeam/golibs v0.4.4/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
|
||||||
github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU=
|
github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU=
|
||||||
github.com/AdguardTeam/urlfilter v0.14.1 h1:imYls0fit9ojA6pP1hWFUEIjyoXbDF85ZM+G67bI48c=
|
github.com/AdguardTeam/urlfilter v0.14.2 h1:k26vEYz0mT/liDGZ0JGIBLYLMHaisIGX1UR0qaVnO4k=
|
||||||
github.com/AdguardTeam/urlfilter v0.14.1/go.mod h1:klx4JbOfc4EaNb5lWLqOwfg+pVcyRukmoJRvO55lL5U=
|
github.com/AdguardTeam/urlfilter v0.14.2/go.mod h1:klx4JbOfc4EaNb5lWLqOwfg+pVcyRukmoJRvO55lL5U=
|
||||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
|
|
|
@ -11,39 +11,40 @@ import (
|
||||||
|
|
||||||
func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
const text = `
|
const text = `
|
||||||
|cname^$dnsrewrite=new_cname
|
|cname^$dnsrewrite=new-cname
|
||||||
|
|
||||||
|a_record^$dnsrewrite=127.0.0.1
|
|a-record^$dnsrewrite=127.0.0.1
|
||||||
|
|
||||||
|aaaa_record^$dnsrewrite=::1
|
|aaaa-record^$dnsrewrite=::1
|
||||||
|
|
||||||
|txt_record^$dnsrewrite=NOERROR;TXT;hello_world
|
|txt-record^$dnsrewrite=NOERROR;TXT;hello-world
|
||||||
|
|
||||||
|refused^$dnsrewrite=REFUSED
|
|refused^$dnsrewrite=REFUSED
|
||||||
|
|
||||||
|a_records^$dnsrewrite=127.0.0.1
|
|a-records^$dnsrewrite=127.0.0.1
|
||||||
|a_records^$dnsrewrite=127.0.0.2
|
|a-records^$dnsrewrite=127.0.0.2
|
||||||
|
|
||||||
|aaaa_records^$dnsrewrite=::1
|
|aaaa-records^$dnsrewrite=::1
|
||||||
|aaaa_records^$dnsrewrite=::2
|
|aaaa-records^$dnsrewrite=::2
|
||||||
|
|
||||||
|disable_one^$dnsrewrite=127.0.0.1
|
|disable-one^$dnsrewrite=127.0.0.1
|
||||||
|disable_one^$dnsrewrite=127.0.0.2
|
|disable-one^$dnsrewrite=127.0.0.2
|
||||||
@@||disable_one^$dnsrewrite=127.0.0.1
|
@@||disable-one^$dnsrewrite=127.0.0.1
|
||||||
|
|
||||||
|disable_cname^$dnsrewrite=127.0.0.1
|
|disable-cname^$dnsrewrite=127.0.0.1
|
||||||
|disable_cname^$dnsrewrite=new_cname
|
|disable-cname^$dnsrewrite=new-cname
|
||||||
@@||disable_cname^$dnsrewrite=new_cname
|
@@||disable-cname^$dnsrewrite=new-cname
|
||||||
|
|
||||||
|disable_cname_many^$dnsrewrite=127.0.0.1
|
|disable-cname-many^$dnsrewrite=127.0.0.1
|
||||||
|disable_cname_many^$dnsrewrite=new_cname_1
|
|disable-cname-many^$dnsrewrite=new-cname-1
|
||||||
|disable_cname_many^$dnsrewrite=new_cname_2
|
|disable-cname-many^$dnsrewrite=new-cname-2
|
||||||
@@||disable_cname_many^$dnsrewrite=new_cname_1
|
@@||disable-cname-many^$dnsrewrite=new-cname-1
|
||||||
|
|
||||||
|disable_all^$dnsrewrite=127.0.0.1
|
|disable-all^$dnsrewrite=127.0.0.1
|
||||||
|disable_all^$dnsrewrite=127.0.0.2
|
|disable-all^$dnsrewrite=127.0.0.2
|
||||||
@@||disable_all^$dnsrewrite
|
@@||disable-all^$dnsrewrite
|
||||||
`
|
`
|
||||||
|
|
||||||
f := NewForTest(nil, []Filter{{ID: 0, Data: []byte(text)}})
|
f := NewForTest(nil, []Filter{{ID: 0, Data: []byte(text)}})
|
||||||
setts := &RequestFilteringSettings{
|
setts := &RequestFilteringSettings{
|
||||||
FilteringEnabled: true,
|
FilteringEnabled: true,
|
||||||
|
@ -60,10 +61,10 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
|
|
||||||
res, err := f.CheckHostRules(host, dtyp, setts)
|
res, err := f.CheckHostRules(host, dtyp, setts)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "new_cname", res.CanonName)
|
assert.Equal(t, "new-cname", res.CanonName)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("a_record", func(t *testing.T) {
|
t.Run("a-record", func(t *testing.T) {
|
||||||
dtyp := dns.TypeA
|
dtyp := dns.TypeA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("aaaa_record", func(t *testing.T) {
|
t.Run("aaaa-record", func(t *testing.T) {
|
||||||
dtyp := dns.TypeAAAA
|
dtyp := dns.TypeAAAA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
|
@ -93,7 +94,7 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("txt_record", func(t *testing.T) {
|
t.Run("txt-record", func(t *testing.T) {
|
||||||
dtyp := dns.TypeTXT
|
dtyp := dns.TypeTXT
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
res, err := f.CheckHostRules(host, dtyp, setts)
|
res, err := f.CheckHostRules(host, dtyp, setts)
|
||||||
|
@ -102,7 +103,7 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
if dnsrr := res.DNSRewriteResult; assert.NotNil(t, dnsrr) {
|
if dnsrr := res.DNSRewriteResult; assert.NotNil(t, dnsrr) {
|
||||||
assert.Equal(t, dns.RcodeSuccess, dnsrr.RCode)
|
assert.Equal(t, dns.RcodeSuccess, dnsrr.RCode)
|
||||||
if strVals := dnsrr.Response[dtyp]; assert.Len(t, strVals, 1) {
|
if strVals := dnsrr.Response[dtyp]; assert.Len(t, strVals, 1) {
|
||||||
assert.Equal(t, "hello_world", strVals[0])
|
assert.Equal(t, "hello-world", strVals[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -117,7 +118,7 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("a_records", func(t *testing.T) {
|
t.Run("a-records", func(t *testing.T) {
|
||||||
dtyp := dns.TypeA
|
dtyp := dns.TypeA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("aaaa_records", func(t *testing.T) {
|
t.Run("aaaa-records", func(t *testing.T) {
|
||||||
dtyp := dns.TypeAAAA
|
dtyp := dns.TypeAAAA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
|
@ -149,7 +150,7 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("disable_one", func(t *testing.T) {
|
t.Run("disable-one", func(t *testing.T) {
|
||||||
dtyp := dns.TypeA
|
dtyp := dns.TypeA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
|
@ -164,7 +165,7 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("disable_cname", func(t *testing.T) {
|
t.Run("disable-cname", func(t *testing.T) {
|
||||||
dtyp := dns.TypeA
|
dtyp := dns.TypeA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
|
@ -180,17 +181,17 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("disable_cname_many", func(t *testing.T) {
|
t.Run("disable-cname-many", func(t *testing.T) {
|
||||||
dtyp := dns.TypeA
|
dtyp := dns.TypeA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
res, err := f.CheckHostRules(host, dtyp, setts)
|
res, err := f.CheckHostRules(host, dtyp, setts)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "new_cname_2", res.CanonName)
|
assert.Equal(t, "new-cname-2", res.CanonName)
|
||||||
assert.Nil(t, res.DNSRewriteResult)
|
assert.Nil(t, res.DNSRewriteResult)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("disable_all", func(t *testing.T) {
|
t.Run("disable-all", func(t *testing.T) {
|
||||||
dtyp := dns.TypeA
|
dtyp := dns.TypeA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue