2022-06-02 11:51:21 +02:00
|
|
|
package netx
|
2021-02-02 12:05:47 +01:00
|
|
|
|
|
|
|
import (
|
2021-09-05 19:55:28 +02:00
|
|
|
"context"
|
2021-02-02 12:05:47 +01:00
|
|
|
"crypto/tls"
|
|
|
|
"errors"
|
2021-09-05 19:55:28 +02:00
|
|
|
"net"
|
2021-02-02 12:05:47 +01:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
2021-06-22 13:00:29 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/bytecounter"
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
2022-01-05 17:17:20 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2022-06-02 17:39:48 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/filtering"
|
2022-06-02 00:50:55 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/tracex"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewResolverVanilla(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
r := NewResolver(Config{})
|
2022-01-07 18:33:37 +01:00
|
|
|
ir, ok := r.(*netxlite.ResolverIDNA)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ewr, ok := ir.Resolver.(*netxlite.ErrorWrapperResolver)
|
2021-09-05 18:03:50 +02:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ar, ok := ewr.Resolver.(*netxlite.AddressResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 09:59:44 +02:00
|
|
|
_, ok = ar.Resolver.(*netxlite.ResolverSystemDoNotInstantiate)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewResolverSpecificResolver(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
r := NewResolver(Config{
|
2022-05-31 08:11:07 +02:00
|
|
|
BaseResolver: &netxlite.BogonResolver{
|
2021-02-02 12:05:47 +01:00
|
|
|
// not initialized because it doesn't matter in this context
|
|
|
|
},
|
|
|
|
})
|
2022-01-07 18:33:37 +01:00
|
|
|
ir, ok := r.(*netxlite.ResolverIDNA)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ewr, ok := ir.Resolver.(*netxlite.ErrorWrapperResolver)
|
2021-09-05 18:03:50 +02:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ar, ok := ewr.Resolver.(*netxlite.AddressResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-05-31 08:11:07 +02:00
|
|
|
_, ok = ar.Resolver.(*netxlite.BogonResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewResolverWithBogonFilter(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
r := NewResolver(Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
BogonIsError: true,
|
|
|
|
})
|
2022-01-07 18:33:37 +01:00
|
|
|
ir, ok := r.(*netxlite.ResolverIDNA)
|
2021-09-05 18:03:50 +02:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ewr, ok := ir.Resolver.(*netxlite.ErrorWrapperResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-05-31 08:11:07 +02:00
|
|
|
br, ok := ewr.Resolver.(*netxlite.BogonResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ar, ok := br.Resolver.(*netxlite.AddressResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 09:59:44 +02:00
|
|
|
_, ok = ar.Resolver.(*netxlite.ResolverSystemDoNotInstantiate)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewResolverWithLogging(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
r := NewResolver(Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
Logger: log.Log,
|
|
|
|
})
|
2022-01-07 18:33:37 +01:00
|
|
|
ir, ok := r.(*netxlite.ResolverIDNA)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
lr, ok := ir.Resolver.(*netxlite.ResolverLogger)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
if lr.Logger != log.Log {
|
|
|
|
t.Fatal("not the logger we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ewr, ok := lr.Resolver.(*netxlite.ErrorWrapperResolver)
|
2021-09-05 18:03:50 +02:00
|
|
|
if !ok {
|
2022-01-07 18:33:37 +01:00
|
|
|
t.Fatalf("not the resolver we expected")
|
2021-09-05 18:03:50 +02:00
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ar, ok := ewr.Resolver.(*netxlite.AddressResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 09:59:44 +02:00
|
|
|
_, ok = ar.Resolver.(*netxlite.ResolverSystemDoNotInstantiate)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewResolverWithSaver(t *testing.T) {
|
2022-05-31 21:53:01 +02:00
|
|
|
saver := new(tracex.Saver)
|
2022-06-02 11:51:21 +02:00
|
|
|
r := NewResolver(Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
ResolveSaver: saver,
|
|
|
|
})
|
2022-01-07 18:33:37 +01:00
|
|
|
ir, ok := r.(*netxlite.ResolverIDNA)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 23:15:47 +02:00
|
|
|
sr, ok := ir.Resolver.(*tracex.ResolverSaver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
if sr.Saver != saver {
|
|
|
|
t.Fatal("not the saver we expected")
|
|
|
|
}
|
2022-01-07 17:31:21 +01:00
|
|
|
ewr, ok := sr.Resolver.(*netxlite.ErrorWrapperResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ar, ok := ewr.Resolver.(*netxlite.AddressResolver)
|
2021-09-09 20:21:43 +02:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 09:59:44 +02:00
|
|
|
_, ok = ar.Resolver.(*netxlite.ResolverSystemDoNotInstantiate)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewResolverWithReadWriteCache(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
r := NewResolver(Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
CacheResolutions: true,
|
|
|
|
})
|
2022-01-07 18:33:37 +01:00
|
|
|
ir, ok := r.(*netxlite.ResolverIDNA)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ewr, ok := ir.Resolver.(*netxlite.ErrorWrapperResolver)
|
2021-09-05 18:03:50 +02:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-02 11:51:21 +02:00
|
|
|
cr, ok := ewr.Resolver.(*CacheResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
if cr.ReadOnly != false {
|
|
|
|
t.Fatal("expected readwrite cache here")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ar, ok := cr.Resolver.(*netxlite.AddressResolver)
|
2021-03-08 12:05:43 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 09:59:44 +02:00
|
|
|
_, ok = ar.Resolver.(*netxlite.ResolverSystemDoNotInstantiate)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewResolverWithPrefilledReadonlyCache(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
r := NewResolver(Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
DNSCache: map[string][]string{
|
|
|
|
"dns.google.com": {"8.8.8.8"},
|
|
|
|
},
|
|
|
|
})
|
2022-01-07 18:33:37 +01:00
|
|
|
ir, ok := r.(*netxlite.ResolverIDNA)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ewr, ok := ir.Resolver.(*netxlite.ErrorWrapperResolver)
|
2021-09-05 18:03:50 +02:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-02 11:51:21 +02:00
|
|
|
cr, ok := ewr.Resolver.(*CacheResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
if cr.ReadOnly != true {
|
|
|
|
t.Fatal("expected readonly cache here")
|
|
|
|
}
|
|
|
|
if cr.Get("dns.google.com")[0] != "8.8.8.8" {
|
|
|
|
t.Fatal("cache not correctly prefilled")
|
|
|
|
}
|
2022-01-07 18:33:37 +01:00
|
|
|
ar, ok := cr.Resolver.(*netxlite.AddressResolver)
|
2021-03-08 12:05:43 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 09:59:44 +02:00
|
|
|
_, ok = ar.Resolver.(*netxlite.ResolverSystemDoNotInstantiate)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-02 17:39:48 +02:00
|
|
|
func TestNewTLSDialer(t *testing.T) {
|
|
|
|
t.Run("we always have error wrapping", func(t *testing.T) {
|
|
|
|
server := filtering.NewTLSServer(filtering.TLSActionReset)
|
|
|
|
defer server.Close()
|
|
|
|
tdx := NewTLSDialer(Config{})
|
|
|
|
conn, err := tdx.DialTLSContext(context.Background(), "tcp", server.Endpoint())
|
|
|
|
if err == nil || err.Error() != netxlite.FailureConnectionReset {
|
|
|
|
t.Fatal("unexpected err", err)
|
|
|
|
}
|
|
|
|
if conn != nil {
|
|
|
|
t.Fatal("expected nil conn")
|
|
|
|
}
|
|
|
|
})
|
2021-02-02 12:05:47 +01:00
|
|
|
|
2022-06-02 17:39:48 +02:00
|
|
|
t.Run("we can collect TLS measurements", func(t *testing.T) {
|
|
|
|
server := filtering.NewTLSServer(filtering.TLSActionReset)
|
|
|
|
defer server.Close()
|
|
|
|
saver := &tracex.Saver{}
|
|
|
|
tdx := NewTLSDialer(Config{
|
|
|
|
TLSSaver: saver,
|
|
|
|
})
|
|
|
|
conn, err := tdx.DialTLSContext(context.Background(), "tcp", server.Endpoint())
|
|
|
|
if err == nil || err.Error() != netxlite.FailureConnectionReset {
|
|
|
|
t.Fatal("unexpected err", err)
|
|
|
|
}
|
|
|
|
if conn != nil {
|
|
|
|
t.Fatal("expected nil conn")
|
|
|
|
}
|
|
|
|
if len(saver.Read()) <= 0 {
|
|
|
|
t.Fatal("did not read any event")
|
|
|
|
}
|
2021-02-02 12:05:47 +01:00
|
|
|
})
|
|
|
|
|
2022-06-02 17:39:48 +02:00
|
|
|
t.Run("we can collect dial measurements", func(t *testing.T) {
|
|
|
|
server := filtering.NewTLSServer(filtering.TLSActionReset)
|
|
|
|
defer server.Close()
|
|
|
|
saver := &tracex.Saver{}
|
|
|
|
tdx := NewTLSDialer(Config{
|
|
|
|
DialSaver: saver,
|
|
|
|
})
|
|
|
|
conn, err := tdx.DialTLSContext(context.Background(), "tcp", server.Endpoint())
|
|
|
|
if err == nil || err.Error() != netxlite.FailureConnectionReset {
|
|
|
|
t.Fatal("unexpected err", err)
|
|
|
|
}
|
|
|
|
if conn != nil {
|
|
|
|
t.Fatal("expected nil conn")
|
|
|
|
}
|
|
|
|
if len(saver.Read()) <= 0 {
|
|
|
|
t.Fatal("did not read any event")
|
|
|
|
}
|
2021-02-02 12:05:47 +01:00
|
|
|
})
|
|
|
|
|
2022-06-02 17:39:48 +02:00
|
|
|
t.Run("we can collect I/O measurements", func(t *testing.T) {
|
|
|
|
server := filtering.NewTLSServer(filtering.TLSActionReset)
|
|
|
|
defer server.Close()
|
|
|
|
saver := &tracex.Saver{}
|
|
|
|
tdx := NewTLSDialer(Config{
|
|
|
|
ReadWriteSaver: saver,
|
|
|
|
})
|
|
|
|
conn, err := tdx.DialTLSContext(context.Background(), "tcp", server.Endpoint())
|
|
|
|
if err == nil || err.Error() != netxlite.FailureConnectionReset {
|
|
|
|
t.Fatal("unexpected err", err)
|
|
|
|
}
|
|
|
|
if conn != nil {
|
|
|
|
t.Fatal("expected nil conn")
|
|
|
|
}
|
|
|
|
if len(saver.Read()) <= 0 {
|
|
|
|
t.Fatal("did not read any event")
|
|
|
|
}
|
2021-02-02 12:05:47 +01:00
|
|
|
})
|
|
|
|
|
2022-06-02 17:39:48 +02:00
|
|
|
t.Run("we can skip TLS verification", func(t *testing.T) {
|
|
|
|
server := filtering.NewTLSServer(filtering.TLSActionBlockText)
|
|
|
|
defer server.Close()
|
|
|
|
tdx := NewTLSDialer(Config{NoTLSVerify: true})
|
|
|
|
conn, err := tdx.DialTLSContext(context.Background(), "tcp", server.Endpoint())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.(*netxlite.ErrWrapper).WrappedErr)
|
|
|
|
}
|
|
|
|
conn.Close()
|
2021-02-02 12:05:47 +01:00
|
|
|
})
|
|
|
|
|
2022-06-02 17:39:48 +02:00
|
|
|
t.Run("we can set the cert pool", func(t *testing.T) {
|
|
|
|
server := filtering.NewTLSServer(filtering.TLSActionBlockText)
|
|
|
|
defer server.Close()
|
|
|
|
tdx := NewTLSDialer(Config{
|
|
|
|
CertPool: server.CertPool(),
|
|
|
|
TLSConfig: &tls.Config{
|
|
|
|
ServerName: "dns.google",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
conn, err := tdx.DialTLSContext(context.Background(), "tcp", server.Endpoint())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
conn.Close()
|
2021-02-02 12:05:47 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewVanilla(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
txp := NewHTTPTransport(Config{})
|
2022-05-31 08:11:07 +02:00
|
|
|
if _, ok := txp.(*netxlite.HTTPTransportWrapper); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewWithDialer(t *testing.T) {
|
|
|
|
expected := errors.New("mocked error")
|
2022-06-02 11:51:21 +02:00
|
|
|
dialer := &mocks.Dialer{
|
|
|
|
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
|
|
|
return nil, expected
|
|
|
|
},
|
|
|
|
}
|
|
|
|
txp := NewHTTPTransport(Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
Dialer: dialer,
|
|
|
|
})
|
|
|
|
client := &http.Client{Transport: txp}
|
|
|
|
resp, err := client.Get("http://www.google.com")
|
|
|
|
if !errors.Is(err, expected) {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
|
|
|
if resp != nil {
|
|
|
|
t.Fatal("not the response we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewWithByteCounter(t *testing.T) {
|
|
|
|
counter := bytecounter.New()
|
2022-06-02 11:51:21 +02:00
|
|
|
txp := NewHTTPTransport(Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
ByteCounter: counter,
|
|
|
|
})
|
2022-05-31 08:11:07 +02:00
|
|
|
bctxp, ok := txp.(*bytecounter.HTTPTransport)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
if bctxp.Counter != counter {
|
|
|
|
t.Fatal("not the byte counter we expected")
|
|
|
|
}
|
2022-05-31 08:11:07 +02:00
|
|
|
if _, ok := bctxp.HTTPTransport.(*netxlite.HTTPTransportWrapper); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewWithLogger(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
txp := NewHTTPTransport(Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
Logger: log.Log,
|
|
|
|
})
|
fix(netxlite): do not mutate outgoing requests (#508)
I have recently seen a data race related our way of
mutating the outgoing request to set the host header.
Unfortunately, I've lost track of the race output,
because I rebooted my Linux box before saving it.
Though, after inspecting why and and where we're mutating
outgoing requets, I've found that:
1. we add the host header when logging to have it logged,
which is not a big deal since we already emit the URL
rather than just the URL path when logging a request, and
so we can safely zap this piece of code;
2. as a result, in measurements we may omit the host header
but again this is pretty much obvious from the URL itself
and so it should not be very important (nonetheless,
avoid surprises and keep the existing behavior);
3. when the User-Agent header is not set, we default to
a `miniooni/0.1.0-dev` user agent, which is probably not
very useful anyway, so we can actually remove it.
Part of https://github.com/ooni/probe/issues/1733 (this diff
has been extracted from https://github.com/ooni/probe-cli/pull/506).
2021-09-27 13:35:47 +02:00
|
|
|
ltxp, ok := txp.(*netxlite.HTTPTransportLogger)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
if ltxp.Logger != log.Log {
|
|
|
|
t.Fatal("not the logger we expected")
|
|
|
|
}
|
2022-05-31 08:11:07 +02:00
|
|
|
if _, ok := ltxp.HTTPTransport.(*netxlite.HTTPTransportWrapper); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewWithSaver(t *testing.T) {
|
2022-05-31 21:53:01 +02:00
|
|
|
saver := new(tracex.Saver)
|
2022-06-02 11:51:21 +02:00
|
|
|
txp := NewHTTPTransport(Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
HTTPSaver: saver,
|
|
|
|
})
|
2022-06-01 23:15:47 +02:00
|
|
|
stxptxp, ok := txp.(*tracex.HTTPTransportSaver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
if stxptxp.Saver != saver {
|
|
|
|
t.Fatal("not the logger we expected")
|
|
|
|
}
|
2022-06-01 19:27:47 +02:00
|
|
|
if stxptxp.Saver != saver {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the logger we expected")
|
|
|
|
}
|
2022-06-01 19:27:47 +02:00
|
|
|
if _, ok := stxptxp.HTTPTransport.(*netxlite.HTTPTransportWrapper); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientInvalidURL(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(Config{}, "\t\t\t")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
if dnsclient != nil {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("expected nil resolver here")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientUnsupportedScheme(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(Config{}, "antani:///")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err == nil || err.Error() != "unsupported resolver scheme" {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
if dnsclient != nil {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("expected nil resolver here")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientSystemResolver(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{}, "system:///")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-06-01 09:59:44 +02:00
|
|
|
if _, ok := dnsclient.(*netxlite.ResolverSystemDoNotInstantiate); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientEmpty(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{}, "")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-06-01 09:59:44 +02:00
|
|
|
if _, ok := dnsclient.(*netxlite.ResolverSystemDoNotInstantiate); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientPowerdnsDoH(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{}, "doh://powerdns")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
if _, ok := r.Transport().(*netxlite.DNSOverHTTPSTransport); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientGoogleDoH(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{}, "doh://google")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
if _, ok := r.Transport().(*netxlite.DNSOverHTTPSTransport); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientCloudflareDoH(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{}, "doh://cloudflare")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
if _, ok := r.Transport().(*netxlite.DNSOverHTTPSTransport); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientCloudflareDoHSaver(t *testing.T) {
|
2022-05-31 21:53:01 +02:00
|
|
|
saver := new(tracex.Saver)
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{ResolveSaver: saver}, "doh://cloudflare")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 23:15:47 +02:00
|
|
|
txp, ok := r.Transport().(*tracex.DNSTransportSaver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
if _, ok := txp.DNSTransport.(*netxlite.DNSOverHTTPSTransport); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientUDP(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{}, "udp://8.8.8.8:53")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
if _, ok := r.Transport().(*netxlite.DNSOverUDPTransport); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientUDPDNSSaver(t *testing.T) {
|
2022-05-31 21:53:01 +02:00
|
|
|
saver := new(tracex.Saver)
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{ResolveSaver: saver}, "udp://8.8.8.8:53")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 23:15:47 +02:00
|
|
|
txp, ok := r.Transport().(*tracex.DNSTransportSaver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
if _, ok := txp.DNSTransport.(*netxlite.DNSOverUDPTransport); !ok {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientTCP(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{}, "tcp://8.8.8.8:53")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
txp, ok := r.Transport().(*netxlite.DNSOverTCPTransport)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
if txp.Network() != "tcp" {
|
|
|
|
t.Fatal("not the Network we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientTCPDNSSaver(t *testing.T) {
|
2022-05-31 21:53:01 +02:00
|
|
|
saver := new(tracex.Saver)
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{ResolveSaver: saver}, "tcp://8.8.8.8:53")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 23:15:47 +02:00
|
|
|
txp, ok := r.Transport().(*tracex.DNSTransportSaver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
dotcp, ok := txp.DNSTransport.(*netxlite.DNSOverTCPTransport)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
if dotcp.Network() != "tcp" {
|
|
|
|
t.Fatal("not the Network we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientDoT(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{}, "dot://8.8.8.8:53")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
txp, ok := r.Transport().(*netxlite.DNSOverTCPTransport)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
if txp.Network() != "dot" {
|
|
|
|
t.Fatal("not the Network we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientDoTDNSSaver(t *testing.T) {
|
2022-05-31 21:53:01 +02:00
|
|
|
saver := new(tracex.Saver)
|
2022-06-02 11:51:21 +02:00
|
|
|
dnsclient, err := NewDNSClient(
|
|
|
|
Config{ResolveSaver: saver}, "dot://8.8.8.8:53")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
r, ok := dnsclient.(*netxlite.SerialResolver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the resolver we expected")
|
|
|
|
}
|
2022-06-01 23:15:47 +02:00
|
|
|
txp, ok := r.Transport().(*tracex.DNSTransportSaver)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
2022-05-14 17:38:31 +02:00
|
|
|
dotls, ok := txp.DNSTransport.(*netxlite.DNSOverTCPTransport)
|
2021-02-02 12:05:47 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("not the transport we expected")
|
|
|
|
}
|
|
|
|
if dotls.Network() != "dot" {
|
|
|
|
t.Fatal("not the Network we expected")
|
|
|
|
}
|
|
|
|
dnsclient.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSCLientDoTWithoutPort(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
c, err := NewDNSClientWithOverrides(
|
|
|
|
Config{}, "dot://8.8.8.8", "", "8.8.8.8", "")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
if c.Address() != "8.8.8.8:853" {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("expected default port to be added")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSCLientTCPWithoutPort(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
c, err := NewDNSClientWithOverrides(
|
|
|
|
Config{}, "tcp://8.8.8.8", "", "8.8.8.8", "")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
if c.Address() != "8.8.8.8:53" {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("expected default port to be added")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSCLientUDPWithoutPort(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
c, err := NewDNSClientWithOverrides(
|
|
|
|
Config{}, "udp://8.8.8.8", "", "8.8.8.8", "")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-01-10 11:53:06 +01:00
|
|
|
if c.Address() != "8.8.8.8:53" {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("expected default port to be added")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientBadDoTEndpoint(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
_, err := NewDNSClient(
|
|
|
|
Config{}, "dot://bad:endpoint:53")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err == nil || !strings.Contains(err.Error(), "too many colons in address") {
|
|
|
|
t.Fatal("expected error with bad endpoint")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientBadTCPEndpoint(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
_, err := NewDNSClient(
|
|
|
|
Config{}, "tcp://bad:endpoint:853")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err == nil || !strings.Contains(err.Error(), "too many colons in address") {
|
|
|
|
t.Fatal("expected error with bad endpoint")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSClientBadUDPEndpoint(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
_, err := NewDNSClient(
|
|
|
|
Config{}, "udp://bad:endpoint:853")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err == nil || !strings.Contains(err.Error(), "too many colons in address") {
|
|
|
|
t.Fatal("expected error with bad endpoint")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSCLientWithInvalidTLSVersion(t *testing.T) {
|
2022-06-02 11:51:21 +02:00
|
|
|
_, err := NewDNSClientWithOverrides(
|
|
|
|
Config{}, "dot://8.8.8.8", "", "", "TLSv999")
|
2021-06-25 12:39:45 +02:00
|
|
|
if !errors.Is(err, netxlite.ErrInvalidTLSVersion) {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatalf("not the error we expected: %+v", err)
|
|
|
|
}
|
|
|
|
}
|
2022-06-02 11:51:21 +02:00
|
|
|
|
|
|
|
func TestSuccess(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skip test in short mode")
|
|
|
|
}
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
counter := bytecounter.New()
|
|
|
|
config := Config{
|
|
|
|
BogonIsError: true,
|
|
|
|
ByteCounter: counter,
|
|
|
|
CacheResolutions: true,
|
|
|
|
ContextByteCounting: true,
|
|
|
|
DialSaver: &tracex.Saver{},
|
|
|
|
HTTPSaver: &tracex.Saver{},
|
|
|
|
Logger: log.Log,
|
|
|
|
ReadWriteSaver: &tracex.Saver{},
|
|
|
|
ResolveSaver: &tracex.Saver{},
|
|
|
|
TLSSaver: &tracex.Saver{},
|
|
|
|
}
|
|
|
|
txp := NewHTTPTransport(config)
|
|
|
|
client := &http.Client{Transport: txp}
|
|
|
|
resp, err := client.Get("https://www.google.com")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if _, err = netxlite.ReadAllContext(context.Background(), resp.Body); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = resp.Body.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if counter.Sent.Load() <= 0 {
|
|
|
|
t.Fatal("no bytes sent?!")
|
|
|
|
}
|
|
|
|
if counter.Received.Load() <= 0 {
|
|
|
|
t.Fatal("no bytes received?!")
|
|
|
|
}
|
|
|
|
if ev := config.DialSaver.Read(); len(ev) <= 0 {
|
|
|
|
t.Fatal("no dial events?!")
|
|
|
|
}
|
|
|
|
if ev := config.HTTPSaver.Read(); len(ev) <= 0 {
|
|
|
|
t.Fatal("no HTTP events?!")
|
|
|
|
}
|
|
|
|
if ev := config.ReadWriteSaver.Read(); len(ev) <= 0 {
|
|
|
|
t.Fatal("no R/W events?!")
|
|
|
|
}
|
|
|
|
if ev := config.ResolveSaver.Read(); len(ev) <= 0 {
|
|
|
|
t.Fatal("no resolver events?!")
|
|
|
|
}
|
|
|
|
if ev := config.TLSSaver.Read(); len(ev) <= 0 {
|
|
|
|
t.Fatal("no TLS events?!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBogonResolutionNotBroken(t *testing.T) {
|
|
|
|
saver := new(tracex.Saver)
|
|
|
|
r := NewResolver(Config{
|
|
|
|
BogonIsError: true,
|
|
|
|
DNSCache: map[string][]string{
|
|
|
|
"www.google.com": {"127.0.0.1"},
|
|
|
|
},
|
|
|
|
ResolveSaver: saver,
|
|
|
|
Logger: log.Log,
|
|
|
|
})
|
|
|
|
addrs, err := r.LookupHost(context.Background(), "www.google.com")
|
|
|
|
if !errors.Is(err, netxlite.ErrDNSBogon) {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
|
|
|
if err.Error() != netxlite.FailureDNSBogonError {
|
|
|
|
t.Fatal("error not correctly wrapped")
|
|
|
|
}
|
|
|
|
if len(addrs) > 0 {
|
|
|
|
t.Fatal("expected no addresses here")
|
|
|
|
}
|
|
|
|
}
|