Ver Fonte

fix(httpapi): lift the deleted-client tombstone on successful known-mac re-add (#1532)

Closes #1530.

The #1278 revival path never lifted the tombstone: DeleteDeletedClient sat inside the UpsertKnownMac error branch, so a hand-deleted client could not come back through PUT /api/settings/known-macs even with a live lease and a reachable ARP entry. The lift now runs on the success path, after the upsert, and the regression test seeds a tombstone and asserts it is gone after the PUT.

Co-authored-by: Bann-DEV <bann.dev@gmail.com>
Bann-DEV há 1 mês atrás
pai
commit
07bdf089e3

+ 3 - 1
server-go/internal/httpapi/settings.go

@@ -380,10 +380,12 @@ func (s *server) registerKnownMacsRoutes(mux *http.ServeMux) {
 			return
 		}
 		if err := s.db.UpsertKnownMac(db.KnownMac{MAC: mac, Name: body.Name, Note: body.Note}); err != nil {
-		_ = s.db.DeleteDeletedClient(mac) // #1278: re-alta manual quita la lápida
 			writeError(w, http.StatusInternalServerError, "db_error")
 			return
 		}
+		// #1278: re-alta manual quita la lápida (en el camino de éxito: en el
+		// de error no se registró nada y la lápida debe quedarse).
+		_ = s.db.DeleteDeletedClient(mac)
 		writeJSON(w, http.StatusOK, knownMacItem{MAC: mac, Name: body.Name, Note: body.Note})
 	})))
 

+ 24 - 0
server-go/internal/httpapi/settings_knownmacs_test.go

@@ -55,6 +55,30 @@ func TestKnownMacsRoundtrip(t *testing.T) {
 	}
 }
 
+// TestKnownMacsPutLiftsTombstone (#1278): la re-alta manual quita la lápida
+// para que el cliente pueda volver a alta solo desde las fuentes vivas. El
+// bug: la llamada vivía en la rama de error del upsert y el camino de éxito
+// nunca la ejecutaba (el borrado manual era irreversible en la práctica).
+func TestKnownMacsPutLiftsTombstone(t *testing.T) {
+	srv := makeTestServer(t)
+	_, cookie, _ := loginCookie(t, srv.URL, "admin", "test123456")
+	const mac = "38:B8:00:0A:24:37"
+	if err := srv.db.AddDeletedClient(mac); err != nil {
+		t.Fatalf("AddDeletedClient: %v", err)
+	}
+	if tomb, _ := srv.db.DeletedClients(); !tomb[mac] {
+		t.Fatal("prepara: la lápida no quedó registrada")
+	}
+	res, _ := wanSpeedRequest(t, "PUT", srv.URL, "/api/settings/known-macs", cookie,
+		`{"mac":"`+mac+`","name":"","note":"re-alta"}`)
+	if res.StatusCode != http.StatusOK {
+		t.Fatalf("PUT: status %d, esperado 200", res.StatusCode)
+	}
+	if tomb, _ := srv.db.DeletedClients(); tomb[mac] {
+		t.Fatal("PUT conocido no levantó la lápida (#1278)")
+	}
+}
+
 // TestKnownMacsInvalidInput: MAC mal formada → 400; PUT sin admin → 401.
 func TestKnownMacsInvalidInput(t *testing.T) {
 	srv := makeTestServer(t)