2021-05-17 20:33:00 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-06-10 14:05:56 +08:00
|
|
|
"github.com/Dreamacro/clash/adapter/outbound"
|
2021-05-17 20:33:00 +08:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(t, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
cleanContainer(id)
|
|
|
|
})
|
|
|
|
|
|
|
|
proxy, err := outbound.NewSnell(outbound.SnellOption{
|
|
|
|
Name: "snell",
|
|
|
|
Server: localIP.String(),
|
|
|
|
Port: 10002,
|
|
|
|
Psk: "password",
|
2022-03-16 12:10:13 +08:00
|
|
|
ObfsOpts: map[string]any{
|
2021-05-17 20:33:00 +08:00
|
|
|
"mode": "http",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(t, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(t, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
cleanContainer(id)
|
|
|
|
})
|
|
|
|
|
|
|
|
proxy, err := outbound.NewSnell(outbound.SnellOption{
|
|
|
|
Name: "snell",
|
|
|
|
Server: localIP.String(),
|
|
|
|
Port: 10002,
|
|
|
|
Psk: "password",
|
2022-03-16 12:10:13 +08:00
|
|
|
ObfsOpts: map[string]any{
|
2021-05-17 20:33:00 +08:00
|
|
|
"mode": "tls",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(t, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(t, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
cleanContainer(id)
|
|
|
|
})
|
|
|
|
|
|
|
|
proxy, err := outbound.NewSnell(outbound.SnellOption{
|
|
|
|
Name: "snell",
|
|
|
|
Server: localIP.String(),
|
|
|
|
Port: 10002,
|
|
|
|
Psk: "password",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(t, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(waitTime)
|
|
|
|
testSuit(t, proxy)
|
|
|
|
}
|
2021-07-18 17:23:22 +08:00
|
|
|
|
2022-01-10 20:24:20 +08: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")
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(t, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
cleanContainer(id)
|
|
|
|
})
|
|
|
|
|
|
|
|
proxy, err := outbound.NewSnell(outbound.SnellOption{
|
|
|
|
Name: "snell",
|
|
|
|
Server: localIP.String(),
|
|
|
|
Port: 10002,
|
|
|
|
Psk: "password",
|
|
|
|
UDP: true,
|
|
|
|
Version: 3,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(t, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(waitTime)
|
|
|
|
testSuit(t, proxy)
|
|
|
|
}
|
|
|
|
|
2021-07-18 17:23:22 +08: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"))},
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := startContainer(cfg, hostCfg, "snell-http")
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(b, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Cleanup(func() {
|
|
|
|
cleanContainer(id)
|
|
|
|
})
|
|
|
|
|
|
|
|
proxy, err := outbound.NewSnell(outbound.SnellOption{
|
|
|
|
Name: "snell",
|
|
|
|
Server: localIP.String(),
|
|
|
|
Port: 10002,
|
|
|
|
Psk: "password",
|
2022-03-16 12:10:13 +08:00
|
|
|
ObfsOpts: map[string]any{
|
2021-07-18 17:23:22 +08:00
|
|
|
"mode": "http",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
assert.FailNow(b, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(waitTime)
|
|
|
|
benchmarkProxy(b, proxy)
|
|
|
|
}
|