clash/test/snell_test.go

174 lines
3.8 KiB
Go
Raw Normal View History

2021-05-17 12:33:00 +00:00
package main
import (
"fmt"
"testing"
"time"
2022-06-07 02:45:32 +00:00
"github.com/Dreamacro/clash/adapter/outbound"
C "github.com/Dreamacro/clash/constant"
2021-05-17 12:33:00 +00:00
"github.com/docker/docker/api/types/container"
2022-05-21 09:37:06 +00:00
"github.com/stretchr/testify/require"
2021-05-17 12:33:00 +00:00
)
func TestClash_SnellObfsHTTP(t *testing.T) {
cfg := &container.Config{
Image: ImageSnell,
ExposedPorts: defaultExposedPorts,
Cmd: []string{"-c", "/config.conf"},
}
hostCfg := &container.HostConfig{
PortBindings: defaultPortBindings,
Binds: []string{fmt.Sprintf("%s:/config.conf", C.Path.Resolve("snell-http.conf"))},
}
id, err := startContainer(cfg, hostCfg, "snell-http")
2022-05-21 09:37:06 +00:00
require.NoError(t, err)
2021-05-17 12:33:00 +00:00
t.Cleanup(func() {
cleanContainer(id)
})
proxy, err := outbound.NewSnell(outbound.SnellOption{
Name: "snell",
Server: localIP.String(),
Port: 10002,
Psk: "password",
2022-03-16 04:10:13 +00:00
ObfsOpts: map[string]any{
2021-05-17 12:33:00 +00:00
"mode": "http",
},
})
2022-05-21 09:37:06 +00:00
require.NoError(t, err)
2021-05-17 12:33:00 +00:00
time.Sleep(waitTime)
testSuit(t, proxy)
}
func TestClash_SnellObfsTLS(t *testing.T) {
cfg := &container.Config{
Image: ImageSnell,
ExposedPorts: defaultExposedPorts,
Cmd: []string{"-c", "/config.conf"},
}
hostCfg := &container.HostConfig{
PortBindings: defaultPortBindings,
Binds: []string{fmt.Sprintf("%s:/config.conf", C.Path.Resolve("snell-tls.conf"))},
}
id, err := startContainer(cfg, hostCfg, "snell-tls")
2022-05-21 09:37:06 +00:00
require.NoError(t, err)
2021-05-17 12:33:00 +00:00
t.Cleanup(func() {
cleanContainer(id)
})
proxy, err := outbound.NewSnell(outbound.SnellOption{
Name: "snell",
Server: localIP.String(),
Port: 10002,
Psk: "password",
2022-03-16 04:10:13 +00:00
ObfsOpts: map[string]any{
2021-05-17 12:33:00 +00:00
"mode": "tls",
},
})
2022-05-21 09:37:06 +00:00
require.NoError(t, err)
2021-05-17 12:33:00 +00:00
time.Sleep(waitTime)
testSuit(t, proxy)
}
func TestClash_Snell(t *testing.T) {
cfg := &container.Config{
Image: ImageSnell,
ExposedPorts: defaultExposedPorts,
Cmd: []string{"-c", "/config.conf"},
}
hostCfg := &container.HostConfig{
PortBindings: defaultPortBindings,
Binds: []string{fmt.Sprintf("%s:/config.conf", C.Path.Resolve("snell.conf"))},
}
id, err := startContainer(cfg, hostCfg, "snell")
2022-05-21 09:37:06 +00:00
require.NoError(t, err)
2021-05-17 12:33:00 +00:00
t.Cleanup(func() {
cleanContainer(id)
})
proxy, err := outbound.NewSnell(outbound.SnellOption{
Name: "snell",
Server: localIP.String(),
Port: 10002,
Psk: "password",
})
2022-05-21 09:37:06 +00:00
require.NoError(t, err)
2021-05-17 12:33:00 +00:00
time.Sleep(waitTime)
testSuit(t, proxy)
}
2021-07-18 09:23:22 +00:00
2022-01-10 12:24:20 +00:00
func TestClash_Snellv3(t *testing.T) {
cfg := &container.Config{
Image: ImageSnell,
ExposedPorts: defaultExposedPorts,
Cmd: []string{"-c", "/config.conf"},
}
hostCfg := &container.HostConfig{
PortBindings: defaultPortBindings,
Binds: []string{fmt.Sprintf("%s:/config.conf", C.Path.Resolve("snell.conf"))},
}
id, err := startContainer(cfg, hostCfg, "snell")
2022-05-21 09:37:06 +00:00
require.NoError(t, err)
2022-01-10 12:24:20 +00:00
t.Cleanup(func() {
cleanContainer(id)
})
proxy, err := outbound.NewSnell(outbound.SnellOption{
Name: "snell",
Server: localIP.String(),
Port: 10002,
Psk: "password",
UDP: true,
Version: 3,
})
2022-05-21 09:37:06 +00:00
require.NoError(t, err)
2022-01-10 12:24:20 +00:00
time.Sleep(waitTime)
testSuit(t, proxy)
}
2021-07-18 09:23:22 +00:00
func Benchmark_Snell(b *testing.B) {
cfg := &container.Config{
Image: ImageSnell,
ExposedPorts: defaultExposedPorts,
Cmd: []string{"-c", "/config.conf"},
}
hostCfg := &container.HostConfig{
PortBindings: defaultPortBindings,
Binds: []string{fmt.Sprintf("%s:/config.conf", C.Path.Resolve("snell-http.conf"))},
}
2022-05-23 04:27:34 +00:00
id, err := startContainer(cfg, hostCfg, "snell-bench")
2022-05-21 09:37:06 +00:00
require.NoError(b, err)
2021-07-18 09:23:22 +00:00
b.Cleanup(func() {
cleanContainer(id)
})
proxy, err := outbound.NewSnell(outbound.SnellOption{
Name: "snell",
Server: localIP.String(),
Port: 10002,
Psk: "password",
2022-03-16 04:10:13 +00:00
ObfsOpts: map[string]any{
2021-07-18 09:23:22 +00:00
"mode": "http",
},
})
2022-05-21 09:37:06 +00:00
require.NoError(b, err)
2021-07-18 09:23:22 +00:00
time.Sleep(waitTime)
benchmarkProxy(b, proxy)
}