package e2e import ( "fmt" "os" "os/exec" "path/filepath" "strings" "testing" ) func TestConfigPropagation(t *testing.T) { binaryPath := EnsureBinary(t) tmpConfigDir := t.TempDir() tmpRuntimeDir := t.TempDir() profile := "config-test-vpn" // Write a valid dummy profile for config-test-vpn so it doesn't fail the profile-existence check confContent := `[Interface] PrivateKey = YXNkZmFzZGZhc2RmYXNkZmFzZGZhc2RmYXNkZmFzZGY= Address = 10.0.0.2/24 [Peer] PublicKey = YXNkZmFzZGZhc2RmYXNkZmFzZGZhc2RmYXNkZmFzZGY= Endpoint = 127.0.0.1:51820 AllowedIPs = 10.0.0.0/24 ` profilesDir := filepath.Join(tmpConfigDir, "wg-wrap", "profiles") _ = os.MkdirAll(profilesDir, 0755) _ = os.WriteFile(filepath.Join(profilesDir, profile+".conf"), []byte(confContent), 0644) // 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), fmt.Sprintf("XDG_CONFIG_HOME=%s", tmpConfigDir), ) 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) cmdIsolated := exec.Command(binaryPath, "run", "--profile", profile, "--", "sh", "-c", "echo $XDG_RUNTIME_DIR") cmdIsolated.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir), fmt.Sprintf("XDG_CONFIG_HOME=%s", tmpConfigDir), ) 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)) } }