2019-09-18 18:44:27 +03:00
|
|
|
package home
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-05-27 14:54:31 +03:00
|
|
|
"time"
|
2019-09-18 18:44:27 +03:00
|
|
|
|
2020-05-27 14:54:31 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/dnsforward"
|
|
|
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
2019-09-18 18:44:27 +03:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-27 14:54:31 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-09-18 18:44:27 +03:00
|
|
|
func TestWhois(t *testing.T) {
|
2020-05-27 14:54:31 +03:00
|
|
|
err := prepareTestDNSServer()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2019-10-07 19:13:06 +03:00
|
|
|
w := Whois{timeoutMsec: 5000}
|
|
|
|
resp, err := w.queryAll("8.8.8.8")
|
2020-06-11 15:39:54 +03:00
|
|
|
assert.Nil(t, err)
|
2019-09-18 18:44:27 +03:00
|
|
|
m := whoisParse(resp)
|
2020-06-11 15:39:54 +03:00
|
|
|
assert.Equal(t, "Google LLC", m["orgname"])
|
|
|
|
assert.Equal(t, "US", m["country"])
|
|
|
|
assert.Equal(t, "Mountain View", m["city"])
|
2019-09-18 18:44:27 +03:00
|
|
|
}
|