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.

Prove demo commercial API preview redaction

rcourtman9c498b55c6b2
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 97cad98b34..62ecc21be3 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -2644,7 +2644,7 @@ read-side boundary. `internal/api/demo_mode_commercial.go`,
`internal/api/monitored_system_ledger.go`, and
`internal/api/subscription_state_handlers.go` must fail closed with a generic
`404` for public-demo billing, license-status, and monitored-system-ledger
-reads whenever `DEMO_MODE` is enabled. Demo runtimes may still use real
-server-side entitlement evaluation internally, but the governed browser/API
-contract must not expose commercial identity, usage, or upgrade-state payloads
-back to public viewers through those read surfaces.
+reads or preview probes whenever `DEMO_MODE` is enabled. Demo runtimes may
+still use real server-side entitlement evaluation internally, but the
+governed browser/API contract must not expose commercial identity, usage, or
+upgrade-state payloads back to public viewers through those read surfaces.
diff --git a/internal/api/demo_middleware_test.go b/internal/api/demo_middleware_test.go
index c2f770b678..5a8ab1f692 100644
--- a/internal/api/demo_middleware_test.go
+++ b/internal/api/demo_middleware_test.go
@@ -57,6 +57,13 @@ func TestDemoModeMiddleware(t *testing.T) {
{"demo on hidden license status", true, http.MethodGet, "/api/license/status", "", false, http.StatusNotFound, true},
{"demo on hidden commercial posture", true, http.MethodGet, "/api/license/commercial-posture", "", false, http.StatusNotFound, true},
{"demo on hidden license entitlements", true, http.MethodGet, "/api/license/entitlements", "", false, http.StatusNotFound, true},
+ {"demo on hidden monitored system ledger", true, http.MethodGet, "/api/license/monitored-system-ledger", "", false, http.StatusNotFound, true},
+ {"demo on hidden monitored system explanation", true, http.MethodPost, "/api/license/monitored-system-ledger/explain", "", false, http.StatusNotFound, true},
+ {"demo on hidden monitored system preview", true, http.MethodPost, "/api/license/monitored-system-ledger/preview", "", false, http.StatusNotFound, true},
+ {"demo on hidden truenas draft preview", true, http.MethodPost, "/api/truenas/connections/preview", "", false, http.StatusNotFound, true},
+ {"demo on hidden truenas saved preview", true, http.MethodPost, "/api/truenas/connections/conn-1/preview", "", false, http.StatusNotFound, true},
+ {"demo on hidden vmware draft preview", true, http.MethodPost, "/api/vmware/connections/preview", "", false, http.StatusNotFound, true},
+ {"demo on hidden vmware saved preview", true, http.MethodPost, "/api/vmware/connections/conn-1/preview", "", false, http.StatusNotFound, true},
{"demo on hidden checkout start", true, http.MethodGet, "/auth/license-purchase-start", "", false, http.StatusNotFound, true},
{"demo on hidden license activate", true, http.MethodPost, "/api/license/activate", "", false, http.StatusNotFound, true},
{"demo on hidden purchase start", true, http.MethodGet, licensePurchaseStartPath, "", false, http.StatusNotFound, true},
diff --git a/internal/api/demo_mode_commercial_test.go b/internal/api/demo_mode_commercial_test.go
index ea7bdee4f3..6a0817d17f 100644
--- a/internal/api/demo_mode_commercial_test.go
+++ b/internal/api/demo_mode_commercial_test.go
@@ -1,6 +1,8 @@
package api
import (
+ "net/http"
+ "net/http/httptest"
"strings"
"testing"
)
@@ -65,6 +67,58 @@ func TestSanitizeRuntimeCapabilitiesPayloadForPublicDemo(t *testing.T) {
}
}
+func TestPublicDemoCommercialPolicyForRequestHidesUsagePreviewRoutes(t *testing.T) {
+ hiddenRoutes := []struct {
+ name string
+ method string
+ path string
+ }{
+ {name: "ledger read", method: http.MethodGet, path: "/api/license/monitored-system-ledger"},
+ {name: "ledger explain", method: http.MethodPost, path: "/api/license/monitored-system-ledger/explain"},
+ {name: "ledger preview", method: http.MethodPost, path: "/api/license/monitored-system-ledger/preview"},
+ {name: "truenas draft preview", method: http.MethodPost, path: "/api/truenas/connections/preview"},
+ {name: "truenas saved preview", method: http.MethodPost, path: "/api/truenas/connections/conn-1/preview"},
+ {name: "vmware draft preview", method: http.MethodPost, path: "/api/vmware/connections/preview"},
+ {name: "vmware saved preview", method: http.MethodPost, path: "/api/vmware/connections/conn-1/preview"},
+ }
+
+ for _, tc := range hiddenRoutes {
+ t.Run(tc.name, func(t *testing.T) {
+ req := httptest.NewRequest(tc.method, tc.path, nil)
+ exposure, ok := publicDemoCommercialPolicyForRequest(req)
+ if !ok {
+ t.Fatalf("%s %s did not match public demo commercial policy", tc.method, tc.path)
+ }
+ if exposure != publicDemoCommercialExposureHidden {
+ t.Fatalf("%s %s exposure=%q, want %q", tc.method, tc.path, exposure, publicDemoCommercialExposureHidden)
+ }
+ })
+ }
+
+ allowedRoutes := []struct {
+ name string
+ method string
+ path string
+ }{
+ {name: "truenas list", method: http.MethodGet, path: "/api/truenas/connections"},
+ {name: "truenas add", method: http.MethodPost, path: "/api/truenas/connections"},
+ {name: "truenas saved test", method: http.MethodPost, path: "/api/truenas/connections/conn-1/test"},
+ {name: "vmware list", method: http.MethodGet, path: "/api/vmware/connections"},
+ {name: "vmware add", method: http.MethodPost, path: "/api/vmware/connections"},
+ {name: "vmware saved test", method: http.MethodPost, path: "/api/vmware/connections/conn-1/test"},
+ {name: "runtime capabilities", method: http.MethodGet, path: "/api/license/runtime-capabilities"},
+ }
+
+ for _, tc := range allowedRoutes {
+ t.Run(tc.name, func(t *testing.T) {
+ req := httptest.NewRequest(tc.method, tc.path, nil)
+ if exposure, ok := publicDemoCommercialPolicyForRequest(req); ok {
+ t.Fatalf("%s %s unexpectedly matched public demo commercial policy with exposure=%q", tc.method, tc.path, exposure)
+ }
+ })
+ }
+}
+
func routeBelongsToPublicDemoCommercialBoundary(route string) bool {
switch {
case route == "/auth/trial-activate":