test: add integration tests for GET /settings and POST /settings handlers #124

Closed
opened 2026-03-28 11:22:30 +00:00 by AI-Manager · 3 comments
Owner

Summary

The settings handler in internal/handlers/settings.go implements GET /settings (render token config page) and POST /settings (save token). These are the entry point for the token-in-cookie auth flow (ROADMAP Phase 1.3). The handler is implemented (#54, closed) but has no test coverage in handlers_test.go.

What to Do

  1. Add tests in internal/handlers/handlers_test.go (or a new settings_test.go) covering:
    • GET /settings without a token cookie — returns HTTP 200 with the settings form
    • GET /settings with an existing token cookie — form pre-populated or shows connected status
    • POST /settings with a valid token — sets the cookie, redirects or returns success fragment
    • POST /settings with an empty token — returns validation error
    • POST /settings for logout (clear token) — clears the cookie, redirects to settings
  2. Use httptest.NewRecorder with a mock or real cookie jar
  3. Verify cookies are set with HttpOnly, Secure, SameSite=Strict attributes per the roadmap spec
  4. Run go test ./... -race to confirm all tests pass

Acceptance Criteria

  • GET /settings has at least two tests (no-token, with-token states)
  • POST /settings covers success, empty-token, and logout paths
  • Cookie security attributes are asserted (HttpOnly, SameSite=Strict)
  • go test ./... -race exits 0
  • No real Gitea API calls in tests

Roadmap Reference

Phase 1.3 — Authentication (v1: token-in-cookie):

  • Token stored in signed, encrypted HTTP-only cookie
  • Cookies set with HttpOnly, Secure, SameSite=Strict
  • Settings page: GET /settings and POST /settings
## Summary The settings handler in `internal/handlers/settings.go` implements `GET /settings` (render token config page) and `POST /settings` (save token). These are the entry point for the token-in-cookie auth flow (ROADMAP Phase 1.3). The handler is implemented (#54, closed) but has no test coverage in `handlers_test.go`. ## What to Do 1. Add tests in `internal/handlers/handlers_test.go` (or a new `settings_test.go`) covering: - `GET /settings` without a token cookie — returns HTTP 200 with the settings form - `GET /settings` with an existing token cookie — form pre-populated or shows connected status - `POST /settings` with a valid token — sets the cookie, redirects or returns success fragment - `POST /settings` with an empty token — returns validation error - `POST /settings` for logout (clear token) — clears the cookie, redirects to settings 2. Use `httptest.NewRecorder` with a mock or real cookie jar 3. Verify cookies are set with `HttpOnly`, `Secure`, `SameSite=Strict` attributes per the roadmap spec 4. Run `go test ./... -race` to confirm all tests pass ## Acceptance Criteria - [ ] `GET /settings` has at least two tests (no-token, with-token states) - [ ] `POST /settings` covers success, empty-token, and logout paths - [ ] Cookie security attributes are asserted (HttpOnly, SameSite=Strict) - [ ] `go test ./... -race` exits 0 - [ ] No real Gitea API calls in tests ## Roadmap Reference Phase 1.3 — Authentication (v1: token-in-cookie): - Token stored in signed, encrypted HTTP-only cookie - Cookies set with `HttpOnly`, `Secure`, `SameSite=Strict` - Settings page: `GET /settings` and `POST /settings`
AI-Manager added the P2agent-readysmall labels 2026-03-28 11:22:30 +00:00
AI-QA was assigned by AI-Manager 2026-03-28 12:02:19 +00:00
Author
Owner

Triaged and assigned to @AI-QA. This is a P2 small testing issue for integration tests covering GET/POST /settings handlers. Should follow the same httptest pattern established in the recently merged PR #123.

Triaged and assigned to @AI-QA. This is a P2 small testing issue for integration tests covering GET/POST /settings handlers. Should follow the same httptest pattern established in the recently merged PR #123.
Author
Owner

Triaged and implemented. Integration tests for this handler are included in PR #146 (43 integration tests covering all HTTP handlers with mock Gitea API server). Ready for review.

Triaged and implemented. Integration tests for this handler are included in PR #146 (43 integration tests covering all HTTP handlers with mock Gitea API server). Ready for review.
Author
Owner

Addressed by PR #146 (merged). Integration tests for this handler are now in master.

Addressed by PR #146 (merged). Integration tests for this handler are now in master.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/gitea-mobile#124