Pull request: * all: allow multiple hosts in reverse lookups

Merge in DNS/adguard-home from 2269-multiple-hosts to master

For #2269.

Squashed commit of the following:

commit f8ae452540b106f2d5b130b8edb08c4e76b003f4
Merge: 8dd06f7cc 3e1f92225
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Nov 6 17:28:12 2020 +0300

    Merge branch 'master' into 2269-multiple-hosts

commit 8dd06f7cca27ec32a4690e2673603b166f82af0a
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Nov 5 20:28:33 2020 +0300

    * all: allow multiple hosts in reverse lookups
This commit is contained in:
Ainar Garipov
2020-11-06 17:34:40 +03:00
parent 3e1f922252
commit 298f74ba81
5 changed files with 116 additions and 65 deletions

View File

@@ -15,7 +15,7 @@ import (
func prepareTestDir() string {
const dir = "./agh-test"
_ = os.RemoveAll(dir)
_ = os.MkdirAll(dir, 0755)
_ = os.MkdirAll(dir, 0o755)
return dir
}
@@ -50,17 +50,24 @@ func TestAutoHostsResolution(t *testing.T) {
// Test hosts file
table := ah.List()
name, ok := table["127.0.0.1"]
names, ok := table["127.0.0.1"]
assert.True(t, ok)
assert.Equal(t, "host", name)
assert.Equal(t, []string{"host", "localhost"}, names)
// Test PTR
a, _ := dns.ReverseAddr("127.0.0.1")
a = strings.TrimSuffix(a, ".")
assert.True(t, ah.ProcessReverse(a, dns.TypePTR) == "host")
hosts := ah.ProcessReverse(a, dns.TypePTR)
if assert.Len(t, hosts, 2) {
assert.Equal(t, hosts[0], "host")
}
a, _ = dns.ReverseAddr("::1")
a = strings.TrimSuffix(a, ".")
assert.True(t, ah.ProcessReverse(a, dns.TypePTR) == "localhost")
hosts = ah.ProcessReverse(a, dns.TypePTR)
if assert.Len(t, hosts, 1) {
assert.Equal(t, hosts[0], "localhost")
}
}
func TestAutoHostsFSNotify(t *testing.T) {