vmess_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. Address: &net.IPOrDomain{
  35. Address: &net.IPOrDomain_Ip{
  36. Ip: []byte{127, 0, 0, 1},
  37. },
  38. },
  39. Port: 80,
  40. User: &protocol.User{
  41. Email: "[email protected]",
  42. Level: 255,
  43. Account: serial.ToTypedMessage(&vmess.Account{
  44. Id: "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  45. SecuritySettings: &protocol.SecurityConfig{
  46. Type: protocol.SecurityType_AUTO,
  47. },
  48. }),
  49. },
  50. },
  51. },
  52. },
  53. {
  54. Input: `{
  55. "address": "127.0.0.1",
  56. "port": 80,
  57. "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  58. "email": "[email protected]",
  59. "level": 255
  60. }`,
  61. Parser: loadJSON(creator),
  62. Output: &outbound.Config{
  63. Receiver: &protocol.ServerEndpoint{
  64. Address: &net.IPOrDomain{
  65. Address: &net.IPOrDomain_Ip{
  66. Ip: []byte{127, 0, 0, 1},
  67. },
  68. },
  69. Port: 80,
  70. User: &protocol.User{
  71. Email: "[email protected]",
  72. Level: 255,
  73. Account: serial.ToTypedMessage(&vmess.Account{
  74. Id: "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  75. SecuritySettings: &protocol.SecurityConfig{
  76. Type: protocol.SecurityType_AUTO,
  77. },
  78. }),
  79. },
  80. },
  81. },
  82. },
  83. })
  84. }
  85. func TestVMessInbound(t *testing.T) {
  86. creator := func() Buildable {
  87. return new(VMessInboundConfig)
  88. }
  89. runMultiTestCase(t, []TestCase{
  90. {
  91. Input: `{
  92. "clients": [
  93. {
  94. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  95. "level": 0,
  96. "email": "[email protected]",
  97. "security": "aes-128-gcm"
  98. }
  99. ],
  100. "default": {
  101. "level": 0
  102. }
  103. }`,
  104. Parser: loadJSON(creator),
  105. Output: &inbound.Config{
  106. User: []*protocol.User{
  107. {
  108. Level: 0,
  109. Email: "[email protected]",
  110. Account: serial.ToTypedMessage(&vmess.Account{
  111. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  112. SecuritySettings: &protocol.SecurityConfig{
  113. Type: protocol.SecurityType_AES128_GCM,
  114. },
  115. }),
  116. },
  117. },
  118. Default: &inbound.DefaultConfig{
  119. Level: 0,
  120. },
  121. },
  122. },
  123. })
  124. }