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

Function configureNamespaceWGClient

backend/wireguard/integration_e2e_test.go:289–332  ·  view source on GitHub ↗
(
	t *testing.T,
	ns *namespaceFixture,
	iface string,
	clientPrivateKey string,
	clientWGIP string,
	serverPublicKey string,
	serverEndpointPort int,
	serverWGIP string,
)

Source from the content-addressed store, hash-verified

287}
288
289func configureNamespaceWGClient(
290 t *testing.T,
291 ns *namespaceFixture,
292 iface string,
293 clientPrivateKey string,
294 clientWGIP string,
295 serverPublicKey string,
296 serverEndpointPort int,
297 serverWGIP string,
298) {
299 t.Helper()
300
301 keyFile, err := os.CreateTemp("", "wg-client-key-*")
302 if err != nil {
303 t.Fatalf("failed to create temp key file: %v", err)
304 }
305 if _, err = keyFile.WriteString(clientPrivateKey + "\n"); err != nil {
306 _ = keyFile.Close()
307 t.Fatalf("failed to write temp key file: %v", err)
308 }
309 if err = keyFile.Close(); err != nil {
310 t.Fatalf("failed to close temp key file: %v", err)
311 }
312 t.Cleanup(func() {
313 _ = os.Remove(keyFile.Name())
314 })
315
316 runCommand(t, "ip", "netns", "exec", ns.name, "ip", "link", "add", "dev", iface, "type", "wireguard")
317 runCommand(t, "ip", "netns", "exec", ns.name, "ip", "address", "add", clientWGIP+"/32", "dev", iface)
318
319 endpoint := fmt.Sprintf("%s:%d", ns.hostTransitIP, serverEndpointPort)
320 runCommand(
321 t,
322 "ip", "netns", "exec", ns.name,
323 "wg", "set", iface,
324 "private-key", keyFile.Name(),
325 "peer", serverPublicKey,
326 "endpoint", endpoint,
327 "allowed-ips", serverWGIP+"/32",
328 )
329
330 runCommand(t, "ip", "netns", "exec", ns.name, "ip", "link", "set", "up", "dev", iface)
331 runCommand(t, "ip", "netns", "exec", ns.name, "ip", "route", "replace", serverWGIP+"/32", "dev", iface)
332}
333
334func configureNamespaceWGClientDualStack(
335 t *testing.T,

Callers 3

Calls 2

runCommandFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected