socks_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/net/packetaddr"
  6. "github.com/v2fly/v2ray-core/v5/common/protocol"
  7. "github.com/v2fly/v2ray-core/v5/common/serial"
  8. "github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
  9. "github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon/testassist"
  10. v4 "github.com/v2fly/v2ray-core/v5/infra/conf/v4"
  11. "github.com/v2fly/v2ray-core/v5/proxy/socks"
  12. )
  13. func TestSocksInboundConfig(t *testing.T) {
  14. creator := func() cfgcommon.Buildable {
  15. return new(v4.SocksServerConfig)
  16. }
  17. testassist.RunMultiTestCase(t, []testassist.TestCase{
  18. {
  19. Input: `{
  20. "auth": "password",
  21. "accounts": [
  22. {
  23. "user": "my-username",
  24. "pass": "my-password"
  25. }
  26. ],
  27. "udp": false,
  28. "ip": "127.0.0.1",
  29. "timeout": 5,
  30. "userLevel": 1,
  31. "packetEncoding": "Packet"
  32. }`,
  33. Parser: testassist.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. PacketEncoding: packetaddr.PacketAddrType_Packet,
  48. },
  49. },
  50. })
  51. }
  52. func TestSocksOutboundConfig(t *testing.T) {
  53. creator := func() cfgcommon.Buildable {
  54. return new(v4.SocksClientConfig)
  55. }
  56. testassist.RunMultiTestCase(t, []testassist.TestCase{
  57. {
  58. Input: `{
  59. "servers": [{
  60. "address": "127.0.0.1",
  61. "port": 1234,
  62. "users": [
  63. {"user": "test user", "pass": "test pass", "email": "test@email.com"}
  64. ]
  65. }]
  66. }`,
  67. Parser: testassist.LoadJSON(creator),
  68. Output: &socks.ClientConfig{
  69. Server: []*protocol.ServerEndpoint{
  70. {
  71. Address: &net.IPOrDomain{
  72. Address: &net.IPOrDomain_Ip{
  73. Ip: []byte{127, 0, 0, 1},
  74. },
  75. },
  76. Port: 1234,
  77. User: []*protocol.User{
  78. {
  79. Email: "test@email.com",
  80. Account: serial.ToTypedMessage(&socks.Account{
  81. Username: "test user",
  82. Password: "test pass",
  83. }),
  84. },
  85. },
  86. },
  87. },
  88. },
  89. },
  90. })
  91. }