vmess_test.go 2.7 KB

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