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