vless_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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-direct-udp443",
  26. "encryption": "none",
  27. "level": 0
  28. }
  29. ]
  30. }]
  31. }`,
  32. Parser: loadJSON(creator),
  33. Output: &outbound.Config{
  34. Vnext: []*protocol.ServerEndpoint{
  35. {
  36. Address: &net.IPOrDomain{
  37. Address: &net.IPOrDomain_Domain{
  38. Domain: "example.com",
  39. },
  40. },
  41. Port: 443,
  42. User: []*protocol.User{
  43. {
  44. Account: serial.ToTypedMessage(&vless.Account{
  45. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  46. Flow: "xtls-rprx-direct-udp443",
  47. Encryption: "none",
  48. }),
  49. Level: 0,
  50. },
  51. },
  52. },
  53. },
  54. },
  55. },
  56. })
  57. }
  58. func TestVLessInbound(t *testing.T) {
  59. creator := func() Buildable {
  60. return new(VLessInboundConfig)
  61. }
  62. runMultiTestCase(t, []TestCase{
  63. {
  64. Input: `{
  65. "clients": [
  66. {
  67. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  68. "flow": "xtls-rprx-direct",
  69. "level": 0,
  70. "email": "[email protected]"
  71. }
  72. ],
  73. "decryption": "none",
  74. "fallbacks": [
  75. {
  76. "dest": 80
  77. },
  78. {
  79. "alpn": "h2",
  80. "dest": "@/dev/shm/domain.socket",
  81. "xver": 2
  82. },
  83. {
  84. "path": "/innerws",
  85. "dest": "serve-ws-none"
  86. }
  87. ]
  88. }`,
  89. Parser: loadJSON(creator),
  90. Output: &inbound.Config{
  91. Clients: []*protocol.User{
  92. {
  93. Account: serial.ToTypedMessage(&vless.Account{
  94. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  95. Flow: "xtls-rprx-direct",
  96. }),
  97. Level: 0,
  98. Email: "[email protected]",
  99. },
  100. },
  101. Decryption: "none",
  102. Fallbacks: []*inbound.Fallback{
  103. {
  104. Alpn: "",
  105. Path: "",
  106. Type: "tcp",
  107. Dest: "127.0.0.1:80",
  108. Xver: 0,
  109. },
  110. {
  111. Alpn: "h2",
  112. Path: "",
  113. Type: "unix",
  114. Dest: "@/dev/shm/domain.socket",
  115. Xver: 2,
  116. },
  117. {
  118. Alpn: "",
  119. Path: "/innerws",
  120. Type: "serve",
  121. Dest: "serve-ws-none",
  122. Xver: 0,
  123. },
  124. },
  125. },
  126. },
  127. })
  128. }