1
0

inbound_detour_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. "github.com/sagernet/sing/common"
  9. "github.com/sagernet/sing/common/json/badoption"
  10. )
  11. func TestChainedInbound(t *testing.T) {
  12. method := shadowaead_2022.List[0]
  13. password := mkBase64(t, 16)
  14. startInstance(t, option.Options{
  15. Inbounds: []option.Inbound{
  16. {
  17. Type: C.TypeMixed,
  18. Tag: "mixed-in",
  19. Options: &option.HTTPMixedInboundOptions{
  20. ListenOptions: option.ListenOptions{
  21. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  22. ListenPort: clientPort,
  23. },
  24. },
  25. },
  26. {
  27. Type: C.TypeShadowsocks,
  28. Options: &option.ShadowsocksInboundOptions{
  29. ListenOptions: option.ListenOptions{
  30. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  31. ListenPort: serverPort,
  32. InboundOptions: option.InboundOptions{
  33. Detour: "detour",
  34. },
  35. },
  36. Method: method,
  37. Password: password,
  38. },
  39. },
  40. {
  41. Type: C.TypeShadowsocks,
  42. Tag: "detour",
  43. Options: &option.ShadowsocksInboundOptions{
  44. ListenOptions: option.ListenOptions{
  45. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  46. ListenPort: otherPort,
  47. },
  48. Method: method,
  49. Password: password,
  50. },
  51. },
  52. },
  53. Outbounds: []option.Outbound{
  54. {
  55. Type: C.TypeDirect,
  56. },
  57. {
  58. Type: C.TypeShadowsocks,
  59. Tag: "ss-out",
  60. Options: &option.ShadowsocksOutboundOptions{
  61. Method: method,
  62. Password: password,
  63. DialerOptions: option.DialerOptions{
  64. Detour: "detour-out",
  65. },
  66. },
  67. },
  68. {
  69. Type: C.TypeShadowsocks,
  70. Tag: "detour-out",
  71. Options: &option.ShadowsocksOutboundOptions{
  72. ServerOptions: option.ServerOptions{
  73. Server: "127.0.0.1",
  74. ServerPort: serverPort,
  75. },
  76. Method: method,
  77. Password: password,
  78. },
  79. },
  80. },
  81. Route: &option.RouteOptions{
  82. Rules: []option.Rule{
  83. {
  84. Type: C.RuleTypeDefault,
  85. DefaultOptions: option.DefaultRule{
  86. RawDefaultRule: option.RawDefaultRule{
  87. Inbound: []string{"mixed-in"},
  88. },
  89. RuleAction: option.RuleAction{
  90. Action: C.RuleActionTypeRoute,
  91. RouteOptions: option.RouteActionOptions{
  92. Outbound: "ss-out",
  93. },
  94. },
  95. },
  96. },
  97. },
  98. },
  99. })
  100. testTCP(t, clientPort, testPort)
  101. }