Pull request: all: update go and backend tools

Updates #2275.

Squashed commit of the following:

commit f24c26cd2b49fac00a581936da4ccb13ca341bc9
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Mar 10 21:33:15 2021 +0300

    aghtest: imp docs

commit 46f5b06f9743e800b489e8c30af07d24bfdcf989
Merge: bfb852cb 55d4c7ee
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Mar 10 21:32:32 2021 +0300

    Merge branch 'master' into 2275-upd

commit bfb852cbc74ec219a41e985f2dcb090d58299aee
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Mar 10 19:06:32 2021 +0300

    scripts: rem unsupported platform

commit c1645e247f18d384a980c60d3a94b9363f83f174
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Mar 10 18:47:57 2021 +0300

    all: rollback more

commit 989811b5e38498234dc11baf5dd153c76b9dada4
Merge: 976bdfbd 2d704242
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Mar 10 18:30:42 2021 +0300

    Merge branch 'master' into 2275-upd

commit 976bdfbdd44983f4cd657a486b94ff63f5885fd5
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Mar 10 18:28:23 2021 +0300

    aghtest: fix os_windows

commit 9e85080eefe882d72c939969f7008e3c46467c0c
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Mar 10 18:15:37 2021 +0300

    all: rewrite windows workaround, imp code, docs

commit 35a0b1d8656640a962fe9ae019c3d665f42707ce
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Jan 21 20:38:17 2021 +0300

    all: update go and backend tools
This commit is contained in:
Ainar Garipov
2021-03-11 12:17:54 +03:00
parent 55d4c7ee4f
commit c08bf86b71
24 changed files with 849 additions and 185 deletions

View File

@@ -45,8 +45,7 @@ type RequestFilteringSettings struct {
// Resolver is the interface for net.Resolver to simplify testing.
type Resolver interface {
// TODO(e.burkov): Replace with LookupIP after upgrading go to v1.15.
LookupIPAddr(ctx context.Context, host string) (ips []net.IPAddr, err error)
LookupIP(ctx context.Context, network, host string) (ips []net.IP, err error)
}
// Config allows you to configure DNS filtering with New() or just change variables directly.

View File

@@ -250,7 +250,9 @@ func TestCheckHostSafeSearchGoogle(t *testing.T) {
res, err := d.CheckHost(host, dns.TypeA, &setts)
assert.Nil(t, err)
assert.True(t, res.IsFiltered)
assert.Len(t, res.Rules, 1)
if assert.Len(t, res.Rules, 1) {
assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0")
}
})
}
}
@@ -306,15 +308,16 @@ func TestSafeSearchCacheGoogle(t *testing.T) {
safeDomain, ok := d.SafeSearchDomain(domain)
assert.Truef(t, ok, "Failed to get safesearch domain for %s", domain)
ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain)
ips, err := resolver.LookupIP(context.Background(), "ip", safeDomain)
if err != nil {
t.Fatalf("Failed to lookup for %s", safeDomain)
}
ip := ipAddrs[0].IP
for _, ipAddr := range ipAddrs {
if ipAddr.IP.To4() != nil {
ip = ipAddr.IP
var ip net.IP
for _, foundIP := range ips {
if foundIP.To4() != nil {
ip = foundIP
break
}
}
@@ -378,8 +381,8 @@ func TestMatching(t *testing.T) {
name string
rules string
host string
wantIsFiltered bool
wantReason Reason
wantIsFiltered bool
wantDNSType uint16
}{{
name: "sanity",

View File

@@ -102,21 +102,23 @@ func (d *DNSFilter) checkSafeSearch(host string) (Result, error) {
return res, nil
}
ipAddrs, err := d.resolver.LookupIPAddr(context.Background(), safeHost)
ips, err := d.resolver.LookupIP(context.Background(), "ip", safeHost)
if err != nil {
log.Tracef("SafeSearchDomain for %s was found but failed to lookup for %s cause %s", host, safeHost, err)
return Result{}, err
}
for _, ipAddr := range ipAddrs {
if ipv4 := ipAddr.IP.To4(); ipv4 != nil {
res.Rules[0].IP = ipv4
l := d.setCacheResult(gctx.safeSearchCache, host, res)
log.Debug("SafeSearch: stored in cache: %s (%d bytes)", host, l)
return res, nil
for _, ip := range ips {
if ip = ip.To4(); ip == nil {
continue
}
res.Rules[0].IP = ip
l := d.setCacheResult(gctx.safeSearchCache, host, res)
log.Debug("SafeSearch: stored in cache: %s (%d bytes)", host, l)
return res, nil
}
return Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", safeHost)