2019-09-18 08:44:27 -07:00
|
|
|
package home
|
|
|
|
|
|
|
|
import (
|
2021-01-26 09:44:19 -07:00
|
|
|
"context"
|
2019-09-18 08:44:27 -07:00
|
|
|
"testing"
|
|
|
|
|
2020-10-30 03:32:02 -07:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
2019-09-18 08:44:27 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-27 04:54:31 -07:00
|
|
|
func prepareTestDNSServer() error {
|
|
|
|
config.DNS.Port = 1234
|
2020-06-23 02:13:13 -07:00
|
|
|
Context.dnsServer = dnsforward.NewServer(dnsforward.DNSCreateParams{})
|
2020-05-27 04:54:31 -07:00
|
|
|
conf := &dnsforward.ServerConfig{}
|
2020-06-17 14:36:19 -07:00
|
|
|
conf.UpstreamDNS = []string{"8.8.8.8"}
|
2021-02-04 10:35:13 -07:00
|
|
|
|
2020-05-27 04:54:31 -07:00
|
|
|
return Context.dnsServer.Prepare(conf)
|
|
|
|
}
|
|
|
|
|
2021-02-04 10:35:13 -07:00
|
|
|
// TODO(e.burkov): It's kind of complicated to get rid of network access in this
|
|
|
|
// test. The thing is that *Whois creates new *net.Dialer each time it requests
|
|
|
|
// the server, so it becomes hard to simulate handling of request from test even
|
|
|
|
// with substituted upstream. However, it must be done.
|
2019-09-18 08:44:27 -07:00
|
|
|
func TestWhois(t *testing.T) {
|
2020-06-17 14:36:19 -07:00
|
|
|
assert.Nil(t, prepareTestDNSServer())
|
2020-05-27 04:54:31 -07:00
|
|
|
|
2019-10-07 09:13:06 -07:00
|
|
|
w := Whois{timeoutMsec: 5000}
|
2021-01-26 09:44:19 -07:00
|
|
|
resp, err := w.queryAll(context.Background(), "8.8.8.8")
|
2020-06-11 05:39:54 -07:00
|
|
|
assert.Nil(t, err)
|
2019-09-18 08:44:27 -07:00
|
|
|
m := whoisParse(resp)
|
2020-06-11 05:39:54 -07:00
|
|
|
assert.Equal(t, "Google LLC", m["orgname"])
|
|
|
|
assert.Equal(t, "US", m["country"])
|
|
|
|
assert.Equal(t, "Mountain View", m["city"])
|
2019-09-18 08:44:27 -07:00
|
|
|
}
|