chore: add more shadowsocks tests
This commit is contained in:
parent
5055542d61
commit
9a55213ddc
1 changed files with 95 additions and 5 deletions
100
test/ss_test.go
100
test/ss_test.go
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/base64"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -11,10 +13,66 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClash_Shadowsocks(t *testing.T) {
|
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{
|
cfg := &container.Config{
|
||||||
Image: ImageShadowsocksRust,
|
Image: ImageShadowsocks,
|
||||||
Entrypoint: []string{"ssserver"},
|
Env: []string{
|
||||||
Cmd: []string{"-s", "0.0.0.0:10002", "-m", "chacha20-ietf-poly1305", "-k", "FzcLbKs2dY9mhL", "-U"},
|
"SS_MODULE=ss-server",
|
||||||
|
"SS_CONFIG=-s 0.0.0.0 -u -p 10002 -m " + method + " -k " + password,
|
||||||
|
},
|
||||||
ExposedPorts: defaultExposedPorts,
|
ExposedPorts: defaultExposedPorts,
|
||||||
}
|
}
|
||||||
hostCfg := &container.HostConfig{
|
hostCfg := &container.HostConfig{
|
||||||
|
@ -32,8 +90,40 @@ func TestClash_Shadowsocks(t *testing.T) {
|
||||||
Name: "ss",
|
Name: "ss",
|
||||||
Server: localIP.String(),
|
Server: localIP.String(),
|
||||||
Port: 10002,
|
Port: 10002,
|
||||||
Password: "FzcLbKs2dY9mhL",
|
Password: password,
|
||||||
Cipher: "chacha20-ietf-poly1305",
|
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,
|
UDP: true,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
Loading…
Reference in a new issue