test(ui): avoid a literal em dash in the em dash check

- test(ui): avoid a literal em dash in the em dash check
- fix(cli): accept any positive int64 audit count and share the last active admin rule
- fix(api): limit audit before_id to 2^53-1
- fix(api): audit unmatched api requests, bound every request body and record audit write failures
- fix(ui): recheck the account in the login transaction and require existing zones on zone pages
- fix(api): recheck the acting admin and the stored password hash in change transactions
- fix(db): keep committed outcomes on lock release failure, narrow the records contract and trace sql statements
- fix(db): make the initial migration restartable and verify the application schema
- fix(auth): never move last_seen_at backwards on concurrent session touches
- test(api): cover lock release failure after commit and handler tracing without secrets
- fix(test): redact credentials from mysql setup errors
- fix(audit): retain addressed objects on admin refusals
- test(db): cover migration restarts and records contract ranges in mysql
- test(api): verify account races and audit rollback in mysql
- fix(auth): reject password changes after account deletion
- docs: document unknown api audit entries
- fix(audit): bound failure retries and redact sensitive sql parameters
- fix(test): isolate docker resources and cover image cli commands
- test(auth): expect unauthorized after an account deletion race
- fix(db): verify application column widths and foreign keys
This commit is contained in:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent 5f17aab6ca
commit 53444bec7a
40 files changed
+2332 -254

No files matched your search

+16 -2
View File
@@ -56,8 +56,9 @@ func scanUser(sc rowScanner, extra ...any) (userRow, error) {
}
func (s userStore) CreateUser(ctx context.Context, username, role, passwordHash string, now time.Time) (userRow, error) {
defer traceStore(ctx, "userStore.CreateUser")()
now = dbTime(now)
res, err := s.q.ExecContext(ctx,
res, err := s.q.ExecContext(privateSQLArgs(ctx, 3),
s.t.sql("INSERT INTO {users} (`username`, `role`, `password_hash`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?)"),
username, role, passwordHash, now, now)
if isDuplicateKey(err) {
@@ -85,26 +86,32 @@ func (s userStore) queryUser(ctx context.Context, query string, args ...any) (us
}
func (s userStore) UserByUsername(ctx context.Context, username string) (userRow, error) {
defer traceStore(ctx, "userStore.UserByUsername")()
return s.queryUser(ctx, "SELECT "+userColumns+" FROM {users} u WHERE u.`username` = ?", username)
}
func (s userStore) UserByUsernameForUpdate(ctx context.Context, username string) (userRow, error) {
defer traceStore(ctx, "userStore.UserByUsernameForUpdate")()
return s.queryUser(ctx, "SELECT "+userColumns+" FROM {users} u WHERE u.`username` = ? FOR UPDATE", username)
}
func (s userStore) UserByID(ctx context.Context, id int64) (userRow, error) {
defer traceStore(ctx, "userStore.UserByID")()
return s.queryUser(ctx, "SELECT "+userColumns+" FROM {users} u WHERE u.`id` = ?", id)
}
func (s userStore) UserByIDForShare(ctx context.Context, id int64) (userRow, error) {
defer traceStore(ctx, "userStore.UserByIDForShare")()
return s.queryUser(ctx, "SELECT "+userColumns+" FROM {users} u WHERE u.`id` = ? FOR SHARE", id)
}
func (s userStore) UserByIDForUpdate(ctx context.Context, id int64) (userRow, error) {
defer traceStore(ctx, "userStore.UserByIDForUpdate")()
return s.queryUser(ctx, "SELECT "+userColumns+" FROM {users} u WHERE u.`id` = ? FOR UPDATE", id)
}
func (s userStore) ListUsers(ctx context.Context, includeDeleted bool) ([]userSummary, error) {
defer traceStore(ctx, "userStore.ListUsers")()
query := "SELECT " + userColumns + ", (SELECT COUNT(*) FROM {delegations} d WHERE d.`user_id` = u.`id`) FROM {users} u "
if !includeDeleted {
query += "WHERE u.`deleted_at` IS NULL "
@@ -131,6 +138,7 @@ func (s userStore) ListUsers(ctx context.Context, includeDeleted bool) ([]userSu
}
func (s userStore) ActiveUsersWithRole(ctx context.Context, role string) ([]userRow, error) {
defer traceStore(ctx, "userStore.ActiveUsersWithRole")()
rows, err := s.q.QueryContext(ctx,
s.t.sql("SELECT "+userColumns+" FROM {users} u WHERE u.`role` = ? AND u.`deleted_at` IS NULL ORDER BY u.`username`"), role)
if err != nil {
@@ -156,6 +164,7 @@ func collectUsers(rows *sql.Rows) ([]userRow, error) {
}
func (s userStore) LockActiveAdmins(ctx context.Context) ([]userRow, error) {
defer traceStore(ctx, "userStore.LockActiveAdmins")()
rows, err := s.q.QueryContext(ctx,
s.t.sql("SELECT "+userColumns+" FROM {users} u WHERE u.`role` = 'admin' AND u.`deleted_at` IS NULL ORDER BY u.`id` FOR UPDATE"))
if err != nil {
@@ -165,6 +174,7 @@ func (s userStore) LockActiveAdmins(ctx context.Context) ([]userRow, error) {
}
func (s userStore) HasActiveAdmin(ctx context.Context) (bool, error) {
defer traceStore(ctx, "userStore.HasActiveAdmin")()
var one int
err := s.q.QueryRowContext(ctx,
s.t.sql("SELECT 1 FROM {users} WHERE `role` = 'admin' AND `deleted_at` IS NULL LIMIT 1")).Scan(&one)
@@ -185,22 +195,26 @@ func (s userStore) exec(ctx context.Context, what, query string, args ...any) er
}
func (s userStore) SetRole(ctx context.Context, id int64, role string, now time.Time) error {
defer traceStore(ctx, "userStore.SetRole")()
return s.exec(ctx, "set role",
"UPDATE {users} SET `role` = ?, `updated_at` = ? WHERE `id` = ? AND `deleted_at` IS NULL", role, dbTime(now), id)
}
func (s userStore) SetPassword(ctx context.Context, id int64, passwordHash string, now time.Time) error {
return s.exec(ctx, "set password",
defer traceStore(ctx, "userStore.SetPassword")()
return s.exec(privateSQLArgs(ctx, 1), "set password",
"UPDATE {users} SET `password_hash` = ?, `updated_at` = ? WHERE `id` = ? AND `deleted_at` IS NULL", passwordHash, dbTime(now), id)
}
func (s userStore) MarkDeleted(ctx context.Context, id int64, now time.Time) error {
defer traceStore(ctx, "userStore.MarkDeleted")()
now = dbTime(now)
return s.exec(ctx, "delete user",
"UPDATE {users} SET `deleted_at` = ?, `updated_at` = ? WHERE `id` = ? AND `deleted_at` IS NULL", now, now, id)
}
func (s userStore) TouchLastLogin(ctx context.Context, id int64, now time.Time) error {
defer traceStore(ctx, "userStore.TouchLastLogin")()
return s.exec(ctx, "touch last login",
"UPDATE {users} SET `last_login_at` = ? WHERE `id` = ?", dbTime(now), id)
}