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: Add CheckAuth tests for API package

rcourtman9a40157aead2
diff --git a/internal/api/auth_helpers_test.go b/internal/api/auth_helpers_test.go
index f8a2b95b21..ecdca4f06c 100644
--- a/internal/api/auth_helpers_test.go
+++ b/internal/api/auth_helpers_test.go
@@ -810,3 +810,41 @@ func TestCheckAuth_NoSessionCookie(t *testing.T) {
t.Error("CheckAuth should return false without session or valid auth")
}
}
+
+func TestCheckAuth_ValidSessionWithSlidingExpiration(t *testing.T) {
+ dir := t.TempDir()
+ InitSessionStore(dir)
+
+ store := GetSessionStore()
+ sessionToken := generateSessionToken()
+ store.CreateSession(sessionToken, 24*time.Hour, "test-agent", "127.0.0.1")
+
+ cfg := &config.Config{
+ // No auth configured, so session alone should work
+ }
+ req := httptest.NewRequest("GET", "/api/test", nil)
+ req.AddCookie(&http.Cookie{
+ Name: "pulse_session",
+ Value: sessionToken,
+ })
+ w := httptest.NewRecorder()
+
+ result := CheckAuth(cfg, w, req)
+ if !result {
+ t.Error("CheckAuth should return true for valid session with sliding expiration")
+ }
+}
+
+func TestCheckAuth_NoAuthConfigured(t *testing.T) {
+ cfg := &config.Config{
+ // No auth configured at all
+ }
+ req := httptest.NewRequest("GET", "/api/test", nil)
+ w := httptest.NewRecorder()
+
+ result := CheckAuth(cfg, w, req)
+ // Should return true when no auth is configured
+ if !result {
+ t.Error("CheckAuth should return true when no auth is configured")
+ }
+}