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"
|
2021-03-25 16:00:27 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-09-18 18:44:27 +03:00
|
|
|
)
|
|
|
|
|
2021-03-25 16:00:27 +03:00
|
|
|
func prepareTestDNSServer(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
|
2020-05-27 14:54:31 +03:00
|
|
|
config.DNS.Port = 1234
|
2021-03-25 16:00:27 +03:00
|
|
|
|
|
|
|
var err error
|
|
|
|
Context.dnsServer, err = dnsforward.NewServer(dnsforward.DNSCreateParams{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
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
|
|
|
|
2021-03-25 16:00:27 +03:00
|
|
|
err = Context.dnsServer.Prepare(conf)
|
|
|
|
require.NoError(t, err)
|
2020-05-27 14:54:31 +03:00
|
|
|
}
|
|
|
|
|
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) {
|
2021-03-25 16:00:27 +03:00
|
|
|
prepareTestDNSServer(t)
|
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")
|
2021-03-25 16:00:27 +03:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-09-18 18:44:27 +03:00
|
|
|
m := whoisParse(resp)
|
2021-03-25 16:00:27 +03:00
|
|
|
require.NotEmpty(t, m)
|
|
|
|
|
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
|
|
|
}
|