mihomo/test/vless_test.go

133 lines
3.4 KiB
Go
Raw Permalink Normal View History

2021-11-17 16:03:47 +08:00
package main
import (
"fmt"
"testing"
"time"
2022-06-07 10:45:32 +08:00
"github.com/Dreamacro/clash/adapter/outbound"
C "github.com/Dreamacro/clash/constant"
2021-11-17 16:03:47 +08:00
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"
)
2022-06-07 10:45:32 +08:00
// TODO: fix udp test
2021-11-17 16:03:47 +08:00
func TestClash_VlessTLS(t *testing.T) {
cfg := &container.Config{
Image: ImageVmess,
ExposedPorts: defaultExposedPorts,
}
hostCfg := &container.HostConfig{
PortBindings: defaultPortBindings,
Binds: []string{
fmt.Sprintf("%s:/etc/v2ray/config.json", C.Path.Resolve("vless-tls.json")),
fmt.Sprintf("%s:/etc/ssl/v2ray/fullchain.pem", C.Path.Resolve("example.org.pem")),
fmt.Sprintf("%s:/etc/ssl/v2ray/privkey.pem", C.Path.Resolve("example.org-key.pem")),
},
}
id, err := startContainer(cfg, hostCfg, "vless-tls")
if err != nil {
assert.FailNow(t, err.Error())
}
defer cleanContainer(id)
proxy, err := outbound.NewVless(outbound.VlessOption{
Name: "vless",
Server: localIP.String(),
Port: 10002,
UUID: "b831381d-6324-4d53-ad4f-8cda48b30811",
2022-06-07 10:45:32 +08:00
TLS: true,
2021-11-17 16:03:47 +08:00
SkipCertVerify: true,
ServerName: "example.org",
2022-03-29 07:18:09 +08:00
UDP: true,
2021-11-17 16:03:47 +08:00
})
if err != nil {
assert.FailNow(t, err.Error())
}
time.Sleep(waitTime)
testSuit(t, proxy)
}
2022-06-07 10:45:32 +08:00
// TODO: fix udp test
2021-11-17 16:03:47 +08:00
func TestClash_VlessXTLS(t *testing.T) {
cfg := &container.Config{
Image: ImageXray,
ExposedPorts: defaultExposedPorts,
}
hostCfg := &container.HostConfig{
PortBindings: defaultPortBindings,
Binds: []string{
fmt.Sprintf("%s:/etc/xray/config.json", C.Path.Resolve("vless-xtls.json")),
fmt.Sprintf("%s:/etc/ssl/v2ray/fullchain.pem", C.Path.Resolve("example.org.pem")),
fmt.Sprintf("%s:/etc/ssl/v2ray/privkey.pem", C.Path.Resolve("example.org-key.pem")),
},
}
id, err := startContainer(cfg, hostCfg, "vless-xtls")
if err != nil {
assert.FailNow(t, err.Error())
}
defer cleanContainer(id)
proxy, err := outbound.NewVless(outbound.VlessOption{
2022-03-29 07:18:09 +08:00
Name: "vless",
Server: localIP.String(),
Port: 10002,
UUID: "b831381d-6324-4d53-ad4f-8cda48b30811",
2022-06-07 10:45:32 +08:00
TLS: true,
2021-09-08 22:36:54 +08:00
SkipCertVerify: true,
ServerName: "example.org",
2022-03-29 07:18:09 +08:00
UDP: true,
Flow: "xtls-rprx-direct",
FlowShow: true,
2021-09-08 22:36:54 +08:00
})
if err != nil {
assert.FailNow(t, err.Error())
}
time.Sleep(waitTime)
testSuit(t, proxy)
}
2022-03-29 23:50:41 +08:00
2022-06-07 10:45:32 +08:00
// TODO: fix udp test
2022-03-29 23:50:41 +08:00
func TestClash_VlessWS(t *testing.T) {
cfg := &container.Config{
Image: ImageVmess,
ExposedPorts: defaultExposedPorts,
}
hostCfg := &container.HostConfig{
PortBindings: defaultPortBindings,
Binds: []string{
fmt.Sprintf("%s:/etc/v2ray/config.json", C.Path.Resolve("vless-ws.json")),
fmt.Sprintf("%s:/etc/ssl/v2ray/fullchain.pem", C.Path.Resolve("example.org.pem")),
fmt.Sprintf("%s:/etc/ssl/v2ray/privkey.pem", C.Path.Resolve("example.org-key.pem")),
},
}
id, err := startContainer(cfg, hostCfg, "vless-ws")
if err != nil {
assert.FailNow(t, err.Error())
}
defer cleanContainer(id)
proxy, err := outbound.NewVless(outbound.VlessOption{
Name: "vless",
Server: localIP.String(),
Port: 10002,
UUID: "b831381d-6324-4d53-ad4f-8cda48b30811",
2022-06-07 10:45:32 +08:00
TLS: true,
2021-11-17 16:03:47 +08:00
SkipCertVerify: true,
ServerName: "example.org",
2022-03-29 23:50:41 +08:00
Network: "ws",
UDP: true,
2021-11-17 16:03:47 +08:00
})
if err != nil {
assert.FailNow(t, err.Error())
}
time.Sleep(waitTime)
testSuit(t, proxy)
}