From 43cde0eefd8ecc7fd95478971c184d2851b77df1 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 26 Feb 2026 02:56:00 -0800 Subject: [PATCH] test: add failing test for dashboard CSRFField (refs #146) --- internal/handlers/handlers_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 49da78a..5cb6b9c 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -404,6 +404,24 @@ func TestHandleDashboard(t *testing.T) { assert.Equal(t, http.StatusOK, recorder.Code) assert.Contains(t, recorder.Body.String(), "Applications") }) + + t.Run("renders dashboard with apps without crashing on CSRFField", func(t *testing.T) { + t.Parallel() + + testCtx := setupTestHandlers(t) + + // Create an app so the template iterates over AppStats and hits .CSRFField + createTestApp(t, testCtx, "csrf-test-app") + + request := httptest.NewRequest(http.MethodGet, "/", nil) + recorder := httptest.NewRecorder() + + handler := testCtx.handlers.HandleDashboard() + handler.ServeHTTP(recorder, request) + + assert.Equal(t, http.StatusOK, recorder.Code, "dashboard should not 500 when apps exist (CSRFField must be accessible)") + assert.Contains(t, recorder.Body.String(), "csrf-test-app") + }) } func TestHandleAppNew(t *testing.T) {