Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Verify host uninstall enforces token binding

rcourtman895a7e07e2fa
diff --git a/internal/api/host_agents_additional_test.go b/internal/api/host_agents_additional_test.go
index 61737f768b..b41dbdf3b6 100644
--- a/internal/api/host_agents_additional_test.go
+++ b/internal/api/host_agents_additional_test.go
@@ -164,6 +164,31 @@ func TestHostAgentHandlers_HandleUninstall(t *testing.T) {
}
}
+func TestHostAgentHandlers_HandleUninstallRejectsTokenMismatch(t *testing.T) {
+ handler, monitor := newHostAgentHandlers(t, nil)
+ hostID := seedHostAgent(t, monitor)
+
+ state := monitorState(t, monitor)
+ state.UpsertHost(models.Host{
+ ID: hostID,
+ Hostname: "host-token-mismatch.local",
+ TokenID: "token-1",
+ })
+
+ body := []byte(`{"hostId":"` + hostID + `"}`)
+ req := httptest.NewRequest(http.MethodPost, "/api/agents/host/uninstall", bytes.NewReader(body))
+ attachAPITokenRecord(req, &config.APITokenRecord{
+ ID: "token-2",
+ Scopes: []string{config.ScopeHostReport},
+ })
+ rec := httptest.NewRecorder()
+
+ handler.HandleUninstall(rec, req)
+ if rec.Code != http.StatusForbidden {
+ t.Fatalf("status = %d, want 403: %s", rec.Code, rec.Body.String())
+ }
+}
+
func TestHostAgentHandlers_HandleLinkUnlink(t *testing.T) {
handler, monitor := newHostAgentHandlers(t, nil)
hostID := seedHostAgent(t, monitor)