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.

Require host config read scope

rcourtman9e3b8f722efa
diff --git a/internal/api/host_agent_config_scope_test.go b/internal/api/host_agent_config_scope_test.go
new file mode 100644
index 0000000000..e80568bf92
--- /dev/null
+++ b/internal/api/host_agent_config_scope_test.go
@@ -0,0 +1,29 @@
+package api
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/config"
+)
+
+func TestHostAgentConfigRequiresHostConfigScope(t *testing.T) {
+ rawToken := "host-config-read-scope-token-123.12345678"
+ record := newTokenRecord(t, rawToken, []string{config.ScopeMonitoringRead}, nil)
+ cfg := newTestConfigWithTokens(t, record)
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ req := httptest.NewRequest(http.MethodGet, "/api/agents/host/host-1/config", nil)
+ req.Header.Set("X-API-Token", rawToken)
+ rec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(rec, req)
+
+ if rec.Code != http.StatusForbidden {
+ t.Fatalf("expected 403 for missing host-agent:config:read scope, got %d", rec.Code)
+ }
+ if !strings.Contains(rec.Body.String(), config.ScopeHostConfigRead) {
+ t.Fatalf("expected missing scope response to mention %q, got %q", config.ScopeHostConfigRead, rec.Body.String())
+ }
+}