vless_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package main
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. "github.com/docker/docker/api/types/container"
  7. "github.com/metacubex/mihomo/adapter/outbound"
  8. C "github.com/metacubex/mihomo/constant"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. // TODO: fix udp test
  12. func TestMihomo_VlessTLS(t *testing.T) {
  13. cfg := &container.Config{
  14. Image: ImageVmess,
  15. ExposedPorts: defaultExposedPorts,
  16. }
  17. hostCfg := &container.HostConfig{
  18. PortBindings: defaultPortBindings,
  19. Binds: []string{
  20. fmt.Sprintf("%s:/etc/v2ray/config.json", C.Path.Resolve("vless-tls.json")),
  21. fmt.Sprintf("%s:/etc/ssl/v2ray/fullchain.pem", C.Path.Resolve("example.org.pem")),
  22. fmt.Sprintf("%s:/etc/ssl/v2ray/privkey.pem", C.Path.Resolve("example.org-key.pem")),
  23. },
  24. }
  25. id, err := startContainer(cfg, hostCfg, "vless-tls")
  26. if err != nil {
  27. assert.FailNow(t, err.Error())
  28. }
  29. defer cleanContainer(id)
  30. proxy, err := outbound.NewVless(outbound.VlessOption{
  31. Name: "vless",
  32. Server: localIP.String(),
  33. Port: 10002,
  34. UUID: "b831381d-6324-4d53-ad4f-8cda48b30811",
  35. TLS: true,
  36. SkipCertVerify: true,
  37. ServerName: "example.org",
  38. UDP: true,
  39. })
  40. if err != nil {
  41. assert.FailNow(t, err.Error())
  42. }
  43. time.Sleep(waitTime)
  44. testSuit(t, proxy)
  45. }
  46. // TODO: fix udp test
  47. func TestMihomo_VlessXTLS(t *testing.T) {
  48. cfg := &container.Config{
  49. Image: ImageXray,
  50. ExposedPorts: defaultExposedPorts,
  51. }
  52. hostCfg := &container.HostConfig{
  53. PortBindings: defaultPortBindings,
  54. Binds: []string{
  55. fmt.Sprintf("%s:/etc/xray/config.json", C.Path.Resolve("vless-xtls.json")),
  56. fmt.Sprintf("%s:/etc/ssl/v2ray/fullchain.pem", C.Path.Resolve("example.org.pem")),
  57. fmt.Sprintf("%s:/etc/ssl/v2ray/privkey.pem", C.Path.Resolve("example.org-key.pem")),
  58. },
  59. }
  60. id, err := startContainer(cfg, hostCfg, "vless-xtls")
  61. if err != nil {
  62. assert.FailNow(t, err.Error())
  63. }
  64. defer cleanContainer(id)
  65. proxy, err := outbound.NewVless(outbound.VlessOption{
  66. Name: "vless",
  67. Server: localIP.String(),
  68. Port: 10002,
  69. UUID: "b831381d-6324-4d53-ad4f-8cda48b30811",
  70. TLS: true,
  71. SkipCertVerify: true,
  72. ServerName: "example.org",
  73. UDP: true,
  74. Flow: "xtls-rprx-direct",
  75. })
  76. if err != nil {
  77. assert.FailNow(t, err.Error())
  78. }
  79. time.Sleep(waitTime)
  80. testSuit(t, proxy)
  81. }
  82. // TODO: fix udp test
  83. func TestMihomo_VlessWS(t *testing.T) {
  84. cfg := &container.Config{
  85. Image: ImageVmess,
  86. ExposedPorts: defaultExposedPorts,
  87. }
  88. hostCfg := &container.HostConfig{
  89. PortBindings: defaultPortBindings,
  90. Binds: []string{
  91. fmt.Sprintf("%s:/etc/v2ray/config.json", C.Path.Resolve("vless-ws.json")),
  92. fmt.Sprintf("%s:/etc/ssl/v2ray/fullchain.pem", C.Path.Resolve("example.org.pem")),
  93. fmt.Sprintf("%s:/etc/ssl/v2ray/privkey.pem", C.Path.Resolve("example.org-key.pem")),
  94. },
  95. }
  96. id, err := startContainer(cfg, hostCfg, "vless-ws")
  97. if err != nil {
  98. assert.FailNow(t, err.Error())
  99. }
  100. defer cleanContainer(id)
  101. proxy, err := outbound.NewVless(outbound.VlessOption{
  102. Name: "vless",
  103. Server: localIP.String(),
  104. Port: 10002,
  105. UUID: "b831381d-6324-4d53-ad4f-8cda48b30811",
  106. TLS: true,
  107. SkipCertVerify: true,
  108. ServerName: "example.org",
  109. Network: "ws",
  110. UDP: true,
  111. })
  112. if err != nil {
  113. assert.FailNow(t, err.Error())
  114. }
  115. time.Sleep(waitTime)
  116. testSuit(t, proxy)
  117. }