diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 49da78a..ce54f8f 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -404,6 +404,25 @@ 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) { diff --git a/templates/dashboard.html b/templates/dashboard.html index bf96b60..ff66e1c 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -69,7 +69,7 @@ View Edit
- {{ .CSRFField }} + {{ $.CSRFField }}