pia_wireguard_outbound_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package xray
  2. import (
  3. "encoding/base64"
  4. "testing"
  5. )
  6. func testWGKey(seed byte) string {
  7. raw := make([]byte, 32)
  8. for i := range raw {
  9. raw[i] = seed
  10. }
  11. return base64.StdEncoding.EncodeToString(raw)
  12. }
  13. func TestValidateOutboundConfig_PiaUserspaceWireGuard(t *testing.T) {
  14. piaOutbound := `{
  15. "tag": "pia-us-east-useast1",
  16. "piaHostname": "useast1",
  17. "protocol": "wireguard",
  18. "settings": {
  19. "secretKey": "` + testWGKey(1) + `",
  20. "address": ["10.0.0.2/32"],
  21. "mtu": 1420,
  22. "noKernelTun": true,
  23. "peers": [{
  24. "publicKey": "` + testWGKey(2) + `",
  25. "endpoint": "198.51.100.10:51820",
  26. "allowedIPs": ["0.0.0.0/0"],
  27. "keepAlive": 25
  28. }]
  29. }
  30. }`
  31. if err := ValidateOutboundConfig([]byte(piaOutbound)); err != nil {
  32. t.Fatalf("xray-core rejected the PIA WireGuard outbound the panel emits: %v", err)
  33. }
  34. second := `{
  35. "tag": "pia-us-west-uswest1",
  36. "piaHostname": "uswest1",
  37. "protocol": "wireguard",
  38. "settings": {
  39. "secretKey": "` + testWGKey(1) + `",
  40. "address": ["10.0.0.2/32"],
  41. "mtu": 1420,
  42. "noKernelTun": true,
  43. "peers": [{
  44. "publicKey": "` + testWGKey(2) + `",
  45. "endpoint": "198.51.100.20:51820",
  46. "allowedIPs": ["0.0.0.0/0"],
  47. "keepAlive": 25
  48. }]
  49. }
  50. }`
  51. if err := ValidateOutboundConfig([]byte(second)); err != nil {
  52. t.Fatalf("second PIA WireGuard outbound: %v", err)
  53. }
  54. }