vmess_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/vmess"
  9. "github.com/xtls/xray-core/proxy/vmess/inbound"
  10. "github.com/xtls/xray-core/proxy/vmess/outbound"
  11. )
  12. func TestVMessOutbound(t *testing.T) {
  13. creator := func() Buildable {
  14. return new(VMessOutboundConfig)
  15. }
  16. runMultiTestCase(t, []TestCase{
  17. {
  18. Input: `{
  19. "vnext": [{
  20. "address": "127.0.0.1",
  21. "port": 80,
  22. "users": [
  23. {
  24. "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  25. "email": "[email protected]",
  26. "level": 255
  27. }
  28. ]
  29. }]
  30. }`,
  31. Parser: loadJSON(creator),
  32. Output: &outbound.Config{
  33. Receiver: []*protocol.ServerEndpoint{
  34. {
  35. Address: &net.IPOrDomain{
  36. Address: &net.IPOrDomain_Ip{
  37. Ip: []byte{127, 0, 0, 1},
  38. },
  39. },
  40. Port: 80,
  41. User: []*protocol.User{
  42. {
  43. Email: "[email protected]",
  44. Level: 255,
  45. Account: serial.ToTypedMessage(&vmess.Account{
  46. Id: "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  47. SecuritySettings: &protocol.SecurityConfig{
  48. Type: protocol.SecurityType_AUTO,
  49. },
  50. }),
  51. },
  52. },
  53. },
  54. },
  55. },
  56. },
  57. {
  58. Input: `{
  59. "address": "127.0.0.1",
  60. "port": 80,
  61. "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  62. "email": "[email protected]",
  63. "level": 255
  64. }`,
  65. Parser: loadJSON(creator),
  66. Output: &outbound.Config{
  67. Receiver: []*protocol.ServerEndpoint{
  68. {
  69. Address: &net.IPOrDomain{
  70. Address: &net.IPOrDomain_Ip{
  71. Ip: []byte{127, 0, 0, 1},
  72. },
  73. },
  74. Port: 80,
  75. User: []*protocol.User{
  76. {
  77. Email: "[email protected]",
  78. Level: 255,
  79. Account: serial.ToTypedMessage(&vmess.Account{
  80. Id: "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  81. SecuritySettings: &protocol.SecurityConfig{
  82. Type: protocol.SecurityType_AUTO,
  83. },
  84. }),
  85. },
  86. },
  87. },
  88. },
  89. },
  90. },
  91. })
  92. }
  93. func TestVMessInbound(t *testing.T) {
  94. creator := func() Buildable {
  95. return new(VMessInboundConfig)
  96. }
  97. runMultiTestCase(t, []TestCase{
  98. {
  99. Input: `{
  100. "clients": [
  101. {
  102. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  103. "level": 0,
  104. "email": "[email protected]",
  105. "security": "aes-128-gcm"
  106. }
  107. ],
  108. "default": {
  109. "level": 0
  110. },
  111. "detour": {
  112. "to": "tag_to_detour"
  113. },
  114. "disableInsecureEncryption": true
  115. }`,
  116. Parser: loadJSON(creator),
  117. Output: &inbound.Config{
  118. User: []*protocol.User{
  119. {
  120. Level: 0,
  121. Email: "[email protected]",
  122. Account: serial.ToTypedMessage(&vmess.Account{
  123. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  124. SecuritySettings: &protocol.SecurityConfig{
  125. Type: protocol.SecurityType_AES128_GCM,
  126. },
  127. }),
  128. },
  129. },
  130. Default: &inbound.DefaultConfig{
  131. Level: 0,
  132. },
  133. Detour: &inbound.DetourConfig{
  134. To: "tag_to_detour",
  135. },
  136. },
  137. },
  138. })
  139. }