Skip to content

Commit

Permalink
* whois: use the upstream server to resolve whois server hostname
Browse files Browse the repository at this point in the history
Close AdguardTeam#1535

Squashed commit of the following:

commit 7755d7a
Merge: e24e945 5c2ca69
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 e24e945
Merge: db76471 355e634
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 db76471
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Wed May 27 12:57:00 2020 +0300

    fix

commit dc38f66
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
  • Loading branch information
szolin committed May 27, 2020
1 parent 5c2ca69 commit 391e619
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion home/whois.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package home

import (
"context"
"encoding/binary"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions home/whois_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 391e619

Please sign in to comment.