ss_plugin_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 TestShadowsocksObfs(t *testing.T) {
  9. for _, mode := range []string{
  10. "http", "tls",
  11. } {
  12. t.Run("obfs-local "+mode, func(t *testing.T) {
  13. testShadowsocksPlugin(t, "obfs-local", "obfs="+mode, "--plugin obfs-server --plugin-opts obfs="+mode)
  14. })
  15. }
  16. }
  17. func TestShadowsocksV2RayPlugin(t *testing.T) {
  18. testShadowsocksPlugin(t, "v2ray-plugin", "", "--plugin v2ray-plugin --plugin-opts=server")
  19. }
  20. func testShadowsocksPlugin(t *testing.T, name string, opts string, args string) {
  21. startDockerContainer(t, DockerOptions{
  22. Image: ImageShadowsocksLegacy,
  23. Ports: []uint16{serverPort, testPort},
  24. Env: []string{
  25. "SS_MODULE=ss-server",
  26. "SS_CONFIG=-s 0.0.0.0 -u -p 10000 -m chacha20-ietf-poly1305 -k FzcLbKs2dY9mhL " + args,
  27. },
  28. })
  29. startInstance(t, option.Options{
  30. Inbounds: []option.Inbound{
  31. {
  32. Type: C.TypeMixed,
  33. MixedOptions: option.HTTPMixedInboundOptions{
  34. ListenOptions: option.ListenOptions{
  35. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  36. ListenPort: clientPort,
  37. },
  38. },
  39. },
  40. },
  41. Outbounds: []option.Outbound{
  42. {
  43. Type: C.TypeShadowsocks,
  44. ShadowsocksOptions: option.ShadowsocksOutboundOptions{
  45. ServerOptions: option.ServerOptions{
  46. Server: "127.0.0.1",
  47. ServerPort: serverPort,
  48. },
  49. Method: "chacha20-ietf-poly1305",
  50. Password: "FzcLbKs2dY9mhL",
  51. Plugin: name,
  52. PluginOptions: opts,
  53. },
  54. },
  55. },
  56. })
  57. testSuitSimple(t, clientPort, testPort)
  58. }