inbound_detour_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. "github.com/sagernet/sing-shadowsocks/shadowaead_2022"
  8. )
  9. func TestChainedInbound(t *testing.T) {
  10. method := shadowaead_2022.List[0]
  11. password := mkBase64(t, 16)
  12. startInstance(t, option.Options{
  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.TypeShadowsocks,
  26. ShadowsocksOptions: option.ShadowsocksInboundOptions{
  27. ListenOptions: option.ListenOptions{
  28. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  29. ListenPort: serverPort,
  30. Detour: "detour",
  31. },
  32. Method: method,
  33. Password: password,
  34. },
  35. },
  36. {
  37. Type: C.TypeShadowsocks,
  38. Tag: "detour",
  39. ShadowsocksOptions: option.ShadowsocksInboundOptions{
  40. ListenOptions: option.ListenOptions{
  41. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  42. ListenPort: otherPort,
  43. },
  44. Method: method,
  45. Password: password,
  46. },
  47. },
  48. },
  49. Outbounds: []option.Outbound{
  50. {
  51. Type: C.TypeDirect,
  52. },
  53. {
  54. Type: C.TypeShadowsocks,
  55. Tag: "ss-out",
  56. ShadowsocksOptions: option.ShadowsocksOutboundOptions{
  57. Method: method,
  58. Password: password,
  59. DialerOptions: option.DialerOptions{
  60. Detour: "detour-out",
  61. },
  62. },
  63. },
  64. {
  65. Type: C.TypeShadowsocks,
  66. Tag: "detour-out",
  67. ShadowsocksOptions: option.ShadowsocksOutboundOptions{
  68. ServerOptions: option.ServerOptions{
  69. Server: "127.0.0.1",
  70. ServerPort: serverPort,
  71. },
  72. Method: method,
  73. Password: password,
  74. },
  75. },
  76. },
  77. Route: &option.RouteOptions{
  78. Rules: []option.Rule{
  79. {
  80. DefaultOptions: option.DefaultRule{
  81. Inbound: []string{"mixed-in"},
  82. Outbound: "ss-out",
  83. },
  84. },
  85. },
  86. },
  87. })
  88. testTCP(t, clientPort, testPort)
  89. }