wireguard_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package conf_test
  2. import (
  3. "testing"
  4. . "github.com/xtls/xray-core/infra/conf"
  5. "github.com/xtls/xray-core/proxy/wireguard"
  6. )
  7. func TestWireGuardOutbound(t *testing.T) {
  8. creator := func() Buildable {
  9. return new(WireGuardConfig)
  10. }
  11. runMultiTestCase(t, []TestCase{
  12. {
  13. Input: `{
  14. "secretKey": "uJv5tZMDltsiYEn+kUwb0Ll/CXWhMkaSCWWhfPEZM3A=",
  15. "address": ["10.1.1.1", "fd59:7153:2388:b5fd:0000:0000:1234:0001"],
  16. "peers": [
  17. {
  18. "publicKey": "6e65ce0be17517110c17d77288ad87e7fd5252dcc7d09b95a39d61db03df832a",
  19. "endpoint": "127.0.0.1:1234"
  20. }
  21. ],
  22. "mtu": 1300,
  23. "workers": 2
  24. }`,
  25. Parser: loadJSON(creator),
  26. Output: &wireguard.DeviceConfig{
  27. // key converted into hex form
  28. SecretKey: "b89bf9b5930396db226049fe914c1bd0b97f0975a13246920965a17cf1193370",
  29. Endpoint: []string{"10.1.1.1", "fd59:7153:2388:b5fd:0000:0000:1234:0001"},
  30. Peers: []*wireguard.PeerConfig{
  31. {
  32. // also can read from hex form directly
  33. PublicKey: "6e65ce0be17517110c17d77288ad87e7fd5252dcc7d09b95a39d61db03df832a",
  34. PreSharedKey: "0000000000000000000000000000000000000000000000000000000000000000",
  35. Endpoint: "127.0.0.1:1234",
  36. KeepAlive: 0,
  37. AllowedIps: []string{"0.0.0.0/0", "::0/0"},
  38. },
  39. },
  40. Mtu: 1300,
  41. NumWorkers: 2,
  42. },
  43. },
  44. })
  45. }