High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(profiles): implement profile rename via PATCH endpoint
Data2cce10a4321d
diff --git a/dashboard/src/pages/ProfilesPage.tsx b/dashboard/src/pages/ProfilesPage.tsxindex c62d3d63..705ce1d5 100644--- a/dashboard/src/pages/ProfilesPage.tsx+++ b/dashboard/src/pages/ProfilesPage.tsx@@ -118,6 +118,20 @@ export default function ProfilesPage() {}};+ const handleSave = async (name: string, useWhen: string) => {+ if (!showDetails?.id) return;+ try {+ await api.updateProfile(showDetails.id, {+ name: name !== showDetails.name ? name : undefined,+ useWhen: useWhen !== showDetails.useWhen ? useWhen : undefined,+ });+ setShowDetails(null);+ loadProfiles();+ } catch (e) {+ console.error("Failed to update profile", e);+ }+ };+// Generate launch commandconst launchCommand = useMemo(() => {if (!showLaunch) return "";@@ -312,6 +326,7 @@ export default function ProfilesPage() {showDetails ? instanceByProfile.get(showDetails.name) : undefined}onClose={() => setShowDetails(null)}+ onSave={handleSave}onDelete={handleDelete}/></div>diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.tsindex 1b0afb70..10980be3 100644--- a/dashboard/src/services/api.ts+++ b/dashboard/src/services/api.ts@@ -42,6 +42,29 @@ export async function deleteProfile(id: string): Promise<void> {});}+export interface UpdateProfileRequest {+ name?: string;+ useWhen?: string;+ description?: string;+}++export interface UpdateProfileResponse {+ status: string;+ id: string;+ name: string;+}++export async function updateProfile(+ id: string,+ data: UpdateProfileRequest,+): Promise<UpdateProfileResponse> {+ return request<UpdateProfileResponse>(`/profiles/${encodeURIComponent(id)}`, {+ method: "PATCH",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify(data),+ });+}+// Instances — endpoint is /instances (no /api prefix)export async function fetchInstances(): Promise<Instance[]> {return request<Instance[]>("/instances");diff --git a/docs/references/profile-api.md b/docs/references/profile-api.mdindex 514154f8..d7c7e5db 100644--- a/docs/references/profile-api.md+++ b/docs/references/profile-api.md@@ -197,23 +197,31 @@ curl -X POST http://localhost:9867/profiles \**Endpoint:** `PATCH /profiles/{id}`**Parameters:**-- `id` (string, path) — Profile ID or name+- `id` (string, path) — Profile ID (e.g. `prof_abc123`). Name is not accepted.+- `name` (string, body, optional) — New name for the profile (rename)- `description` (string, body, optional) — Profile description- `useWhen` (string, body, optional) — Use case guidance for agents**Curl:**```bash-curl -X PATCH http://localhost:9867/profiles/my-profile \+# Update metadata+curl -X PATCH http://localhost:9867/profiles/prof_abc123 \-H "Content-Type: application/json" \-d '{"description": "Updated description","useWhen": "Updated use case"}'++# Rename a profile+curl -X PATCH http://localhost:9867/profiles/prof_abc123 \+ -H "Content-Type: application/json" \+ -d '{"name": "new-name"}'```**Request Body:**```json{+ "name": "new-profile-name","description": "New description for the profile","useWhen": "New use case guidance"}@@ -223,14 +231,17 @@ curl -X PATCH http://localhost:9867/profiles/my-profile \```json{"status": "updated",- "id": "my-profile",- "name": "my-profile"+ "id": "prof_def456",+ "name": "new-profile-name"}```**Notes:**- Only provided fields are updated-- Can omit either field to update only one+- Can omit any field to update only the others+- **Must use profile ID, not name** — returns 404 if name is used+- Renaming updates both the profile name and generates a new ID+- Returns 409 Conflict if the new name already exists---@@ -239,28 +250,29 @@ curl -X PATCH http://localhost:9867/profiles/my-profile \**Endpoint:** `DELETE /profiles/{id}`**Parameters:**-- `id` (string, path) — Profile ID or name+- `id` (string, path) — Profile ID (e.g. `prof_abc123`). Name is not accepted.**CLI:**```bash-pinchtab profile delete my-profile+pinchtab profile delete prof_abc123```**Curl:**```bash-curl -X DELETE http://localhost:9867/profiles/my-profile+curl -X DELETE http://localhost:9867/profiles/prof_abc123```**Response:**```json{"status": "deleted",- "id": "my-profile",+ "id": "prof_abc123","name": "my-profile"}```**Notes:**+- **Must use profile ID, not name** — returns 404 if name is used- Recursively deletes entire profile directory- Returns 404 if profile not found- Deletion is permanent and cannot be undone@@ -272,18 +284,18 @@ curl -X DELETE http://localhost:9867/profiles/my-profile**Endpoint:** `POST /profiles/{id}/reset`**Parameters:**-- `id` (string, path) — Profile ID or name+- `id` (string, path) — Profile ID (e.g. `prof_abc123`). Name is not accepted.**Curl:**```bash-curl -X POST http://localhost:9867/profiles/my-profile/reset+curl -X POST http://localhost:9867/profiles/prof_abc123/reset```**Response:**```json{"status": "reset",- "id": "my-profile",+ "id": "prof_abc123","name": "my-profile"}```@@ -789,7 +801,7 @@ async function deleteProfile(id) {## FAQ**Q: Can I rename a profile?**-A: Not directly. Create a new profile with the desired name and delete the old one.+A: Yes, use `PATCH /profiles/{id}` with `{"name": "new-name"}` in the request body. You must use the profile ID (e.g. `prof_abc123`), not the profile name.**Q: Can I move profiles to different machines?**A: Yes, use POST /profiles/import with the profile directory from another machine.@@ -818,9 +830,9 @@ A: Copy the profile directory from `~/.pinchtab/profiles/<name>/`.| List | GET | `/profiles` | None || Get | GET | `/profiles/{id}` | ID or name || Create | POST | `/profiles` | Name |-| Update | PATCH | `/profiles/{id}` | ID or name |-| Delete | DELETE | `/profiles/{id}` | ID or name |-| Reset | POST | `/profiles/{id}/reset` | ID or name |+| Update | PATCH | `/profiles/{id}` | **ID only** |+| Delete | DELETE | `/profiles/{id}` | **ID only** |+| Reset | POST | `/profiles/{id}/reset` | **ID only** || Logs | GET | `/profiles/{id}/logs` | ID or name || Analytics | GET | `/profiles/{id}/analytics` | ID or name || Import | POST | `/profiles/import` | Name + source path |diff --git a/internal/profiles/handlers.go b/internal/profiles/handlers.goindex 929c9864..8ebdac26 100644--- a/internal/profiles/handlers.go+++ b/internal/profiles/handlers.go@@ -22,7 +22,7 @@ func (pm *ProfileManager) RegisterHandlers(mux *http.ServeMux) {mux.HandleFunc("GET /profiles/{id}/logs", pm.handleLogsByIDOrName)mux.HandleFunc("GET /profiles/{id}/analytics", pm.handleAnalyticsByIDOrName)mux.HandleFunc("DELETE /profiles/{id}", pm.handleDeleteByID)- mux.HandleFunc("PATCH /profiles/{id}", pm.handleUpdateByIDOrName)+ mux.HandleFunc("PATCH /profiles/{id}", pm.handleUpdateByID)}func (pm *ProfileManager) handleList(w http.ResponseWriter, r *http.Request) {@@ -208,17 +208,14 @@ func (pm *ProfileManager) handleGetByID(w http.ResponseWriter, r *http.Request)func (pm *ProfileManager) handleDeleteByID(w http.ResponseWriter, r *http.Request) {id := r.PathValue("id")- name, err := pm.FindByID(id)+ name, err := pm.resolveIDOnly(id)if err != nil {- name = id- if !pm.Exists(name) {- web.Error(w, 404, fmt.Errorf("profile %q not found", id))- return- }+ web.Error(w, 404, err)+ return}if err := pm.Delete(name); err != nil {- web.Error(w, 404, err)+ web.Error(w, 500, err)return}@@ -236,9 +233,17 @@ func (pm *ProfileManager) resolveIDOrName(idOrName string) (string, error) {return "", fmt.Errorf("profile %q not found (not a valid ID or name)", idOrName)}-func (pm *ProfileManager) handleUpdateByIDOrName(w http.ResponseWriter, r *http.Request) {- idOrName := r.PathValue("id")- name, err := pm.resolveIDOrName(idOrName)+func (pm *ProfileManager) resolveIDOnly(id string) (string, error) {+ name, err := pm.FindByID(id)+ if err != nil {+ return "", fmt.Errorf("profile %q not found (must use profile ID, not name)", id)+ }+ return name, nil+}++func (pm *ProfileManager) handleUpdateByID(w http.ResponseWriter, r *http.Request) {+ id := r.PathValue("id")+ name, err := pm.resolveIDOnly(id)if err != nil {web.Error(w, 404, err)return@@ -254,6 +259,21 @@ func (pm *ProfileManager) handleUpdateByIDOrName(w http.ResponseWriter, r *http.return}+ finalName := name+ if req.Name != "" && req.Name != name {+ if err := pm.Rename(name, req.Name); err != nil {+ if strings.Contains(err.Error(), "already exists") {+ web.Error(w, 409, err)+ } else if strings.Contains(err.Error(), "cannot contain") || strings.Contains(err.Error(), "cannot be empty") {+ web.Error(w, 400, err)+ } else {+ web.Error(w, 500, err)+ }+ return+ }+ finalName = req.Name+ }+updates := make(map[string]string)if req.Description != "" {updates["description"] = req.Description@@ -262,28 +282,28 @@ func (pm *ProfileManager) handleUpdateByIDOrName(w http.ResponseWriter, r *http.updates["useWhen"] = req.UseWhen}if len(updates) > 0 {- if err := pm.UpdateMeta(name, updates); err != nil {- web.Error(w, 404, err)+ if err := pm.UpdateMeta(finalName, updates); err != nil {+ web.Error(w, 500, err)return}}- web.JSON(w, 200, map[string]any{"status": "updated", "id": idOrName, "name": name})+ web.JSON(w, 200, map[string]any{"status": "updated", "id": profileID(finalName), "name": finalName})}func (pm *ProfileManager) handleResetByIDOrName(w http.ResponseWriter, r *http.Request) {- idOrName := r.PathValue("id")- name, err := pm.resolveIDOrName(idOrName)+ id := r.PathValue("id")+ name, err := pm.resolveIDOnly(id)if err != nil {web.Error(w, 404, err)return}if err := pm.Reset(name); err != nil {- web.Error(w, 404, err)+ web.Error(w, 500, err)return}- web.JSON(w, 200, map[string]any{"status": "reset", "id": idOrName, "name": name})+ web.JSON(w, 200, map[string]any{"status": "reset", "id": id, "name": name})}func (pm *ProfileManager) handleLogsByIDOrName(w http.ResponseWriter, r *http.Request) {diff --git a/internal/profiles/profiles.go b/internal/profiles/profiles.goindex eb0301c1..d6b463bd 100644--- a/internal/profiles/profiles.go+++ b/internal/profiles/profiles.go@@ -429,6 +429,52 @@ func (pm *ProfileManager) UpdateMeta(name string, meta map[string]string) errorreturn writeProfileMeta(dir, existing)}+func (pm *ProfileManager) Rename(oldName, newName string) error {+ if err := ValidateProfileName(oldName); err != nil {+ return err+ }+ if err := ValidateProfileName(newName); err != nil {+ return err+ }+ if oldName == newName {+ return nil+ }++ pm.mu.Lock()+ defer pm.mu.Unlock()++ oldDir, err := pm.findProfileDirByName(oldName)+ if err != nil {+ return err+ }++ if _, err := pm.findProfileDirByName(newName); err == nil {+ return fmt.Errorf("profile %q already exists", newName)+ }++ newDir := filepath.Join(pm.baseDir, profileID(newName))+ if _, err := os.Stat(newDir); err == nil {+ return fmt.Errorf("profile directory for %q already exists", newName)+ }++ meta := readProfileMeta(oldDir)+ meta.ID = profileID(newName)+ meta.Name = newName+ if err := writeProfileMeta(oldDir, meta); err != nil {+ return fmt.Errorf("failed to update profile metadata: %w", err)+ }++ if err := os.Rename(oldDir, newDir); err != nil {+ meta.ID = profileID(oldName)+ meta.Name = oldName+ _ = writeProfileMeta(oldDir, meta)+ return fmt.Errorf("failed to rename profile directory: %w", err)+ }++ slog.Info("profile renamed", "from", oldName, "to", newName)+ return nil+}+func (pm *ProfileManager) FindByID(id string) (string, error) {pm.mu.RLock()defer pm.mu.RUnlock()diff --git a/internal/profiles/profiles_test.go b/internal/profiles/profiles_test.goindex 09e254b9..3e199716 100644--- a/internal/profiles/profiles_test.go+++ b/internal/profiles/profiles_test.go@@ -296,10 +296,11 @@ func TestProfileHandlerCreate(t *testing.T) {func TestProfileHandlerReset(t *testing.T) {pm := NewProfileManager(t.TempDir())_ = pm.Create("resettable")+ id := profileID("resettable")mux := http.NewServeMux()pm.RegisterHandlers(mux)- req := httptest.NewRequest("POST", "/profiles/resettable/reset", nil)+ req := httptest.NewRequest("POST", "/profiles/"+id+"/reset", nil)w := httptest.NewRecorder()mux.ServeHTTP(w, req)@@ -311,10 +312,11 @@ func TestProfileHandlerReset(t *testing.T) {func TestProfileHandlerDelete(t *testing.T) {pm := NewProfileManager(t.TempDir())_ = pm.Create("deletable")+ id := profileID("deletable")mux := http.NewServeMux()pm.RegisterHandlers(mux)- req := httptest.NewRequest("DELETE", "/profiles/deletable", nil)+ req := httptest.NewRequest("DELETE", "/profiles/"+id, nil)w := httptest.NewRecorder()mux.ServeHTTP(w, req)@@ -606,3 +608,63 @@ func TestProfileDeleteRejectsPathTraversal(t *testing.T) {})}}++func TestProfileRename(t *testing.T) {+ dir := t.TempDir()+ pm := NewProfileManager(dir)++ if err := pm.Create("old-name"); err != nil {+ t.Fatal(err)+ }++ if err := pm.Rename("old-name", "new-name"); err != nil {+ t.Fatalf("Rename failed: %v", err)+ }++ if pm.Exists("old-name") {+ t.Error("old name should not exist after rename")+ }+ if !pm.Exists("new-name") {+ t.Error("new name should exist after rename")+ }++ profiles, _ := pm.List()+ if len(profiles) != 1 {+ t.Fatalf("expected 1 profile, got %d", len(profiles))+ }+ if profiles[0].Name != "new-name" {+ t.Errorf("expected name new-name, got %s", profiles[0].Name)+ }+ if profiles[0].ID != profileID("new-name") {+ t.Errorf("expected ID %s, got %s", profileID("new-name"), profiles[0].ID)+ }+}++func TestProfileRenameRejectsPathTraversal(t *testing.T) {+ pm := NewProfileManager(t.TempDir())+ _ = pm.Create("legit")++ badNames := []string{"../evil", "evil/../other", "..\\windows"}+ for _, name := range badNames {+ t.Run("to_"+name, func(t *testing.T) {+ err := pm.Rename("legit", name)+ if err == nil {+ t.Errorf("Rename to %q should have returned error", name)+ }+ })+ }+}++func TestProfileRenameRejectsDuplicate(t *testing.T) {+ pm := NewProfileManager(t.TempDir())+ _ = pm.Create("profile-a")+ _ = pm.Create("profile-b")++ err := pm.Rename("profile-a", "profile-b")+ if err == nil {+ t.Error("Rename to existing name should fail")+ }+ if !strings.Contains(err.Error(), "already exists") {+ t.Errorf("expected 'already exists' error, got: %v", err)+ }+}diff --git a/tests/integration/helpers_test.go b/tests/integration/helpers_test.goindex 9d369a4a..8a82442e 100644--- a/tests/integration/helpers_test.go+++ b/tests/integration/helpers_test.go@@ -11,6 +11,45 @@ import ("time")+func httpPatch(t *testing.T, path string, payload any) (int, []byte) {+ t.Helper()+ var reader io.Reader+ if payload != nil {+ data, err := json.Marshal(payload)+ if err != nil {+ t.Fatalf("marshal failed: %v", err)+ }+ reader = strings.NewReader(string(data))+ }+ req, err := http.NewRequest("PATCH", serverURL+path, reader)+ if err != nil {+ t.Fatalf("PATCH %s request creation failed: %v", path, err)+ }+ req.Header.Set("Content-Type", "application/json")+ resp, err := http.DefaultClient.Do(req)+ if err != nil {+ t.Fatalf("PATCH %s failed: %v", path, err)+ }+ defer resp.Body.Close() //nolint:errcheck+ body, _ := io.ReadAll(resp.Body)+ return resp.StatusCode, body+}++func httpDelete(t *testing.T, path string) (int, []byte) {+ t.Helper()+ req, err := http.NewRequest("DELETE", serverURL+path, nil)+ if err != nil {+ t.Fatalf("DELETE %s request creation failed: %v", path, err)+ }+ resp, err := http.DefaultClient.Do(req)+ if err != nil {+ t.Fatalf("DELETE %s failed: %v", path, err)+ }+ defer resp.Body.Close() //nolint:errcheck+ body, _ := io.ReadAll(resp.Body)+ return resp.StatusCode, body+}+// httpPostWithRetry attempts a POST request with retries for flaky testsfunc httpPostWithRetry(t *testing.T, path string, body any, maxRetries int) (int, []byte) {t.Helper()diff --git a/tests/integration/main_test.go b/tests/integration/main_test.goindex 16e0c964..ea8a5ff8 100644--- a/tests/integration/main_test.go+++ b/tests/integration/main_test.go@@ -15,8 +15,9 @@ import ()var (- serverURL string- currentTabID string // Track current tab for action operations+ serverURL string+ currentTabID string // Track current tab for action operations+ testBinaryPath string)func TestMain(m *testing.M) {@@ -26,8 +27,11 @@ func TestMain(m *testing.M) {}serverURL = fmt.Sprintf("http://localhost:%s", port)+ // Use unique binary path to avoid conflicts with other users+ testBinaryPath = fmt.Sprintf("/tmp/pinchtab-test-%d", os.Getpid())+// Build the binary- build := exec.Command("go", "build", "-o", "/tmp/pinchtab-test", "./cmd/pinchtab/")+ build := exec.Command("go", "build", "-o", testBinaryPath, "./cmd/pinchtab/")build.Dir = findRepoRoot()build.Stdout = os.Stdoutbuild.Stderr = os.Stderr@@ -35,9 +39,11 @@ func TestMain(m *testing.M) {fmt.Fprintf(os.Stderr, "failed to build pinchtab: %v\n", err)os.Exit(1)}+ // Clean up binary on exit+ defer os.Remove(testBinaryPath)// Start server- cmd := exec.Command("/tmp/pinchtab-test")+ cmd := exec.Command(testBinaryPath)// Build environment for subprocess// Start with a filtered set of inherited env vars, then add test-specific onesdiff --git a/tests/integration/profile_rename_test.go b/tests/integration/profile_rename_test.gonew file mode 100644index 00000000..b4608d33--- /dev/null+++ b/tests/integration/profile_rename_test.go@@ -0,0 +1,193 @@+//go:build integration++package integration++import (+ "testing"+)++// TestProfileRename_FullFlow tests the complete profile rename workflow:+// 1. Create profile → get ID+// 2. Rename via PATCH using ID → get new ID+// 3. Verify accessible by new ID+// 4. Verify old ID no longer works+// 5. Verify name-based access still works (GET only)+// 6. Clean up+func TestProfileRename_FullFlow(t *testing.T) {+ // Step 1: Create profile+ code, body := httpPost(t, "/profiles/create", map[string]any{+ "name": "integration-rename-test",+ })+ if code != 200 {+ t.Fatalf("create failed: %d %s", code, string(body))+ }++ originalID := jsonField(t, body, "id")+ if originalID == "" {+ t.Fatal("no ID in create response")+ }+ t.Logf("created profile with ID: %s", originalID)++ // Step 2: Rename using ID+ code, body = httpPatch(t, "/profiles/"+originalID, map[string]any{+ "name": "integration-rename-test-renamed",+ })+ if code != 200 {+ t.Fatalf("rename failed: %d %s", code, string(body))+ }++ newID := jsonField(t, body, "id")+ newName := jsonField(t, body, "name")+ if newID == "" {+ t.Fatal("no ID in rename response")+ }+ if newName != "integration-rename-test-renamed" {+ t.Errorf("expected name 'integration-rename-test-renamed', got %q", newName)+ }+ t.Logf("renamed to %q with new ID: %s", newName, newID)++ // Step 3: Verify accessible by new ID+ code, body = httpGet(t, "/profiles/"+newID)+ if code != 200 {+ t.Errorf("GET by new ID failed: %d %s", code, string(body))+ }++ // Step 4: Verify old ID no longer works+ code, _ = httpGet(t, "/profiles/"+originalID)+ if code == 200 {+ t.Error("old ID should return 404 after rename")+ }++ // Step 5: Verify GET by name still works (read-only endpoints allow name)+ code, body = httpGet(t, "/profiles/integration-rename-test-renamed")+ if code != 200 {+ t.Errorf("GET by name failed: %d %s", code, string(body))+ }++ // Step 6: Clean up+ code, _ = httpDelete(t, "/profiles/"+newID)+ if code != 200 {+ t.Errorf("cleanup delete failed: %d", code)+ }+}++// TestProfileRename_RequiresID verifies PATCH rejects name-based paths+func TestProfileRename_RequiresID(t *testing.T) {+ // Create profile+ code, body := httpPost(t, "/profiles/create", map[string]any{+ "name": "rename-requires-id-test",+ })+ if code != 200 {+ t.Fatalf("create failed: %d %s", code, string(body))+ }+ profileID := jsonField(t, body, "id")+ defer httpDelete(t, "/profiles/"+profileID)++ // Try PATCH by name - should fail with 404+ code, body = httpPatch(t, "/profiles/rename-requires-id-test", map[string]any{+ "name": "new-name",+ })+ if code != 404 {+ t.Errorf("expected 404 when using name, got %d: %s", code, string(body))+ }++ // Verify error message is clear+ errMsg := jsonField(t, body, "error")+ if errMsg == "" {+ t.Error("expected error message in response")+ }+ t.Logf("error message: %s", errMsg)+}++// TestProfileRename_DeleteRequiresID verifies DELETE rejects name-based paths+func TestProfileRename_DeleteRequiresID(t *testing.T) {+ // Create profile+ code, body := httpPost(t, "/profiles/create", map[string]any{+ "name": "delete-requires-id-test",+ })+ if code != 200 {+ t.Fatalf("create failed: %d %s", code, string(body))+ }+ profileID := jsonField(t, body, "id")++ // Try DELETE by name - should fail with 404+ code, body = httpDelete(t, "/profiles/delete-requires-id-test")+ if code != 404 {+ t.Errorf("expected 404 when using name, got %d: %s", code, string(body))+ }++ // Clean up with ID+ httpDelete(t, "/profiles/"+profileID)+}++// TestProfileRename_ResetRequiresID verifies POST reset rejects name-based paths+func TestProfileRename_ResetRequiresID(t *testing.T) {+ // Create profile+ code, body := httpPost(t, "/profiles/create", map[string]any{+ "name": "reset-requires-id-test",+ })+ if code != 200 {+ t.Fatalf("create failed: %d %s", code, string(body))+ }+ profileID := jsonField(t, body, "id")+ defer httpDelete(t, "/profiles/"+profileID)++ // Try reset by name - should fail with 404+ code, body = httpPost(t, "/profiles/reset-requires-id-test/reset", nil)+ if code != 404 {+ t.Errorf("expected 404 when using name, got %d: %s", code, string(body))+ }++ // Reset by ID should work+ code, body = httpPost(t, "/profiles/"+profileID+"/reset", nil)+ if code != 200 {+ t.Errorf("reset by ID failed: %d %s", code, string(body))+ }+}++// TestProfileRename_Conflict verifies rename to existing name returns 409+func TestProfileRename_Conflict(t *testing.T) {+ // Create two profiles+ _, bodyA := httpPost(t, "/profiles/create", map[string]any{"name": "conflict-test-a"})+ _, bodyB := httpPost(t, "/profiles/create", map[string]any{"name": "conflict-test-b"})+ idA := jsonField(t, bodyA, "id")+ idB := jsonField(t, bodyB, "id")+ defer httpDelete(t, "/profiles/"+idA)+ defer httpDelete(t, "/profiles/"+idB)++ // Try to rename A to B's name+ code, body := httpPatch(t, "/profiles/"+idA, map[string]any{+ "name": "conflict-test-b",+ })+ if code != 409 {+ t.Errorf("expected 409 Conflict, got %d: %s", code, string(body))+ }+}++// TestProfileRename_PathTraversal verifies rename rejects malicious names+func TestProfileRename_PathTraversal(t *testing.T) {+ // Create profile+ code, body := httpPost(t, "/profiles/create", map[string]any{+ "name": "traversal-test",+ })+ if code != 200 {+ t.Fatalf("create failed: %d %s", code, string(body))+ }+ profileID := jsonField(t, body, "id")+ defer httpDelete(t, "/profiles/"+profileID)++ malicious := []string{+ "../etc/passwd",+ "..\\windows\\system32",+ "foo/../../../bar",+ }++ for _, name := range malicious {+ code, _ := httpPatch(t, "/profiles/"+profileID, map[string]any{+ "name": name,+ })+ if code == 200 {+ t.Errorf("rename to %q should have been rejected", name)+ }+ }+}diff --git a/tests/integration/security_profiles_test.go b/tests/integration/security_profiles_test.goindex 6fec4bae..0fe16eef 100644--- a/tests/integration/security_profiles_test.go+++ b/tests/integration/security_profiles_test.go@@ -100,3 +100,5 @@ func TestProfile_ValidNamesAccepted(t *testing.T) {})}}++// Profile rename tests are in profile_rename_test.go