wireguard_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 TestWireGuardConfig(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. "domainStrategy": "ForceIPv6v4",
  25. "kernelMode": false
  26. }`,
  27. Parser: loadJSON(creator),
  28. Output: &wireguard.DeviceConfig{
  29. // key converted into hex form
  30. SecretKey: "b89bf9b5930396db226049fe914c1bd0b97f0975a13246920965a17cf1193370",
  31. Endpoint: []string{"10.1.1.1", "fd59:7153:2388:b5fd:0000:0000:1234:0001"},
  32. Peers: []*wireguard.PeerConfig{
  33. {
  34. // also can read from hex form directly
  35. PublicKey: "6e65ce0be17517110c17d77288ad87e7fd5252dcc7d09b95a39d61db03df832a",
  36. Endpoint: "127.0.0.1:1234",
  37. KeepAlive: 0,
  38. AllowedIps: []string{"0.0.0.0/0", "::0/0"},
  39. },
  40. },
  41. Mtu: 1300,
  42. NumWorkers: 2,
  43. DomainStrategy: wireguard.DeviceConfig_FORCE_IP64,
  44. KernelMode: false,
  45. },
  46. },
  47. })
  48. }