Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

proxy_network_internal_test.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package network
  2. import (
  3. "context"
  4. "errors"
  5. "net"
  6. "testing"
  7. "time"
  8. )
  9. // Regression test for https://github.com/9seconds/mtg/issues/439: the dialer
  10. // used to reach a SOCKS upstream must not inherit the user-supplied DoT/DoH
  11. // resolver, otherwise internal names (docker compose, k8s, /etc/hosts) fail
  12. // to resolve through a public resolver that does not know them.
  13. func TestProxyServerDialerDropsCustomResolver(t *testing.T) {
  14. customResolver := &net.Resolver{
  15. PreferGo: true,
  16. Dial: func(_ context.Context, _, _ string) (net.Conn, error) {
  17. return nil, errors.New("custom resolver must not be queried for SOCKS upstream")
  18. },
  19. }
  20. base := New(
  21. customResolver,
  22. "mtg-test",
  23. 7*time.Second,
  24. 0,
  25. 0,
  26. DefaultKeepAliveConfig,
  27. )
  28. if base.NativeDialer().Resolver != customResolver {
  29. t.Fatalf("base.NativeDialer().Resolver = %v, want custom resolver", base.NativeDialer().Resolver)
  30. }
  31. d := proxyServerDialer(base)
  32. if d.Resolver != nil {
  33. t.Errorf("proxyServerDialer().Resolver = %v, want nil (must use OS resolver)", d.Resolver)
  34. }
  35. if d.Timeout != base.NativeDialer().Timeout {
  36. t.Errorf("proxyServerDialer().Timeout = %v, want %v", d.Timeout, base.NativeDialer().Timeout)
  37. }
  38. if d.FallbackDelay != base.NativeDialer().FallbackDelay {
  39. t.Errorf("proxyServerDialer().FallbackDelay = %v, want %v", d.FallbackDelay, base.NativeDialer().FallbackDelay)
  40. }
  41. }