Pull request 1877: 5913-fix-safesearch-ipv6

Updates #5913.

Squashed commit of the following:

commit a0ab1320ea22dc1b4e2804ef2d14e0091daa6a1e
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Jun 19 15:23:44 2023 +0300

    all: fmt; typo

commit 3a2e561c535bbbd2b2eeeaa1a6f423bc123b1a6b
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Jun 19 15:16:28 2023 +0300

    all: fix safesearch for ipv6
This commit is contained in:
Ainar Garipov
2023-06-19 15:45:01 +03:00
parent b6d00f774b
commit d26c480d03
5 changed files with 31 additions and 16 deletions

View File

@@ -203,7 +203,7 @@ func (ss *Default) CheckHost(
return res, nil
}
return filtering.Result{}, fmt.Errorf("no ipv4 addresses for %q", host)
return filtering.Result{}, fmt.Errorf("no ip addresses for %q", host)
}
// searchHost looks up DNS rewrites in the internal DNS filtering engine.
@@ -255,7 +255,14 @@ func (ss *Default) newResult(
host := rewrite.NewCNAME
if host == "" {
return nil, nil
// If there is a rewrite, but it's neither a CNAME one nor one matching
// the IP version, then it's a service that only has one type of IP
// record but not the other. Return the empty result to be converted
// into a NODATA response.
//
// TODO(a.garipov): Use the main rewrite result mechanism used in
// [dnsforward.Server.filterDNSRequest].
return res, nil
}
ss.log(log.DEBUG, "resolving %q", host)

View File

@@ -71,6 +71,17 @@ func TestDefault_CheckHost_yandex(t *testing.T) {
}
}
func TestDefault_CheckHost_yandexAAAA(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err)
res, err := ss.CheckHost("www.yandex.ru", dns.TypeAAAA)
require.NoError(t, err)
assert.True(t, res.IsFiltered)
}
func TestDefault_CheckHost_google(t *testing.T) {
resolver := &aghtest.TestResolver{}
ip, _ := resolver.HostToIPs("forcesafesearch.google.com")