github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/infra/conf/socks_test.go (about) 1 package conf_test 2 3 import ( 4 "testing" 5 6 "v2ray.com/core/common/net" 7 "v2ray.com/core/common/protocol" 8 "v2ray.com/core/common/serial" 9 . "v2ray.com/core/infra/conf" 10 "v2ray.com/core/proxy/socks" 11 ) 12 13 func TestSocksInboundConfig(t *testing.T) { 14 creator := func() Buildable { 15 return new(SocksServerConfig) 16 } 17 18 runMultiTestCase(t, []TestCase{ 19 { 20 Input: `{ 21 "auth": "password", 22 "accounts": [ 23 { 24 "user": "my-username", 25 "pass": "my-password" 26 } 27 ], 28 "udp": false, 29 "ip": "127.0.0.1", 30 "timeout": 5, 31 "userLevel": 1 32 }`, 33 Parser: loadJSON(creator), 34 Output: &socks.ServerConfig{ 35 AuthType: socks.AuthType_PASSWORD, 36 Accounts: map[string]string{ 37 "my-username": "my-password", 38 }, 39 UdpEnabled: false, 40 Address: &net.IPOrDomain{ 41 Address: &net.IPOrDomain_Ip{ 42 Ip: []byte{127, 0, 0, 1}, 43 }, 44 }, 45 Timeout: 5, 46 UserLevel: 1, 47 }, 48 }, 49 }) 50 } 51 52 func TestSocksOutboundConfig(t *testing.T) { 53 creator := func() Buildable { 54 return new(SocksClientConfig) 55 } 56 57 runMultiTestCase(t, []TestCase{ 58 { 59 Input: `{ 60 "servers": [{ 61 "address": "127.0.0.1", 62 "port": 1234, 63 "users": [ 64 {"user": "test user", "pass": "test pass", "email": "test@email.com"} 65 ] 66 }] 67 }`, 68 Parser: loadJSON(creator), 69 Output: &socks.ClientConfig{ 70 Server: []*protocol.ServerEndpoint{ 71 { 72 Address: &net.IPOrDomain{ 73 Address: &net.IPOrDomain_Ip{ 74 Ip: []byte{127, 0, 0, 1}, 75 }, 76 }, 77 Port: 1234, 78 User: []*protocol.User{ 79 { 80 Email: "test@email.com", 81 Account: serial.ToTypedMessage(&socks.Account{ 82 Username: "test user", 83 Password: "test pass", 84 }), 85 }, 86 }, 87 }, 88 }, 89 }, 90 }, 91 }) 92 }