ss_plugin_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/common"
  8. "github.com/sagernet/sing/common/json/badoption"
  9. )
  10. func TestShadowsocksObfs(t *testing.T) {
  11. for _, mode := range []string{
  12. "http", "tls",
  13. } {
  14. t.Run("obfs-local "+mode, func(t *testing.T) {
  15. testShadowsocksPlugin(t, "obfs-local", "obfs="+mode, "--plugin obfs-server --plugin-opts obfs="+mode)
  16. })
  17. }
  18. }
  19. // Since I can't test this on m1 mac (rosetta error: bss_size overflow), I don't care about it
  20. func _TestShadowsocksV2RayPlugin(t *testing.T) {
  21. testShadowsocksPlugin(t, "v2ray-plugin", "", "--plugin v2ray-plugin --plugin-opts=server")
  22. }
  23. func testShadowsocksPlugin(t *testing.T, name string, opts string, args string) {
  24. startDockerContainer(t, DockerOptions{
  25. Image: ImageShadowsocksLegacy,
  26. Ports: []uint16{serverPort, testPort},
  27. Env: []string{
  28. "SS_MODULE=ss-server",
  29. "SS_CONFIG=-s 0.0.0.0 -u -p 10000 -m chacha20-ietf-poly1305 -k FzcLbKs2dY9mhL " + args,
  30. },
  31. })
  32. startInstance(t, option.Options{
  33. Inbounds: []option.Inbound{
  34. {
  35. Type: C.TypeMixed,
  36. Options: &option.HTTPMixedInboundOptions{
  37. ListenOptions: option.ListenOptions{
  38. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  39. ListenPort: clientPort,
  40. },
  41. },
  42. },
  43. },
  44. Outbounds: []option.Outbound{
  45. {
  46. Type: C.TypeShadowsocks,
  47. Options: &option.ShadowsocksOutboundOptions{
  48. ServerOptions: option.ServerOptions{
  49. Server: "127.0.0.1",
  50. ServerPort: serverPort,
  51. },
  52. Method: "chacha20-ietf-poly1305",
  53. Password: "FzcLbKs2dY9mhL",
  54. Plugin: name,
  55. PluginOptions: opts,
  56. },
  57. },
  58. },
  59. })
  60. testSuitSimple(t, clientPort, testPort)
  61. }