mux_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 TestShadowsocksMux(t *testing.T) {
  10. method := shadowaead_2022.List[0]
  11. password := mkBase64(t, 16)
  12. startInstance(t, option.Options{
  13. Log: &option.LogOptions{
  14. Level: "error",
  15. },
  16. Inbounds: []option.Inbound{
  17. {
  18. Type: C.TypeMixed,
  19. Tag: "mixed-in",
  20. MixedOptions: option.HTTPMixedInboundOptions{
  21. ListenOptions: option.ListenOptions{
  22. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  23. ListenPort: clientPort,
  24. },
  25. },
  26. },
  27. {
  28. Type: C.TypeShadowsocks,
  29. ShadowsocksOptions: option.ShadowsocksInboundOptions{
  30. ListenOptions: option.ListenOptions{
  31. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  32. ListenPort: serverPort,
  33. },
  34. Method: method,
  35. Password: password,
  36. },
  37. },
  38. },
  39. Outbounds: []option.Outbound{
  40. {
  41. Type: C.TypeDirect,
  42. },
  43. {
  44. Type: C.TypeShadowsocks,
  45. Tag: "ss-out",
  46. ShadowsocksOptions: option.ShadowsocksOutboundOptions{
  47. ServerOptions: option.ServerOptions{
  48. Server: "127.0.0.1",
  49. ServerPort: serverPort,
  50. },
  51. Method: method,
  52. Password: password,
  53. Multiplex: &option.MultiplexOptions{
  54. Enabled: true,
  55. },
  56. },
  57. },
  58. },
  59. Route: &option.RouteOptions{
  60. Rules: []option.Rule{
  61. {
  62. DefaultOptions: option.DefaultRule{
  63. Inbound: []string{"mixed-in"},
  64. Outbound: "ss-out",
  65. },
  66. },
  67. },
  68. },
  69. })
  70. testSuit(t, clientPort, testPort)
  71. }