wireguard_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "net/netip"
  4. "testing"
  5. "time"
  6. C "github.com/sagernet/sing-box/constant"
  7. "github.com/sagernet/sing-box/option"
  8. )
  9. func _TestWireGuard(t *testing.T) {
  10. startDockerContainer(t, DockerOptions{
  11. Image: ImageBoringTun,
  12. Cap: []string{"MKNOD", "NET_ADMIN", "NET_RAW"},
  13. Ports: []uint16{serverPort, testPort},
  14. Bind: map[string]string{
  15. "wireguard.conf": "/etc/wireguard/wg0.conf",
  16. },
  17. Cmd: []string{"wg0"},
  18. })
  19. time.Sleep(5 * time.Second)
  20. startInstance(t, option.Options{
  21. Inbounds: []option.Inbound{
  22. {
  23. Type: C.TypeMixed,
  24. MixedOptions: option.HTTPMixedInboundOptions{
  25. ListenOptions: option.ListenOptions{
  26. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  27. ListenPort: clientPort,
  28. },
  29. },
  30. },
  31. },
  32. Outbounds: []option.Outbound{
  33. {
  34. Type: C.TypeWireGuard,
  35. WireGuardOptions: option.WireGuardOutboundOptions{
  36. ServerOptions: option.ServerOptions{
  37. Server: "127.0.0.1",
  38. ServerPort: serverPort,
  39. },
  40. LocalAddress: []netip.Prefix{netip.MustParsePrefix("10.0.0.2/32")},
  41. PrivateKey: "qGnwlkZljMxeECW8fbwAWdvgntnbK7B8UmMFl3zM0mk=",
  42. PeerPublicKey: "QsdcBm+oJw2oNv0cIFXLIq1E850lgTBonup4qnKEQBg=",
  43. },
  44. },
  45. },
  46. })
  47. testSuitWg(t, clientPort, testPort)
  48. }