vmess_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package conf_test
  2. import (
  3. "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
  4. "testing"
  5. "github.com/v2fly/v2ray-core/v4/common/net"
  6. "github.com/v2fly/v2ray-core/v4/common/protocol"
  7. "github.com/v2fly/v2ray-core/v4/common/serial"
  8. . "github.com/v2fly/v2ray-core/v4/infra/conf"
  9. "github.com/v2fly/v2ray-core/v4/proxy/vmess"
  10. "github.com/v2fly/v2ray-core/v4/proxy/vmess/inbound"
  11. "github.com/v2fly/v2ray-core/v4/proxy/vmess/outbound"
  12. )
  13. func TestVMessOutbound(t *testing.T) {
  14. creator := func() cfgcommon.Buildable {
  15. return new(VMessOutboundConfig)
  16. }
  17. runMultiTestCase(t, []TestCase{
  18. {
  19. Input: `{
  20. "vnext": [{
  21. "address": "127.0.0.1",
  22. "port": 80,
  23. "users": [
  24. {
  25. "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  26. "email": "love@v2fly.org",
  27. "level": 255
  28. }
  29. ]
  30. }]
  31. }`,
  32. Parser: loadJSON(creator),
  33. Output: &outbound.Config{
  34. Receiver: []*protocol.ServerEndpoint{
  35. {
  36. Address: &net.IPOrDomain{
  37. Address: &net.IPOrDomain_Ip{
  38. Ip: []byte{127, 0, 0, 1},
  39. },
  40. },
  41. Port: 80,
  42. User: []*protocol.User{
  43. {
  44. Email: "love@v2fly.org",
  45. Level: 255,
  46. Account: serial.ToTypedMessage(&vmess.Account{
  47. Id: "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  48. AlterId: 0,
  49. SecuritySettings: &protocol.SecurityConfig{
  50. Type: protocol.SecurityType_AUTO,
  51. },
  52. }),
  53. },
  54. },
  55. },
  56. },
  57. },
  58. },
  59. })
  60. }
  61. func TestVMessInbound(t *testing.T) {
  62. creator := func() cfgcommon.Buildable {
  63. return new(VMessInboundConfig)
  64. }
  65. runMultiTestCase(t, []TestCase{
  66. {
  67. Input: `{
  68. "clients": [
  69. {
  70. "id": "27848739-7e62-4138-9fd3-098a63964b6b",
  71. "level": 0,
  72. "alterId": 16,
  73. "email": "love@v2fly.org",
  74. "security": "aes-128-gcm"
  75. }
  76. ],
  77. "default": {
  78. "level": 0,
  79. "alterId": 32
  80. },
  81. "detour": {
  82. "to": "tag_to_detour"
  83. },
  84. "disableInsecureEncryption": true
  85. }`,
  86. Parser: loadJSON(creator),
  87. Output: &inbound.Config{
  88. User: []*protocol.User{
  89. {
  90. Level: 0,
  91. Email: "love@v2fly.org",
  92. Account: serial.ToTypedMessage(&vmess.Account{
  93. Id: "27848739-7e62-4138-9fd3-098a63964b6b",
  94. AlterId: 16,
  95. SecuritySettings: &protocol.SecurityConfig{
  96. Type: protocol.SecurityType_AES128_GCM,
  97. },
  98. }),
  99. },
  100. },
  101. Default: &inbound.DefaultConfig{
  102. Level: 0,
  103. AlterId: 32,
  104. },
  105. Detour: &inbound.DetourConfig{
  106. To: "tag_to_detour",
  107. },
  108. SecureEncryptionOnly: true,
  109. },
  110. },
  111. })
  112. }