socks_test.go 2.3 KB

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