Commit graph sonda/internal/api/http/middleware_test.go
Author SHA1 Message Date
tgiachi
a880b87a9e chore: move the module path to git.kmalloc.org/squid/sonda
Migrating hosting from Codeberg to git.kmalloc.org. Renames the
module path in go.mod, every internal import, and the OCI image
source label in the Dockerfile. Build and full test suite verified
green after the rename.
2026-11-15 17:30:29 +01:00
tgiachi
96ad8b1f62 feat(auth): accounts are identified by an email address
Registration, login and the admin's create-user call take `email` instead of
`username`, and the user object returns `email`. The address is checked for its
shape (a plain address, no display name, at most 254 bytes), trimmed, lowercased
and unique. Sonda sends no mail and does not verify it.

- Migration 0018 renames the users column (and the PostgreSQL index); values are
  kept, so an account made before keeps its plain name and still logs in with it
  (login does not check the shape).
- Error code username_taken becomes email_taken; the JWT claim is now `email`,
  so access tokens issued before the upgrade are refused once and clients refresh.
- OpenAPI spec, README, the web login form (type email), strings (en, it) and
  the generated API types follow.

Closes #65
2026-11-12 14:40:33 +01:00
tgiachi
cce689b77d fix(auth): reuse the account, quiet aborted requests, more tests
- requireAdmin reuses the account requireAuth already read in the same request
  instead of reading it again.
- A request the client aborted while the account was being read (a player
  seeking) ends with 499 and no error in the log instead of a 500.
- A comment on what a clock stepped back does to the created-after check.
- Tests: the streaming route with the token of a deleted user, the token's
  issue time round trip, the aborted request, the single lookup for admins.
2026-11-11 19:29:39 +01:00
tgiachi
52d1828b46 fix(auth): a token stops working when its account is deleted
SQLite gives the highest user id again after that user is deleted, and an access
token lives for minutes, so the token of a deleted user worked as whoever got the
id next (settings, taste, listens, account).

requireAuth now looks the account up after checking the token and refuses it when
the account is gone, has another name, or was created after the token was signed.
The token carries its issue time for this.

Tests: a unit test of every case, and the real scenario on SQLite (delete the
highest id, create another user, the old token gets 401, the new one works).

Closes #30
2026-11-11 19:25:09 +01:00