vmess_test.go 2.3 KB

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