123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package main
- import (
- "fmt"
- "testing"
- "time"
- "github.com/docker/docker/api/types/container"
- "github.com/metacubex/mihomo/adapter/outbound"
- C "github.com/metacubex/mihomo/constant"
- "github.com/stretchr/testify/assert"
- )
- // TODO: fix udp test
- func TestMihomo_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",
- TLS: true,
- SkipCertVerify: true,
- ServerName: "example.org",
- UDP: true,
- })
- if err != nil {
- assert.FailNow(t, err.Error())
- }
- time.Sleep(waitTime)
- testSuit(t, proxy)
- }
- // TODO: fix udp test
- func TestMihomo_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{
- Name: "vless",
- Server: localIP.String(),
- Port: 10002,
- UUID: "b831381d-6324-4d53-ad4f-8cda48b30811",
- TLS: true,
- SkipCertVerify: true,
- ServerName: "example.org",
- UDP: true,
- Flow: "xtls-rprx-direct",
- })
- if err != nil {
- assert.FailNow(t, err.Error())
- }
- time.Sleep(waitTime)
- testSuit(t, proxy)
- }
- // TODO: fix udp test
- func TestMihomo_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",
- TLS: true,
- SkipCertVerify: true,
- ServerName: "example.org",
- Network: "ws",
- UDP: true,
- })
- if err != nil {
- assert.FailNow(t, err.Error())
- }
- time.Sleep(waitTime)
- testSuit(t, proxy)
- }
|