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 security status bootstrap token exposure

rcourtman9f1877116b98
diff --git a/internal/api/security_regression_test.go b/internal/api/security_regression_test.go
index 8ee78a3cea..f6348e7375 100644
--- a/internal/api/security_regression_test.go
+++ b/internal/api/security_regression_test.go
@@ -2626,6 +2626,53 @@ func TestValidateBootstrapTokenBypassesAuth(t *testing.T) {
}
}
+func TestSecurityStatusHidesBootstrapTokenWhenAuthConfigured(t *testing.T) {
+ cfg := newTestConfigWithTokens(t)
+ cfg.AuthUser = "admin"
+ cfg.AuthPass = "hashed"
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ ResetRateLimitForIP("203.0.113.49")
+ req := httptest.NewRequest(http.MethodGet, "/api/security/status", nil)
+ req.RemoteAddr = "203.0.113.49:1234"
+ rec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(rec, req)
+ if rec.Code != http.StatusOK {
+ t.Fatalf("expected 200 for security status, got %d", rec.Code)
+ }
+
+ var payload map[string]interface{}
+ if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {
+ t.Fatalf("decode response: %v", err)
+ }
+ if _, ok := payload["bootstrapTokenPath"]; ok {
+ t.Fatalf("expected bootstrapTokenPath to be omitted when auth is configured")
+ }
+}
+
+func TestSecurityStatusIncludesBootstrapTokenWhenUnauthenticated(t *testing.T) {
+ cfg := newTestConfigWithTokens(t)
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ ResetRateLimitForIP("203.0.113.50")
+ req := httptest.NewRequest(http.MethodGet, "/api/security/status", nil)
+ req.RemoteAddr = "203.0.113.50:1234"
+ rec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(rec, req)
+ if rec.Code != http.StatusOK {
+ t.Fatalf("expected 200 for security status, got %d", rec.Code)
+ }
+
+ var payload map[string]interface{}
+ if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {
+ t.Fatalf("decode response: %v", err)
+ }
+ path, ok := payload["bootstrapTokenPath"].(string)
+ if !ok || path == "" {
+ t.Fatalf("expected bootstrapTokenPath to be present for unauthenticated setup")
+ }
+}
+
func TestOIDCLoginBypassesAuth(t *testing.T) {
cfg := newTestConfigWithTokens(t)
cfg.AuthUser = "admin"