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.

Test multi-tenant persistence guardrails

rcourtman17ebc203ff42
diff --git a/internal/config/multi_tenant_test.go b/internal/config/multi_tenant_test.go
new file mode 100644
index 0000000000..d6d8cecfba
--- /dev/null
+++ b/internal/config/multi_tenant_test.go
@@ -0,0 +1,52 @@
+package config
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+func TestMultiTenantPersistence_InvalidOrgIDsRejected(t *testing.T) {
+ baseDir := t.TempDir()
+ mtp := NewMultiTenantPersistence(baseDir)
+
+ invalidIDs := []string{
+ "",
+ ".",
+ "..",
+ "../bad",
+ "bad/..",
+ "bad/../evil",
+ }
+
+ for _, orgID := range invalidIDs {
+ if _, err := mtp.GetPersistence(orgID); err == nil {
+ t.Fatalf("expected error for orgID %q", orgID)
+ }
+ if mtp.OrgExists(orgID) {
+ t.Fatalf("OrgExists should be false for orgID %q", orgID)
+ }
+ }
+
+ if _, err := os.Stat(filepath.Join(baseDir, "orgs")); err == nil {
+ t.Fatalf("unexpected orgs directory created for invalid org IDs")
+ }
+}
+
+func TestMultiTenantPersistence_GetPersistence_CreatesOrgDir(t *testing.T) {
+ baseDir := t.TempDir()
+ mtp := NewMultiTenantPersistence(baseDir)
+
+ if _, err := mtp.GetPersistence("acme"); err != nil {
+ t.Fatalf("GetPersistence(acme) failed: %v", err)
+ }
+
+ orgDir := filepath.Join(baseDir, "orgs", "acme")
+ info, err := os.Stat(orgDir)
+ if err != nil {
+ t.Fatalf("expected org dir to exist: %v", err)
+ }
+ if !info.IsDir() {
+ t.Fatalf("expected org dir to be a directory")
+ }
+}