* whois: use the upstream server to resolve whois server hostname

Close #1535

Squashed commit of the following:

commit 7755d7a50e48db5d341029e1c21da95a396d9090
Merge: e24e945f 5c2ca690
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Wed May 27 14:41:24 2020 +0300

    Merge remote-tracking branch 'origin/master' into 1535-whois-resolve

commit e24e945f9b949e3cabcddb3a8a62962bb7a5b0b9
Merge: db764710 355e634f
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Wed May 27 14:29:44 2020 +0300

    Merge remote-tracking branch 'origin/master' into 1535-whois-resolve

commit db764710a0f0b60293f7bdf6b0d7b858d56819e0
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Wed May 27 12:57:00 2020 +0300

    fix

commit dc38f668d5845cfd696b3107a8f02dda4f10298e
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Wed May 27 12:44:10 2020 +0300

    * whois: use the upstream server to resolve whois server hostname
This commit is contained in:
Simon Zolin 2020-05-27 14:54:31 +03:00
parent 5c2ca69018
commit 391e619979
2 changed files with 20 additions and 1 deletions

View file

@ -1,6 +1,7 @@
package home
import (
"context"
"encoding/binary"
"fmt"
"io/ioutil"
@ -120,7 +121,7 @@ func (w *Whois) query(target string, serverAddr string) (string, error) {
if addr == "whois.arin.net" {
target = "n + " + target
}
conn, err := net.DialTimeout("tcp", serverAddr, time.Duration(w.timeoutMsec)*time.Millisecond)
conn, err := customDialContext(context.TODO(), "tcp", serverAddr)
if err != nil {
return "", err
}

View file

@ -2,11 +2,29 @@ package home
import (
"testing"
"time"
"github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/stretchr/testify/assert"
)
func prepareTestDNSServer() error {
config.DNS.Port = 1234
Context.dnsServer = dnsforward.NewServer(nil, nil, nil)
conf := &dnsforward.ServerConfig{}
uc, err := proxy.ParseUpstreamsConfig([]string{"1.1.1.1"}, nil, time.Second*5)
if err != nil {
return err
}
conf.UpstreamConfig = &uc
return Context.dnsServer.Prepare(conf)
}
func TestWhois(t *testing.T) {
err := prepareTestDNSServer()
assert.Nil(t, err)
w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8")
assert.True(t, err == nil)