Skip to content

Commit

Permalink
Pull request: AGDNS-2202-slog-imp-tests
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit d4ebf59
Merge: 63104ef 50640fb
Author: Dimitry Kolyshev <[email protected]>
Date:   Wed Jul 17 13:31:08 2024 +0300

    Merge remote-tracking branch 'origin/master' into AGDNS-2202-slog-imp-tests

commit 63104ef
Author: Dimitry Kolyshev <[email protected]>
Date:   Wed Jul 17 12:20:02 2024 +0300

    proxy: imp tests

commit 22fdf0c
Author: Dimitry Kolyshev <[email protected]>
Date:   Wed Jul 17 11:13:51 2024 +0300

    upstream: imp tests

commit 5ec8863
Author: Dimitry Kolyshev <[email protected]>
Date:   Wed Jul 17 11:13:23 2024 +0300

    proxy: imp tests
  • Loading branch information
Mizzick committed Jul 17, 2024
1 parent 50640fb commit 07b8131
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions proxy/beforerequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/miekg/dns"
Expand Down Expand Up @@ -52,6 +53,7 @@ func TestProxy_HandleDNSRequest_beforeRequestHandler(t *testing.T) {
errorResponse := (&dns.Msg{}).SetReply(errorRequest)

p := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: &UpstreamConfig{
Upstreams: []upstream.Upstream{&fakeUpstream{
Expand Down
2 changes: 2 additions & 0 deletions proxy/bogusnxdomain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
Expand All @@ -15,6 +16,7 @@ import (

func TestProxy_IsBogusNXDomain(t *testing.T) {
prx := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down
3 changes: 3 additions & 0 deletions proxy/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var upstreamWithAddr = &fakeUpstream{

func TestServeCached(t *testing.T) {
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down Expand Up @@ -288,6 +289,7 @@ func TestCacheExpiration(t *testing.T) {
t.Parallel()

dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down Expand Up @@ -347,6 +349,7 @@ func TestCacheExpirationWithTTLOverride(t *testing.T) {
u := testUpstream{}

dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: &UpstreamConfig{
Expand Down
3 changes: 3 additions & 0 deletions proxy/dns64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/miekg/dns"
Expand Down Expand Up @@ -38,6 +39,7 @@ func TestDNS64Race(t *testing.T) {
}

dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
PrivateSubnets: netutil.SubnetSetFunc(netutil.IsLocallyServed),
Expand Down Expand Up @@ -355,6 +357,7 @@ func TestProxy_Resolve_dns64(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
p := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: &UpstreamConfig{
Expand Down
2 changes: 2 additions & 0 deletions proxy/exchange_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/netutil"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -215,6 +216,7 @@ func TestProxy_Exchange_loadBalance(t *testing.T) {
}

p := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: &UpstreamConfig{
Expand Down
2 changes: 2 additions & 0 deletions proxy/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"
"testing"

"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
Expand All @@ -19,6 +20,7 @@ func TestFilteringHandler(t *testing.T) {

// Prepare the proxy server
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down
1 change: 1 addition & 0 deletions proxy/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestLookupNetIP(t *testing.T) {
require.NoError(t, err)

conf := &Config{
Logger: slogutil.NewDiscardLogger(),
UpstreamConfig: &UpstreamConfig{
Upstreams: []upstream.Upstream{dnsUpstream},
},
Expand Down
13 changes: 13 additions & 0 deletions proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func mustStartDefaultProxy(t *testing.T) (p *Proxy) {
t.Helper()

p = mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down Expand Up @@ -288,6 +289,7 @@ func TestProxyRace(t *testing.T) {
testDefaultUpstreamAddr,
)
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: upsConf,
Expand Down Expand Up @@ -487,6 +489,7 @@ func TestProxy_Resolve_dnssecCache(t *testing.T) {
}

p := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: &UpstreamConfig{Upstreams: []upstream.Upstream{u}},
Expand Down Expand Up @@ -583,6 +586,7 @@ func TestExchangeWithReservedDomains(t *testing.T) {
t.Parallel()

dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfigWithBoot(
Expand Down Expand Up @@ -652,6 +656,7 @@ func TestOneByOneUpstreamsExchange(t *testing.T) {
t.Parallel()

dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfigWithBoot(
Expand Down Expand Up @@ -745,6 +750,7 @@ func TestFallback(t *testing.T) {
}).String()

dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(
Expand Down Expand Up @@ -842,6 +848,7 @@ func TestFallbackFromInvalidBootstrap(t *testing.T) {
require.NoError(t, err)

dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: upsConf,
Expand Down Expand Up @@ -883,6 +890,7 @@ func TestFallbackFromInvalidBootstrap(t *testing.T) {

func TestRefuseAny(t *testing.T) {
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down Expand Up @@ -921,6 +929,7 @@ func TestRefuseAny(t *testing.T) {

func TestInvalidDNSRequest(t *testing.T) {
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down Expand Up @@ -1093,6 +1102,7 @@ func TestExchangeCustomUpstreamConfig(t *testing.T) {

func TestExchangeCustomUpstreamConfigCache(t *testing.T) {
prx := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down Expand Up @@ -1224,6 +1234,7 @@ func TestECSProxy(t *testing.T) {
}

prx := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: &UpstreamConfig{
Expand Down Expand Up @@ -1333,6 +1344,7 @@ func TestECSProxyCacheMinMaxTTL(t *testing.T) {
}

prx := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: &UpstreamConfig{Upstreams: []upstream.Upstream{u}},
Expand Down Expand Up @@ -1576,6 +1588,7 @@ func TestProxy_HandleDNSRequest_private(t *testing.T) {
}

p := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: &UpstreamConfig{
Upstreams: []upstream.Upstream{generalUps},
Expand Down
2 changes: 2 additions & 0 deletions proxy/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"net/netip"
"testing"

"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/miekg/dns"
"github.com/stretchr/testify/require"
)

func TestRatelimitingProxy(t *testing.T) {
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down
7 changes: 7 additions & 0 deletions proxy/server_dnscrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import (
"testing"
"time"

"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/ameshkov/dnscrypt/v2"
"github.com/ameshkov/dnsstamps"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TODO(d.kolyshev): Remove this after migrating dnscrypt to slog.
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}

func getFreePort() uint {
l, _ := net.Listen("tcp", "127.0.0.1:0")
port := uint(l.Addr().(*net.TCPAddr).Port)
Expand All @@ -35,6 +41,7 @@ func createTestDNSCryptProxy(t *testing.T) (*Proxy, dnscrypt.ResolverConfig) {

port := getFreePort()
p := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
DNSCryptUDPListenAddr: []*net.UDPAddr{{
Port: int(port), IP: net.ParseIP(listenIP),
}},
Expand Down
2 changes: 2 additions & 0 deletions proxy/server_https_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestHttpsProxy(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
tlsConf, caPem := newTLSConfig(t)
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
TLSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
HTTPSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
Expand Down Expand Up @@ -80,6 +81,7 @@ func TestProxy_trustedProxies(t *testing.T) {
// Prepare the proxy server.
tlsConf, caPem := newTLSConfig(t)
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
TLSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
HTTPSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
Expand Down
3 changes: 3 additions & 0 deletions proxy/server_quic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/AdguardTeam/dnsproxy/proxyutil"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/miekg/dns"
"github.com/quic-go/quic-go"
Expand All @@ -28,6 +29,7 @@ func TestQuicProxy(t *testing.T) {
}

conf := &Config{
Logger: slogutil.NewDiscardLogger(),
QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
TLSConfig: serverConfig,
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
Expand Down Expand Up @@ -89,6 +91,7 @@ func TestQuicProxy(t *testing.T) {
func TestQuicProxy_largePackets(t *testing.T) {
serverConfig, caPem := newTLSConfig(t)
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
TLSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
HTTPSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
Expand Down
2 changes: 2 additions & 0 deletions proxy/server_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"testing"

"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/miekg/dns"
"github.com/stretchr/testify/require"
Expand All @@ -26,6 +27,7 @@ func TestTcpProxy(t *testing.T) {
func TestTlsProxy(t *testing.T) {
serverConfig, caPem := newTLSConfig(t)
dnsProxy := mustNew(t, &Config{
Logger: slogutil.NewDiscardLogger(),
TLSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
HTTPSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
Expand Down
1 change: 1 addition & 0 deletions upstream/upstream_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

// TODO(ameshkov): Make tests here not depend on external servers.

// TODO(d.kolyshev): Remove this after migrating dnscrypt to slog.
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
Expand Down

0 comments on commit 07b8131

Please sign in to comment.