2019-09-18 18:44:27 +03:00
|
|
|
package home
|
|
|
|
|
|
|
|
import (
|
2021-01-26 19:44:19 +03:00
|
|
|
"context"
|
2019-09-18 18:44:27 +03:00
|
|
|
"testing"
|
|
|
|
|
2020-10-30 13:32:02 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
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
|
2020-06-23 12:13:13 +03:00
|
|
|
Context.dnsServer = dnsforward.NewServer(dnsforward.DNSCreateParams{})
|
2020-05-27 14:54:31 +03:00
|
|
|
conf := &dnsforward.ServerConfig{}
|
2020-06-18 00:36:19 +03:00
|
|
|
conf.UpstreamDNS = []string{"8.8.8.8"}
|
2021-02-04 20:35:13 +03:00
|
|
|
|
2020-05-27 14:54:31 +03:00
|
|
|
return Context.dnsServer.Prepare(conf)
|
|
|
|
}
|
|
|
|
|
2021-02-04 20:35:13 +03: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 18:44:27 +03:00
|
|
|
func TestWhois(t *testing.T) {
|
2020-06-18 00:36:19 +03:00
|
|
|
assert.Nil(t, prepareTestDNSServer())
|
2020-05-27 14:54:31 +03:00
|
|
|
|
2019-10-07 19:13:06 +03:00
|
|
|
w := Whois{timeoutMsec: 5000}
|
2021-01-26 19:44:19 +03:00
|
|
|
resp, err := w.queryAll(context.Background(), "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
|
|
|
}
|