2022-09-25 16:16:48 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/netip"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
|
|
|
"github.com/sagernet/sing-box/option"
|
2024-11-18 18:59:19 +08:00
|
|
|
"github.com/sagernet/sing/common"
|
|
|
|
"github.com/sagernet/sing/common/json/badoption"
|
2022-09-25 16:16:48 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestShadowsocksObfs(t *testing.T) {
|
|
|
|
for _, mode := range []string{
|
|
|
|
"http", "tls",
|
|
|
|
} {
|
|
|
|
t.Run("obfs-local "+mode, func(t *testing.T) {
|
|
|
|
testShadowsocksPlugin(t, "obfs-local", "obfs="+mode, "--plugin obfs-server --plugin-opts obfs="+mode)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-11 14:03:55 +08:00
|
|
|
// Since I can't test this on m1 mac (rosetta error: bss_size overflow), I don't care about it
|
|
|
|
func _TestShadowsocksV2RayPlugin(t *testing.T) {
|
2022-09-25 16:16:48 +08:00
|
|
|
testShadowsocksPlugin(t, "v2ray-plugin", "", "--plugin v2ray-plugin --plugin-opts=server")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testShadowsocksPlugin(t *testing.T, name string, opts string, args string) {
|
|
|
|
startDockerContainer(t, DockerOptions{
|
|
|
|
Image: ImageShadowsocksLegacy,
|
|
|
|
Ports: []uint16{serverPort, testPort},
|
|
|
|
Env: []string{
|
|
|
|
"SS_MODULE=ss-server",
|
|
|
|
"SS_CONFIG=-s 0.0.0.0 -u -p 10000 -m chacha20-ietf-poly1305 -k FzcLbKs2dY9mhL " + args,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
startInstance(t, option.Options{
|
2024-11-18 18:59:19 +08:00
|
|
|
Inbounds: []option.Inbound{
|
2022-09-25 16:16:48 +08:00
|
|
|
{
|
|
|
|
Type: C.TypeMixed,
|
2024-11-18 18:59:19 +08:00
|
|
|
Options: &option.HTTPMixedInboundOptions{
|
2022-09-25 16:16:48 +08:00
|
|
|
ListenOptions: option.ListenOptions{
|
2024-11-18 18:59:19 +08:00
|
|
|
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
|
2022-09-25 16:16:48 +08:00
|
|
|
ListenPort: clientPort,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-18 18:59:19 +08:00
|
|
|
Outbounds: []option.Outbound{
|
2022-09-25 16:16:48 +08:00
|
|
|
{
|
|
|
|
Type: C.TypeShadowsocks,
|
2024-11-18 18:59:19 +08:00
|
|
|
Options: &option.ShadowsocksOutboundOptions{
|
2022-09-25 16:16:48 +08:00
|
|
|
ServerOptions: option.ServerOptions{
|
|
|
|
Server: "127.0.0.1",
|
|
|
|
ServerPort: serverPort,
|
|
|
|
},
|
|
|
|
Method: "chacha20-ietf-poly1305",
|
|
|
|
Password: "FzcLbKs2dY9mhL",
|
|
|
|
Plugin: name,
|
|
|
|
PluginOptions: opts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testSuitSimple(t, clientPort, testPort)
|
|
|
|
}
|