socks_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. "timeout": 5,
  27. "userLevel": 1
  28. }`,
  29. Parser: loadJSON(creator),
  30. Output: &socks.ServerConfig{
  31. AuthType: socks.AuthType_PASSWORD,
  32. Accounts: map[string]string{
  33. "my-username": "my-password",
  34. },
  35. UdpEnabled: false,
  36. Address: &net.IPOrDomain{
  37. Address: &net.IPOrDomain_Ip{
  38. Ip: []byte{127, 0, 0, 1},
  39. },
  40. },
  41. Timeout: 5,
  42. UserLevel: 1,
  43. },
  44. },
  45. })
  46. }
  47. func TestSocksOutboundConfig(t *testing.T) {
  48. creator := func() Buildable {
  49. return new(SocksClientConfig)
  50. }
  51. runMultiTestCase(t, []TestCase{
  52. {
  53. Input: `{
  54. "servers": [{
  55. "address": "127.0.0.1",
  56. "port": 1234,
  57. "users": [
  58. {"user": "test user", "pass": "test pass", "email": "[email protected]"}
  59. ]
  60. }]
  61. }`,
  62. Parser: loadJSON(creator),
  63. Output: &socks.ClientConfig{
  64. Server: []*protocol.ServerEndpoint{
  65. {
  66. Address: &net.IPOrDomain{
  67. Address: &net.IPOrDomain_Ip{
  68. Ip: []byte{127, 0, 0, 1},
  69. },
  70. },
  71. Port: 1234,
  72. User: []*protocol.User{
  73. {
  74. Email: "[email protected]",
  75. Account: serial.ToTypedMessage(&socks.Account{
  76. Username: "test user",
  77. Password: "test pass",
  78. }),
  79. },
  80. },
  81. },
  82. },
  83. },
  84. },
  85. })
  86. }