package e2e import ( "fmt" "os" "os/exec" "strings" "testing" ) func TestConfigPropagation(t *testing.T) { binaryPath, err := GetBinaryPath() if err != nil { t.Skipf("Skipping test: %v", err) } tmpRuntimeDir := t.TempDir() profile := "config-test-vpn" // Test 1: Non-isolated configuration cmd := exec.Command(binaryPath, "show-config", "--profile", profile) cmd.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir)) out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("show-config failed: %v\nOutput: %s", err, string(out)) } output := string(out) expectedBase := tmpRuntimeDir expectedPids := fmt.Sprintf("%s/profiles/%s/pids", tmpRuntimeDir, profile) if !strings.Contains(output, fmt.Sprintf("Runtime Base: %s", expectedBase)) { t.Errorf("Expected Runtime Base %s in output: %s", expectedBase, output) } if !strings.Contains(output, fmt.Sprintf("PIDs Path: %s", expectedPids)) { t.Errorf("Expected PIDs Path %s in output: %s", expectedPids, output) } // Test 2: Configuration after bootstrap (Isolated) // We use 'test-ns' as a way to run a command that we know is isolated. // Actually, we can just run 'show-config' but the current 'Route' // handles 'show-config' BEFORE the bootstrap. // To test isolated config, we can't use 'show-config' because it's a diagnostic // command designed to run outside isolation. // To verify what an isolated process sees, we can use a target command // that prints the environment. cmdIsolated := exec.Command(binaryPath, "--profile", profile, "--", "sh", "-c", "echo $XDG_RUNTIME_DIR") cmdIsolated.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir)) outIso, err := cmdIsolated.CombinedOutput() if err != nil { t.Fatalf("Isolated command failed: %v\nOutput: %s", err, string(outIso)) } if !strings.Contains(string(outIso), expectedBase) { t.Errorf("Expected isolated process to see XDG_RUNTIME_DIR=%s, got: %s", expectedBase, string(outIso)) } }