vless_test.go 2.4 KB

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