direct_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package main
  2. import (
  3. "net/netip"
  4. "testing"
  5. C "github.com/sagernet/sing-box/constant"
  6. "github.com/sagernet/sing-box/option"
  7. )
  8. func TestProxyProtocol(t *testing.T) {
  9. startInstance(t, option.Options{
  10. Log: &option.LogOptions{
  11. Level: "error",
  12. },
  13. Inbounds: []option.Inbound{
  14. {
  15. Type: C.TypeMixed,
  16. Tag: "mixed-in",
  17. MixedOptions: option.HTTPMixedInboundOptions{
  18. ListenOptions: option.ListenOptions{
  19. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  20. ListenPort: clientPort,
  21. },
  22. },
  23. },
  24. {
  25. Type: C.TypeDirect,
  26. DirectOptions: option.DirectInboundOptions{
  27. ListenOptions: option.ListenOptions{
  28. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  29. ListenPort: serverPort,
  30. ProxyProtocol: true,
  31. },
  32. },
  33. },
  34. },
  35. Outbounds: []option.Outbound{
  36. {
  37. Type: C.TypeDirect,
  38. },
  39. {
  40. Type: C.TypeDirect,
  41. Tag: "trojan-out",
  42. DirectOptions: option.DirectOutboundOptions{
  43. OverrideAddress: "127.0.0.1",
  44. OverridePort: serverPort,
  45. ProxyProtocol: 2,
  46. },
  47. },
  48. },
  49. Route: &option.RouteOptions{
  50. Rules: []option.Rule{
  51. {
  52. DefaultOptions: option.DefaultRule{
  53. Inbound: []string{"mixed-in"},
  54. Outbound: "trojan-out",
  55. },
  56. },
  57. },
  58. },
  59. })
  60. testSuit(t, clientPort, testPort)
  61. }