socks_test.go 2.0 KB

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