Make web tests database-free and finish review hardening.

Introduce a Store interface with Postgres and in-memory backends, cover mutations/CSRF/session rotation without Postgres, bound avatar decode dimensions, add truncate/prepareAvatar unit tests, and run go test -race in CI.
This commit is contained in:
2026-08-22 07:36:13 -07:00
parent afd2476f3c
commit f4cec32afb
12 changed files with 945 additions and 223 deletions
+4 -4
View File
@@ -28,7 +28,7 @@ func (s *Server) handleAdminUsers(w http.ResponseWriter, r *http.Request) {
if s.requireAdmin(w, r) == nil {
return
}
users, err := store.ListUsers(r.Context(), s.db)
users, err := s.store.ListUsers(r.Context())
if err != nil {
http.Error(w, "could not load users", http.StatusInternalServerError)
return
@@ -48,14 +48,14 @@ func (s *Server) handleAdminSetRole(w http.ResponseWriter, r *http.Request) {
}
id := chi.URLParam(r, "id")
role := store.Role(r.PostFormValue("role"))
u, err := store.UserByID(r.Context(), s.db, id)
_, err := s.store.UserByID(r.Context(), id)
if err != nil {
http.Error(w, "could not update role", http.StatusBadRequest)
return
}
err = u.SetRole(r.Context(), role)
err = s.store.SetUserRole(r.Context(), id, role)
if errors.Is(err, store.ErrLastAdmin) {
users, listErr := store.ListUsers(r.Context(), s.db)
users, listErr := s.store.ListUsers(r.Context())
if listErr != nil {
http.Error(w, "could not demote last admin", http.StatusBadRequest)
return