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