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