2021-09-28 12:42:01 +02:00
|
|
|
package netxlite
|
2021-02-02 12:05:47 +01:00
|
|
|
|
|
|
|
import (
|
2021-09-09 21:24:27 +02:00
|
|
|
"bytes"
|
2021-02-02 12:05:47 +01:00
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"net"
|
|
|
|
"testing"
|
2021-09-09 21:24:27 +02:00
|
|
|
"time"
|
|
|
|
|
2021-09-28 12:42:01 +02:00
|
|
|
"github.com/apex/log"
|
2022-05-26 20:09:00 +02:00
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"github.com/miekg/dns"
|
2022-05-25 17:03:58 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
2022-05-26 20:09:00 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/filtering"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
2022-05-14 17:38:31 +02:00
|
|
|
func TestDNSOverUDPTransport(t *testing.T) {
|
2021-09-28 11:26:16 +02:00
|
|
|
t.Run("RoundTrip", func(t *testing.T) {
|
2022-05-25 17:03:58 +02:00
|
|
|
t.Run("cannot encode query", func(t *testing.T) {
|
|
|
|
expected := errors.New("mocked error")
|
|
|
|
const address = "9.9.9.9:53"
|
|
|
|
txp := NewDNSOverUDPTransport(nil, address)
|
|
|
|
query := &mocks.DNSQuery{
|
|
|
|
MockBytes: func() ([]byte, error) {
|
|
|
|
return nil, expected
|
|
|
|
},
|
|
|
|
}
|
|
|
|
resp, err := txp.RoundTrip(context.Background(), query)
|
|
|
|
if !errors.Is(err, expected) {
|
|
|
|
t.Fatal("unexpected err", err)
|
|
|
|
}
|
|
|
|
if resp != nil {
|
|
|
|
t.Fatal("expected nil response here")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-09-28 11:26:16 +02:00
|
|
|
t.Run("dial failure", func(t *testing.T) {
|
|
|
|
mocked := errors.New("mocked error")
|
|
|
|
const address = "9.9.9.9:53"
|
2022-05-14 17:38:31 +02:00
|
|
|
txp := NewDNSOverUDPTransport(&mocks.Dialer{
|
2021-09-28 11:26:16 +02:00
|
|
|
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
|
|
|
return nil, mocked
|
|
|
|
},
|
|
|
|
}, address)
|
2022-05-25 17:03:58 +02:00
|
|
|
query := &mocks.DNSQuery{
|
|
|
|
MockBytes: func() ([]byte, error) {
|
|
|
|
return make([]byte, 128), nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
resp, err := txp.RoundTrip(context.Background(), query)
|
2021-09-28 11:26:16 +02:00
|
|
|
if !errors.Is(err, mocked) {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
2022-05-25 17:03:58 +02:00
|
|
|
if resp != nil {
|
2021-09-28 11:26:16 +02:00
|
|
|
t.Fatal("expected no response here")
|
|
|
|
}
|
|
|
|
})
|
2021-02-02 12:05:47 +01:00
|
|
|
|
2022-05-25 17:03:58 +02:00
|
|
|
t.Run("Write failure", func(t *testing.T) {
|
2021-09-28 11:26:16 +02:00
|
|
|
mocked := errors.New("mocked error")
|
2022-05-14 17:38:31 +02:00
|
|
|
txp := NewDNSOverUDPTransport(
|
2021-09-28 11:26:16 +02:00
|
|
|
&mocks.Dialer{
|
|
|
|
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
|
|
|
return &mocks.Conn{
|
|
|
|
MockSetDeadline: func(t time.Time) error {
|
2022-05-25 17:03:58 +02:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
MockWrite: func(b []byte) (int, error) {
|
|
|
|
return 0, mocked
|
2021-09-28 11:26:16 +02:00
|
|
|
},
|
|
|
|
MockClose: func() error {
|
|
|
|
return nil
|
|
|
|
},
|
2022-05-26 20:09:00 +02:00
|
|
|
MockLocalAddr: func() net.Addr {
|
|
|
|
return &mocks.Addr{
|
|
|
|
MockNetwork: func() string {
|
|
|
|
return "udp"
|
|
|
|
},
|
|
|
|
MockString: func() string {
|
|
|
|
return "127.0.0.1:1345"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2021-09-28 11:26:16 +02:00
|
|
|
}, nil
|
2021-09-09 21:24:27 +02:00
|
|
|
},
|
2021-09-28 11:26:16 +02:00
|
|
|
}, "9.9.9.9:53",
|
|
|
|
)
|
2022-05-25 17:03:58 +02:00
|
|
|
query := &mocks.DNSQuery{
|
|
|
|
MockBytes: func() ([]byte, error) {
|
|
|
|
return make([]byte, 128), nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
resp, err := txp.RoundTrip(context.Background(), query)
|
2021-09-28 11:26:16 +02:00
|
|
|
if !errors.Is(err, mocked) {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
2022-05-25 17:03:58 +02:00
|
|
|
if resp != nil {
|
2021-09-28 11:26:16 +02:00
|
|
|
t.Fatal("expected no response here")
|
|
|
|
}
|
|
|
|
})
|
2021-02-02 12:05:47 +01:00
|
|
|
|
2022-05-25 17:03:58 +02:00
|
|
|
t.Run("Read failure", func(t *testing.T) {
|
2021-09-28 11:26:16 +02:00
|
|
|
mocked := errors.New("mocked error")
|
2022-05-14 17:38:31 +02:00
|
|
|
txp := NewDNSOverUDPTransport(
|
2021-09-28 11:26:16 +02:00
|
|
|
&mocks.Dialer{
|
|
|
|
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
|
|
|
return &mocks.Conn{
|
|
|
|
MockSetDeadline: func(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
MockWrite: func(b []byte) (int, error) {
|
2022-05-25 17:03:58 +02:00
|
|
|
return len(b), nil
|
|
|
|
},
|
|
|
|
MockRead: func(b []byte) (int, error) {
|
2021-09-28 11:26:16 +02:00
|
|
|
return 0, mocked
|
|
|
|
},
|
|
|
|
MockClose: func() error {
|
|
|
|
return nil
|
|
|
|
},
|
2022-05-26 20:09:00 +02:00
|
|
|
MockLocalAddr: func() net.Addr {
|
|
|
|
return &mocks.Addr{
|
|
|
|
MockNetwork: func() string {
|
|
|
|
return "udp"
|
|
|
|
},
|
|
|
|
MockString: func() string {
|
|
|
|
return "127.0.0.1:1345"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2021-09-28 11:26:16 +02:00
|
|
|
}, nil
|
2021-09-09 21:24:27 +02:00
|
|
|
},
|
2021-09-28 11:26:16 +02:00
|
|
|
}, "9.9.9.9:53",
|
|
|
|
)
|
2022-05-25 17:03:58 +02:00
|
|
|
query := &mocks.DNSQuery{
|
|
|
|
MockBytes: func() ([]byte, error) {
|
|
|
|
return make([]byte, 128), nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
resp, err := txp.RoundTrip(context.Background(), query)
|
2021-09-28 11:26:16 +02:00
|
|
|
if !errors.Is(err, mocked) {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
2022-05-25 17:03:58 +02:00
|
|
|
if resp != nil {
|
2021-09-28 11:26:16 +02:00
|
|
|
t.Fatal("expected no response here")
|
|
|
|
}
|
|
|
|
})
|
2021-02-02 12:05:47 +01:00
|
|
|
|
2022-05-25 17:03:58 +02:00
|
|
|
t.Run("decode failure", func(t *testing.T) {
|
|
|
|
const expected = 17
|
|
|
|
input := bytes.NewReader(make([]byte, expected))
|
2022-05-14 17:38:31 +02:00
|
|
|
txp := NewDNSOverUDPTransport(
|
2021-09-28 11:26:16 +02:00
|
|
|
&mocks.Dialer{
|
|
|
|
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
|
|
|
return &mocks.Conn{
|
|
|
|
MockSetDeadline: func(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
MockWrite: func(b []byte) (int, error) {
|
|
|
|
return len(b), nil
|
|
|
|
},
|
2022-05-25 17:03:58 +02:00
|
|
|
MockRead: input.Read,
|
2021-09-28 11:26:16 +02:00
|
|
|
MockClose: func() error {
|
|
|
|
return nil
|
|
|
|
},
|
2022-05-26 20:09:00 +02:00
|
|
|
MockLocalAddr: func() net.Addr {
|
|
|
|
return &mocks.Addr{
|
|
|
|
MockNetwork: func() string {
|
|
|
|
return "udp"
|
|
|
|
},
|
|
|
|
MockString: func() string {
|
|
|
|
return "127.0.0.1:1345"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2021-09-28 11:26:16 +02:00
|
|
|
}, nil
|
2021-09-09 21:24:27 +02:00
|
|
|
},
|
2021-09-28 11:26:16 +02:00
|
|
|
}, "9.9.9.9:53",
|
|
|
|
)
|
2022-05-25 17:03:58 +02:00
|
|
|
expectedErr := errors.New("mocked error")
|
2022-05-26 20:09:00 +02:00
|
|
|
txp.Decoder = &mocks.DNSDecoder{
|
2022-05-25 17:03:58 +02:00
|
|
|
MockDecodeResponse: func(data []byte, query model.DNSQuery) (model.DNSResponse, error) {
|
|
|
|
return nil, expectedErr
|
|
|
|
},
|
2021-09-28 11:26:16 +02:00
|
|
|
}
|
2022-05-25 17:03:58 +02:00
|
|
|
query := &mocks.DNSQuery{
|
|
|
|
MockBytes: func() ([]byte, error) {
|
|
|
|
return make([]byte, 128), nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
resp, err := txp.RoundTrip(context.Background(), query)
|
|
|
|
if !errors.Is(err, expectedErr) {
|
|
|
|
t.Fatal("unexpected err", err)
|
|
|
|
}
|
|
|
|
if resp != nil {
|
|
|
|
t.Fatal("expected nil resp")
|
2021-09-28 11:26:16 +02:00
|
|
|
}
|
|
|
|
})
|
2021-02-02 12:05:47 +01:00
|
|
|
|
2022-05-26 20:09:00 +02:00
|
|
|
t.Run("decode success", func(t *testing.T) {
|
2021-09-28 11:26:16 +02:00
|
|
|
const expected = 17
|
|
|
|
input := bytes.NewReader(make([]byte, expected))
|
2022-05-14 17:38:31 +02:00
|
|
|
txp := NewDNSOverUDPTransport(
|
2021-09-28 11:26:16 +02:00
|
|
|
&mocks.Dialer{
|
|
|
|
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
|
|
|
return &mocks.Conn{
|
|
|
|
MockSetDeadline: func(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
MockWrite: func(b []byte) (int, error) {
|
|
|
|
return len(b), nil
|
|
|
|
},
|
|
|
|
MockRead: input.Read,
|
|
|
|
MockClose: func() error {
|
|
|
|
return nil
|
|
|
|
},
|
2022-05-26 20:09:00 +02:00
|
|
|
MockLocalAddr: func() net.Addr {
|
|
|
|
return &mocks.Addr{
|
|
|
|
MockNetwork: func() string {
|
|
|
|
return "udp"
|
|
|
|
},
|
|
|
|
MockString: func() string {
|
|
|
|
return "127.0.0.1:1345"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2021-09-28 11:26:16 +02:00
|
|
|
}, nil
|
2021-09-09 21:24:27 +02:00
|
|
|
},
|
2021-09-28 11:26:16 +02:00
|
|
|
}, "9.9.9.9:53",
|
|
|
|
)
|
2022-05-25 17:03:58 +02:00
|
|
|
expectedResp := &mocks.DNSResponse{}
|
2022-05-26 20:09:00 +02:00
|
|
|
txp.Decoder = &mocks.DNSDecoder{
|
2022-05-25 17:03:58 +02:00
|
|
|
MockDecodeResponse: func(data []byte, query model.DNSQuery) (model.DNSResponse, error) {
|
|
|
|
return expectedResp, nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
query := &mocks.DNSQuery{
|
|
|
|
MockBytes: func() ([]byte, error) {
|
|
|
|
return make([]byte, 128), nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
resp, err := txp.RoundTrip(context.Background(), query)
|
2021-09-28 11:26:16 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-05-25 17:03:58 +02:00
|
|
|
if resp != expectedResp {
|
|
|
|
t.Fatal("unexpected resp")
|
2021-09-28 11:26:16 +02:00
|
|
|
}
|
|
|
|
})
|
2022-05-26 20:09:00 +02:00
|
|
|
|
|
|
|
t.Run("using a real server", func(t *testing.T) {
|
|
|
|
srvr := &filtering.DNSServer{
|
|
|
|
OnQuery: func(domain string) filtering.DNSAction {
|
|
|
|
return filtering.DNSActionCache
|
|
|
|
},
|
|
|
|
Cache: map[string][]string{
|
|
|
|
"dns.google.": {"8.8.8.8"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
listener, err := srvr.Start("127.0.0.1:0")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer listener.Close()
|
|
|
|
dialer := NewDialerWithoutResolver(model.DiscardLogger)
|
|
|
|
txp := NewDNSOverUDPTransport(dialer, listener.LocalAddr().String())
|
|
|
|
encoder := &DNSEncoderMiekg{}
|
|
|
|
query := encoder.Encode("dns.google.", dns.TypeA, false)
|
|
|
|
resp, err := txp.RoundTrip(context.Background(), query)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
addrs, err := resp.DecodeLookupHost()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(addrs, []string{"8.8.8.8"}); diff != "" {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("AsyncRoundTrip", func(t *testing.T) {
|
|
|
|
t.Run("calling Next with cancelled context", func(t *testing.T) {
|
2022-05-26 23:49:14 +02:00
|
|
|
srvr := &filtering.DNSServer{
|
|
|
|
OnQuery: func(domain string) filtering.DNSAction {
|
|
|
|
return filtering.DNSActionCache
|
2022-05-26 20:09:00 +02:00
|
|
|
},
|
2022-05-26 23:49:14 +02:00
|
|
|
Cache: map[string][]string{
|
|
|
|
"dns.google.": {"8.8.8.8"},
|
2022-05-26 20:09:00 +02:00
|
|
|
},
|
|
|
|
}
|
2022-05-26 23:49:14 +02:00
|
|
|
listener, err := srvr.Start("127.0.0.1:0")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer listener.Close()
|
|
|
|
dialer := NewDialerWithoutResolver(model.DiscardLogger)
|
|
|
|
txp := NewDNSOverUDPTransport(dialer, listener.LocalAddr().String())
|
|
|
|
encoder := &DNSEncoderMiekg{}
|
|
|
|
query := encoder.Encode("dns.google.", dns.TypeA, false)
|
|
|
|
ctx := context.Background()
|
|
|
|
rch, err := txp.AsyncRoundTrip(ctx, query, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer rch.Close()
|
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
|
|
cancel() // fail immediately
|
|
|
|
resp, err := rch.Next(ctx)
|
2022-05-26 20:09:00 +02:00
|
|
|
if !errors.Is(err, context.Canceled) {
|
|
|
|
t.Fatal("unexpected err", err)
|
|
|
|
}
|
|
|
|
if resp != nil {
|
|
|
|
t.Fatal("unexpected resp")
|
|
|
|
}
|
2022-05-26 23:49:14 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no-one is reading the channel", func(t *testing.T) {
|
|
|
|
srvr := &filtering.DNSServer{
|
|
|
|
OnQuery: func(domain string) filtering.DNSAction {
|
|
|
|
return filtering.DNSActionLocalHostPlusCache // i.e., two responses
|
|
|
|
},
|
|
|
|
Cache: map[string][]string{
|
|
|
|
"dns.google.": {"8.8.8.8"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
listener, err := srvr.Start("127.0.0.1:0")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer listener.Close()
|
|
|
|
dialer := NewDialerWithoutResolver(model.DiscardLogger)
|
|
|
|
txp := NewDNSOverUDPTransport(dialer, listener.LocalAddr().String())
|
|
|
|
encoder := &DNSEncoderMiekg{}
|
|
|
|
query := encoder.Encode("dns.google.", dns.TypeA, false)
|
|
|
|
ctx := context.Background()
|
|
|
|
rch, err := txp.AsyncRoundTrip(ctx, query, 1) // but just one place
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer rch.Close()
|
|
|
|
<-rch.Joined // should see no-one is reading and stop
|
2022-05-26 20:09:00 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("typical usage to obtain late responses", func(t *testing.T) {
|
|
|
|
srvr := &filtering.DNSServer{
|
|
|
|
OnQuery: func(domain string) filtering.DNSAction {
|
|
|
|
return filtering.DNSActionLocalHostPlusCache
|
|
|
|
},
|
|
|
|
Cache: map[string][]string{
|
|
|
|
"dns.google.": {"8.8.8.8"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
listener, err := srvr.Start("127.0.0.1:0")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer listener.Close()
|
|
|
|
dialer := NewDialerWithoutResolver(model.DiscardLogger)
|
|
|
|
txp := NewDNSOverUDPTransport(dialer, listener.LocalAddr().String())
|
|
|
|
encoder := &DNSEncoderMiekg{}
|
|
|
|
query := encoder.Encode("dns.google.", dns.TypeA, false)
|
2022-05-26 23:49:14 +02:00
|
|
|
rch, err := txp.AsyncRoundTrip(context.Background(), query, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer rch.Close()
|
2022-05-26 20:09:00 +02:00
|
|
|
resp, err := rch.Next(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
addrs, err := resp.DecodeLookupHost()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(addrs, []string{"127.0.0.1"}); diff != "" {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
// One would not normally busy loop but it's fine to do that in the context
|
|
|
|
// of this test because we know we're going to receive a second reply. In
|
|
|
|
// a real network experiment here we'll do other activities, e.g., contacting
|
|
|
|
// the test helper or fetching a webpage.
|
|
|
|
var additional []model.DNSResponse
|
|
|
|
for {
|
|
|
|
additional = rch.TryNextResponses()
|
|
|
|
if len(additional) > 0 {
|
|
|
|
if len(additional) != 1 {
|
|
|
|
t.Fatal("expected exactly one additional response")
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addrs, err = additional[0].DecodeLookupHost()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(addrs, []string{"8.8.8.8"}); diff != "" {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("correct behavior when read times out", func(t *testing.T) {
|
|
|
|
srvr := &filtering.DNSServer{
|
|
|
|
OnQuery: func(domain string) filtering.DNSAction {
|
|
|
|
return filtering.DNSActionTimeout
|
|
|
|
},
|
|
|
|
}
|
|
|
|
listener, err := srvr.Start("127.0.0.1:0")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer listener.Close()
|
|
|
|
dialer := NewDialerWithoutResolver(model.DiscardLogger)
|
|
|
|
txp := NewDNSOverUDPTransport(dialer, listener.LocalAddr().String())
|
|
|
|
txp.IOTimeout = 30 * time.Millisecond // short timeout to have a fast test
|
|
|
|
encoder := &DNSEncoderMiekg{}
|
|
|
|
query := encoder.Encode("dns.google.", dns.TypeA, false)
|
2022-05-26 23:49:14 +02:00
|
|
|
rch, err := txp.AsyncRoundTrip(context.Background(), query, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer rch.Close()
|
2022-05-26 20:09:00 +02:00
|
|
|
result := <-rch.Response
|
|
|
|
if result.Err == nil || result.Err.Error() != "generic_timeout_error" {
|
|
|
|
t.Fatal("unexpected error", result.Err)
|
|
|
|
}
|
|
|
|
if result.Operation != ReadOperation {
|
|
|
|
t.Fatal("unexpected failed operation", result.Operation)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("CloseIdleConnections", func(t *testing.T) {
|
|
|
|
var called bool
|
|
|
|
dialer := &mocks.Dialer{
|
|
|
|
MockCloseIdleConnections: func() {
|
|
|
|
called = true
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const address = "9.9.9.9:53"
|
|
|
|
txp := NewDNSOverUDPTransport(dialer, address)
|
|
|
|
txp.CloseIdleConnections()
|
|
|
|
if !called {
|
|
|
|
t.Fatal("not called")
|
|
|
|
}
|
2021-09-28 11:26:16 +02:00
|
|
|
})
|
2021-02-02 12:05:47 +01:00
|
|
|
|
2021-09-28 11:26:16 +02:00
|
|
|
t.Run("other functions okay", func(t *testing.T) {
|
|
|
|
const address = "9.9.9.9:53"
|
2022-05-14 17:38:31 +02:00
|
|
|
txp := NewDNSOverUDPTransport(NewDialerWithoutResolver(log.Log), address)
|
2021-09-28 11:26:16 +02:00
|
|
|
if txp.RequiresPadding() != false {
|
|
|
|
t.Fatal("invalid RequiresPadding")
|
|
|
|
}
|
|
|
|
if txp.Network() != "udp" {
|
|
|
|
t.Fatal("invalid Network")
|
|
|
|
}
|
|
|
|
if txp.Address() != address {
|
|
|
|
t.Fatal("invalid Address")
|
|
|
|
}
|
|
|
|
})
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|