vless_test.go 2.7 KB

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