socks_test.go 1.9 KB

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