From 9a55213ddc1efcd90f1f7ca2d0fde8e4f34469a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 9 Jun 2022 18:10:00 +0800 Subject: [PATCH] chore: add more shadowsocks tests --- test/ss_test.go | 100 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 5 deletions(-) diff --git a/test/ss_test.go b/test/ss_test.go index 0fef6364..dec98ed4 100644 --- a/test/ss_test.go +++ b/test/ss_test.go @@ -1,6 +1,8 @@ package main import ( + "crypto/rand" + "encoding/base64" "net" "testing" "time" @@ -11,10 +13,66 @@ import ( ) func TestClash_Shadowsocks(t *testing.T) { + for _, method := range []string{ + "aes-128-ctr", + "aes-192-ctr", + "aes-256-ctr", + "aes-128-cfb", + "aes-192-cfb", + "aes-256-cfb", + "rc4-md5", + "chacha20-ietf", + "aes-128-gcm", + "aes-256-gcm", + "chacha20-ietf-poly1305", + "xchacha20-ietf-poly1305", + } { + t.Run(method, func(t *testing.T) { + testClash_Shadowsocks(t, method, "FzcLbKs2dY9mhL") + }) + } + for _, method := range []string{ + "aes-128-gcm", + "aes-256-gcm", + "chacha20-ietf-poly1305", + } { + t.Run(method, func(t *testing.T) { + testClash_ShadowsocksRust(t, method, "FzcLbKs2dY9mhL") + }) + } +} + +func TestClash_Shadowsocks2022(t *testing.T) { + for _, method := range []string{ + "2022-blake3-aes-128-gcm", + } { + t.Run(method, func(t *testing.T) { + testClash_ShadowsocksRust(t, method, mkKey(16)) + }) + } + for _, method := range []string{ + "2022-blake3-aes-256-gcm", + "2022-blake3-chacha20-poly1305", + } { + t.Run(method, func(t *testing.T) { + testClash_ShadowsocksRust(t, method, mkKey(32)) + }) + } +} + +func mkKey(bits int) string { + k := make([]byte, bits) + rand.Read(k) + return base64.StdEncoding.EncodeToString(k) +} + +func testClash_Shadowsocks(t *testing.T, method string, password string) { cfg := &container.Config{ - Image: ImageShadowsocksRust, - Entrypoint: []string{"ssserver"}, - Cmd: []string{"-s", "0.0.0.0:10002", "-m", "chacha20-ietf-poly1305", "-k", "FzcLbKs2dY9mhL", "-U"}, + Image: ImageShadowsocks, + Env: []string{ + "SS_MODULE=ss-server", + "SS_CONFIG=-s 0.0.0.0 -u -p 10002 -m " + method + " -k " + password, + }, ExposedPorts: defaultExposedPorts, } hostCfg := &container.HostConfig{ @@ -32,8 +90,40 @@ func TestClash_Shadowsocks(t *testing.T) { Name: "ss", Server: localIP.String(), Port: 10002, - Password: "FzcLbKs2dY9mhL", - Cipher: "chacha20-ietf-poly1305", + Password: password, + Cipher: method, + UDP: true, + }) + require.NoError(t, err) + + time.Sleep(waitTime) + testSuit(t, proxy) +} + +func testClash_ShadowsocksRust(t *testing.T, method string, password string) { + cfg := &container.Config{ + Image: ImageShadowsocksRust, + Entrypoint: []string{"ssserver"}, + Cmd: []string{"-s", "0.0.0.0:10002", "-m", method, "-k", password, "-U", "-v"}, + ExposedPorts: defaultExposedPorts, + } + hostCfg := &container.HostConfig{ + PortBindings: defaultPortBindings, + } + + id, err := startContainer(cfg, hostCfg, "ss-rust") + require.NoError(t, err) + + t.Cleanup(func() { + cleanContainer(id) + }) + + proxy, err := outbound.NewShadowSocks(outbound.ShadowSocksOption{ + Name: "ss", + Server: localIP.String(), + Port: 10002, + Password: password, + Cipher: method, UDP: true, }) require.NoError(t, err)