vless_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package conf_test
  2. import (
  3. "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
  4. "testing"
  5. "github.com/v2fly/v2ray-core/v4/common/net"
  6. "github.com/v2fly/v2ray-core/v4/common/protocol"
  7. "github.com/v2fly/v2ray-core/v4/common/serial"
  8. . "github.com/v2fly/v2ray-core/v4/infra/conf"
  9. "github.com/v2fly/v2ray-core/v4/proxy/vless"
  10. "github.com/v2fly/v2ray-core/v4/proxy/vless/inbound"
  11. "github.com/v2fly/v2ray-core/v4/proxy/vless/outbound"
  12. )
  13. func TestVLessOutbound(t *testing.T) {
  14. creator := func() cfgcommon.Buildable {
  15. return new(VLessOutboundConfig)
  16. }
  17. runMultiTestCase(t, []TestCase{
  18. {
  19. Input: `{
  20. "vnext": [{
  21. "address": "example.com",
  22. "port": 443,
  23. "users": [
  24. {
  25. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  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. Encryption: "none",
  47. }),
  48. Level: 0,
  49. },
  50. },
  51. },
  52. },
  53. },
  54. },
  55. })
  56. }
  57. func TestVLessInbound(t *testing.T) {
  58. creator := func() cfgcommon.Buildable {
  59. return new(VLessInboundConfig)
  60. }
  61. runMultiTestCase(t, []TestCase{
  62. {
  63. Input: `{
  64. "clients": [
  65. {
  66. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  67. "level": 0,
  68. "email": "love@v2fly.org"
  69. }
  70. ],
  71. "decryption": "none",
  72. "fallbacks": [
  73. {
  74. "dest": 80
  75. },
  76. {
  77. "alpn": "h2",
  78. "dest": "@/dev/shm/domain.socket",
  79. "xver": 2
  80. },
  81. {
  82. "path": "/innerws",
  83. "dest": "serve-ws-none"
  84. }
  85. ]
  86. }`,
  87. Parser: loadJSON(creator),
  88. Output: &inbound.Config{
  89. Clients: []*protocol.User{
  90. {
  91. Account: serial.ToTypedMessage(&vless.Account{
  92. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  93. }),
  94. Level: 0,
  95. Email: "love@v2fly.org",
  96. },
  97. },
  98. Decryption: "none",
  99. Fallbacks: []*inbound.Fallback{
  100. {
  101. Alpn: "",
  102. Path: "",
  103. Type: "tcp",
  104. Dest: "127.0.0.1:80",
  105. Xver: 0,
  106. },
  107. {
  108. Alpn: "h2",
  109. Path: "",
  110. Type: "unix",
  111. Dest: "@/dev/shm/domain.socket",
  112. Xver: 2,
  113. },
  114. {
  115. Alpn: "",
  116. Path: "/innerws",
  117. Type: "serve",
  118. Dest: "serve-ws-none",
  119. Xver: 0,
  120. },
  121. },
  122. },
  123. },
  124. })
  125. }