vless_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. "schedulers": "",
  26. "encryption": "none",
  27. "level": 0
  28. }
  29. ]
  30. }]
  31. }`,
  32. Parser: loadJSON(creator),
  33. Output: &outbound.Config{
  34. Receiver: []*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. Schedulers: "",
  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. "schedulers": "",
  69. "level": 0,
  70. "email": "love@v2fly.org"
  71. }
  72. ],
  73. "decryption": "none",
  74. "fallback": {
  75. "port": 80,
  76. },
  77. "fallback_h2": {
  78. "unix": "@/dev/shm/domain.socket",
  79. "xver": 2
  80. }
  81. }`,
  82. Parser: loadJSON(creator),
  83. Output: &inbound.Config{
  84. User: []*protocol.User{
  85. {
  86. Account: serial.ToTypedMessage(&vless.Account{
  87. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  88. Schedulers: "",
  89. }),
  90. Level: 0,
  91. Email: "love@v2fly.org",
  92. },
  93. },
  94. Decryption: "none",
  95. Fallback: &inbound.Fallback{
  96. Addr: &net.IPOrDomain{
  97. Address: &net.IPOrDomain_Ip{
  98. Ip: []byte{127, 0, 0, 1},
  99. },
  100. },
  101. Port: 80,
  102. },
  103. FallbackH2: &inbound.FallbackH2{
  104. Addr: &net.IPOrDomain{
  105. Address: &net.IPOrDomain_Ip{
  106. Ip: []byte{127, 0, 0, 1},
  107. },
  108. },
  109. Unix: "\x00/dev/shm/domain.socket",
  110. Xver: 2,
  111. },
  112. },
  113. },
  114. })
  115. }