MCPcopy Create free account
hub / github.com/PasarGuard/node / TestConfigInterfaceNetworks

Function TestConfigInterfaceNetworks

backend/wireguard/config_test.go:8–25  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestConfigInterfaceNetworks(t *testing.T) {
9 cfg := &Config{Address: []string{" 10.8.0.1/24 ", ""}}
10 nets := cfg.InterfaceNetworks()
11 if len(nets) != 1 {
12 t.Fatalf("expected 1 network, got %d", len(nets))
13 }
14 if nets[0].String() != "10.8.0.0/24" {
15 t.Fatalf("unexpected network: %s", nets[0].String())
16 }
17 _, ipn, _ := net.ParseCIDR("10.8.0.5/32")
18 if !peerIPAllowedOnInterface(ipn, nets) {
19 t.Fatal("expected 10.8.0.5/32 to be allowed under 10.8.0.0/24")
20 }
21 _, wrong, _ := net.ParseCIDR("10.0.0.2/32")
22 if peerIPAllowedOnInterface(wrong, nets) {
23 t.Fatal("expected 10.0.0.2/32 to be rejected under 10.8.0.0/24")
24 }
25}
26
27func TestNewWireGuardConfig(t *testing.T) {
28 configJSON := `{

Callers

nothing calls this directly

Calls 3

InterfaceNetworksMethod · 0.95
peerIPAllowedOnInterfaceFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected