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 test for ErrorHandler empty URL path normalization

rcourtman0e9cd9cce997
diff --git a/internal/api/middleware_test.go b/internal/api/middleware_test.go
index afaa00aca2..410eceeb02 100644
--- a/internal/api/middleware_test.go
+++ b/internal/api/middleware_test.go
@@ -441,3 +441,22 @@ func TestResponseWriter_EdgeCases(t *testing.T) {
}
})
}
+
+func TestErrorHandler_EmptyPath(t *testing.T) {
+ // Test that empty path is normalized to "/" (fix for issue #334)
+ var capturedPath string
+ handler := ErrorHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ capturedPath = r.URL.Path
+ w.WriteHeader(http.StatusOK)
+ }))
+
+ req := httptest.NewRequest(http.MethodGet, "http://example.com", nil)
+ req.URL.Path = "" // explicitly set empty path
+ rec := httptest.NewRecorder()
+
+ handler.ServeHTTP(rec, req)
+
+ if capturedPath != "/" {
+ t.Errorf("expected empty path to be normalized to '/', got %q", capturedPath)
+ }
+}