wireguard_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. Log: &option.LogOptions{
  22. Level: "error",
  23. },
  24. Inbounds: []option.Inbound{
  25. {
  26. Type: C.TypeMixed,
  27. MixedOptions: option.HTTPMixedInboundOptions{
  28. ListenOptions: option.ListenOptions{
  29. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  30. ListenPort: clientPort,
  31. },
  32. },
  33. },
  34. },
  35. Outbounds: []option.Outbound{
  36. {
  37. Type: C.TypeWireGuard,
  38. WireGuardOptions: option.WireGuardOutboundOptions{
  39. ServerOptions: option.ServerOptions{
  40. Server: "127.0.0.1",
  41. ServerPort: serverPort,
  42. },
  43. LocalAddress: []string{"10.0.0.2/32"},
  44. PrivateKey: "qGnwlkZljMxeECW8fbwAWdvgntnbK7B8UmMFl3zM0mk=",
  45. PeerPublicKey: "QsdcBm+oJw2oNv0cIFXLIq1E850lgTBonup4qnKEQBg=",
  46. },
  47. },
  48. },
  49. })
  50. testSuitWg(t, clientPort, testPort)
  51. }