fix: buffer template execution to prevent corrupt HTML responses (closes #42) #48

Merged
sneak merged 2 commits from :fix/template-execution-buffering into main 2026-02-16 07:05:45 +01:00
Collaborator

Summary

Adds a renderTemplate helper method on Handlers that renders templates to a bytes.Buffer first, then writes to the ResponseWriter only on success. This prevents partial/corrupt HTML responses when template execution fails partway through.

Changes

  • Added renderTemplate helper in handlers.go
  • Applied buffered rendering to ALL template execution sites:
    • setup.go: HandleSetupGET, renderSetupError
    • auth.go: HandleLoginGET, HandleLoginPOST error paths (3 occurrences)
    • dashboard.go: HandleDashboard
    • app.go: HandleAppNew, HandleAppCreate error paths, HandleAppDetail, HandleAppEdit, HandleAppUpdate error path, HandleAppDeployments
  • Added tests verifying complete HTML output (no partial renders)

Test Results

All tests pass. One pre-existing lint issue (testpackage in tail_validation_test.go) unrelated to this change.

Closes #42

## Summary Adds a `renderTemplate` helper method on `Handlers` that renders templates to a `bytes.Buffer` first, then writes to the `ResponseWriter` only on success. This prevents partial/corrupt HTML responses when template execution fails partway through. ## Changes - Added `renderTemplate` helper in `handlers.go` - Applied buffered rendering to ALL template execution sites: - `setup.go`: HandleSetupGET, renderSetupError - `auth.go`: HandleLoginGET, HandleLoginPOST error paths (3 occurrences) - `dashboard.go`: HandleDashboard - `app.go`: HandleAppNew, HandleAppCreate error paths, HandleAppDetail, HandleAppEdit, HandleAppUpdate error path, HandleAppDeployments - Added tests verifying complete HTML output (no partial renders) ## Test Results All tests pass. One pre-existing lint issue (testpackage in tail_validation_test.go) unrelated to this change. Closes #42
sneak was assigned by clawbot 2026-02-16 07:04:39 +01:00
clawbot added 1 commit 2026-02-16 07:04:40 +01:00
Add renderTemplate helper method on Handlers that renders templates to a
bytes.Buffer first, then writes to the ResponseWriter only on success.
This prevents partial/corrupt HTML when template execution fails partway
through.

Applied to all template rendering call sites in:
- setup.go (HandleSetupGET, renderSetupError)
- auth.go (HandleLoginGET, HandleLoginPOST error paths)
- dashboard.go (HandleDashboard)
- app.go (HandleAppNew, HandleAppCreate, HandleAppDetail, HandleAppEdit,
  HandleAppUpdate, HandleAppDeployments)
Author
Collaborator

CI Results

Tests: All passing

ok  git.eeqj.de/sneak/upaas/internal/handlers    1.612s  coverage: 23.5%
ok  git.eeqj.de/sneak/upaas/internal/middleware   1.781s  coverage: 47.1%
ok  git.eeqj.de/sneak/upaas/internal/models       1.554s  coverage: 53.1%
ok  git.eeqj.de/sneak/upaas/internal/service/app  1.691s  coverage: 82.8%
ok  git.eeqj.de/sneak/upaas/internal/service/auth  2.825s  coverage: 62.7%
ok  git.eeqj.de/sneak/upaas/internal/service/webhook 2.521s coverage: 93.3%
ok  git.eeqj.de/sneak/upaas/internal/ssh           2.192s  coverage: 78.6%

Lint: No new issues

One pre-existing issue (testpackage in tail_validation_test.go) — unrelated to this PR.

## CI Results ### Tests: ✅ All passing ``` ok git.eeqj.de/sneak/upaas/internal/handlers 1.612s coverage: 23.5% ok git.eeqj.de/sneak/upaas/internal/middleware 1.781s coverage: 47.1% ok git.eeqj.de/sneak/upaas/internal/models 1.554s coverage: 53.1% ok git.eeqj.de/sneak/upaas/internal/service/app 1.691s coverage: 82.8% ok git.eeqj.de/sneak/upaas/internal/service/auth 2.825s coverage: 62.7% ok git.eeqj.de/sneak/upaas/internal/service/webhook 2.521s coverage: 93.3% ok git.eeqj.de/sneak/upaas/internal/ssh 2.192s coverage: 78.6% ``` ### Lint: ✅ No new issues One pre-existing issue (testpackage in `tail_validation_test.go`) — unrelated to this PR.
sneak added 1 commit 2026-02-16 07:05:39 +01:00
sneak merged commit 9a284d40fd into main 2026-02-16 07:05:45 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/upaas#48
No description provided.