vless_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package conf_test
  2. import (
  3. "testing"
  4. "github.com/xtls/xray-core/common/net"
  5. "github.com/xtls/xray-core/common/protocol"
  6. "github.com/xtls/xray-core/common/serial"
  7. . "github.com/xtls/xray-core/infra/conf"
  8. "github.com/xtls/xray-core/proxy/vless"
  9. "github.com/xtls/xray-core/proxy/vless/inbound"
  10. "github.com/xtls/xray-core/proxy/vless/outbound"
  11. )
  12. func TestVLessOutbound(t *testing.T) {
  13. creator := func() Buildable {
  14. return new(VLessOutboundConfig)
  15. }
  16. runMultiTestCase(t, []TestCase{
  17. {
  18. Input: `{
  19. "vnext": [{
  20. "address": "example.com",
  21. "port": 443,
  22. "users": [
  23. {
  24. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  25. "flow": "xtls-rprx-vision-udp443",
  26. "encryption": "none",
  27. "level": 0
  28. }
  29. ]
  30. }]
  31. }`,
  32. Parser: loadJSON(creator),
  33. Output: &outbound.Config{
  34. Vnext: &protocol.ServerEndpoint{
  35. Address: &net.IPOrDomain{
  36. Address: &net.IPOrDomain_Domain{
  37. Domain: "example.com",
  38. },
  39. },
  40. Port: 443,
  41. User: &protocol.User{
  42. Account: serial.ToTypedMessage(&vless.Account{
  43. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  44. Flow: "xtls-rprx-vision-udp443",
  45. Encryption: "none",
  46. }),
  47. Level: 0,
  48. },
  49. },
  50. },
  51. },
  52. {
  53. Input: `{
  54. "address": "example.com",
  55. "port": 443,
  56. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  57. "flow": "xtls-rprx-vision-udp443",
  58. "encryption": "none",
  59. "level": 0
  60. }`,
  61. Parser: loadJSON(creator),
  62. Output: &outbound.Config{
  63. Vnext: &protocol.ServerEndpoint{
  64. Address: &net.IPOrDomain{
  65. Address: &net.IPOrDomain_Domain{
  66. Domain: "example.com",
  67. },
  68. },
  69. Port: 443,
  70. User: &protocol.User{
  71. Account: serial.ToTypedMessage(&vless.Account{
  72. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  73. Flow: "xtls-rprx-vision-udp443",
  74. Encryption: "none",
  75. }),
  76. Level: 0,
  77. },
  78. },
  79. },
  80. },
  81. })
  82. }
  83. func TestVLessInbound(t *testing.T) {
  84. creator := func() Buildable {
  85. return new(VLessInboundConfig)
  86. }
  87. runMultiTestCase(t, []TestCase{
  88. {
  89. Input: `{
  90. "clients": [
  91. {
  92. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  93. "flow": "xtls-rprx-vision",
  94. "level": 0,
  95. "email": "[email protected]"
  96. }
  97. ],
  98. "decryption": "none",
  99. "fallbacks": [
  100. {
  101. "dest": 80
  102. },
  103. {
  104. "alpn": "h2",
  105. "dest": "@/dev/shm/domain.socket",
  106. "xver": 2
  107. },
  108. {
  109. "path": "/innerws",
  110. "dest": "serve-ws-none"
  111. }
  112. ]
  113. }`,
  114. Parser: loadJSON(creator),
  115. Output: &inbound.Config{
  116. Clients: []*protocol.User{
  117. {
  118. Account: serial.ToTypedMessage(&vless.Account{
  119. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  120. Flow: "xtls-rprx-vision",
  121. }),
  122. Level: 0,
  123. Email: "[email protected]",
  124. },
  125. },
  126. Decryption: "none",
  127. Fallbacks: []*inbound.Fallback{
  128. {
  129. Alpn: "",
  130. Path: "",
  131. Type: "tcp",
  132. Dest: "localhost:80",
  133. Xver: 0,
  134. },
  135. {
  136. Alpn: "h2",
  137. Path: "",
  138. Type: "unix",
  139. Dest: "@/dev/shm/domain.socket",
  140. Xver: 2,
  141. },
  142. {
  143. Alpn: "",
  144. Path: "/innerws",
  145. Type: "serve",
  146. Dest: "serve-ws-none",
  147. Xver: 0,
  148. },
  149. },
  150. },
  151. },
  152. })
  153. }