vmess_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. AlterId: 0,
  48. SecuritySettings: &protocol.SecurityConfig{
  49. Type: protocol.SecurityType_AUTO,
  50. },
  51. }),
  52. },
  53. },
  54. },
  55. },
  56. },
  57. },
  58. })
  59. }
  60. func TestVMessInbound(t *testing.T) {
  61. creator := func() Buildable {
  62. return new(VMessInboundConfig)
  63. }
  64. runMultiTestCase(t, []TestCase{
  65. {
  66. Input: `{
  67. "clients": [
  68. {
  69. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  70. "level": 0,
  71. "alterId": 16,
  72. "email": "[email protected]",
  73. "security": "aes-128-gcm"
  74. }
  75. ],
  76. "default": {
  77. "level": 0,
  78. "alterId": 32
  79. },
  80. "detour": {
  81. "to": "tag_to_detour"
  82. },
  83. "disableInsecureEncryption": true
  84. }`,
  85. Parser: loadJSON(creator),
  86. Output: &inbound.Config{
  87. User: []*protocol.User{
  88. {
  89. Level: 0,
  90. Email: "[email protected]",
  91. Account: serial.ToTypedMessage(&vmess.Account{
  92. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  93. AlterId: 16,
  94. SecuritySettings: &protocol.SecurityConfig{
  95. Type: protocol.SecurityType_AES128_GCM,
  96. },
  97. }),
  98. },
  99. },
  100. Default: &inbound.DefaultConfig{
  101. Level: 0,
  102. AlterId: 32,
  103. },
  104. Detour: &inbound.DetourConfig{
  105. To: "tag_to_detour",
  106. },
  107. SecureEncryptionOnly: true,
  108. },
  109. },
  110. })
  111. }