2019-09-18 15:44:27 +00:00
|
|
|
package home
|
|
|
|
|
|
|
|
import (
|
2021-01-26 16:44:19 +00:00
|
|
|
"context"
|
2019-09-18 15:44:27 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-10-30 10:32:02 +00:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
2019-09-18 15:44:27 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-03-25 13:00:27 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-09-18 15:44:27 +00:00
|
|
|
)
|
|
|
|
|
2021-03-25 13:00:27 +00:00
|
|
|
func prepareTestDNSServer(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
|
2020-05-27 11:54:31 +00:00
|
|
|
config.DNS.Port = 1234
|
2021-03-25 13:00:27 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
Context.dnsServer, err = dnsforward.NewServer(dnsforward.DNSCreateParams{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-05-27 11:54:31 +00:00
|
|
|
conf := &dnsforward.ServerConfig{}
|
2020-06-17 21:36:19 +00:00
|
|
|
conf.UpstreamDNS = []string{"8.8.8.8"}
|
2021-02-04 17:35:13 +00:00
|
|
|
|
2021-03-25 13:00:27 +00:00
|
|
|
err = Context.dnsServer.Prepare(conf)
|
|
|
|
require.NoError(t, err)
|
2020-05-27 11:54:31 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 17:35:13 +00: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 15:44:27 +00:00
|
|
|
func TestWhois(t *testing.T) {
|
2021-03-25 13:00:27 +00:00
|
|
|
prepareTestDNSServer(t)
|
2020-05-27 11:54:31 +00:00
|
|
|
|
2019-10-07 16:13:06 +00:00
|
|
|
w := Whois{timeoutMsec: 5000}
|
2021-01-26 16:44:19 +00:00
|
|
|
resp, err := w.queryAll(context.Background(), "8.8.8.8")
|
2021-03-25 13:00:27 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-09-18 15:44:27 +00:00
|
|
|
m := whoisParse(resp)
|
2021-03-25 13:00:27 +00:00
|
|
|
require.NotEmpty(t, m)
|
|
|
|
|
2020-06-11 12:39:54 +00:00
|
|
|
assert.Equal(t, "Google LLC", m["orgname"])
|
|
|
|
assert.Equal(t, "US", m["country"])
|
|
|
|
assert.Equal(t, "Mountain View", m["city"])
|
2019-09-18 15:44:27 +00:00
|
|
|
}
|