ss_plugin_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // Since I can't test this on m1 mac (rosetta error: bss_size overflow), I don't care about it
  18. func _TestShadowsocksV2RayPlugin(t *testing.T) {
  19. testShadowsocksPlugin(t, "v2ray-plugin", "", "--plugin v2ray-plugin --plugin-opts=server")
  20. }
  21. func testShadowsocksPlugin(t *testing.T, name string, opts string, args string) {
  22. startDockerContainer(t, DockerOptions{
  23. Image: ImageShadowsocksLegacy,
  24. Ports: []uint16{serverPort, testPort},
  25. Env: []string{
  26. "SS_MODULE=ss-server",
  27. "SS_CONFIG=-s 0.0.0.0 -u -p 10000 -m chacha20-ietf-poly1305 -k FzcLbKs2dY9mhL " + args,
  28. },
  29. })
  30. startInstance(t, option.Options{
  31. Inbounds: []option.Inbound{
  32. {
  33. Type: C.TypeMixed,
  34. MixedOptions: option.HTTPMixedInboundOptions{
  35. ListenOptions: option.ListenOptions{
  36. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  37. ListenPort: clientPort,
  38. },
  39. },
  40. },
  41. },
  42. Outbounds: []option.Outbound{
  43. {
  44. Type: C.TypeShadowsocks,
  45. ShadowsocksOptions: option.ShadowsocksOutboundOptions{
  46. ServerOptions: option.ServerOptions{
  47. Server: "127.0.0.1",
  48. ServerPort: serverPort,
  49. },
  50. Method: "chacha20-ietf-poly1305",
  51. Password: "FzcLbKs2dY9mhL",
  52. Plugin: name,
  53. PluginOptions: opts,
  54. },
  55. },
  56. },
  57. })
  58. testSuitSimple(t, clientPort, testPort)
  59. }