Fix critical login/session bug: Store.find() Scan missing Role column
Store.find() (backing FindByIdentifier - used by login - FindByID, and FindSessionUser, used on every authenticated request) selected 7 columns but only Scan()'d 6 destinations, missing &user.Role entirely: find user: find auth user: number of field descriptions must equal number of destinations, got 7 and 6 This broke essentially all login and session validation, in every project vendoring this package, against a real Postgres database. It went undetected because the existing test suite uses a hand-written fake store in each consumer's own httpapi package that never exercises the real query/Scan pair - only a real driver round-trip surfaces a destination-count mismatch like this. Adds backend/auth/store_integration_test.go (skipped unless DATABASE_URL is set, so it never runs in default CI) covering create, find-by-identifier, find-by-id, find-by-session, and list-users against a real database, to catch this class of regression going forward. Verified against a real Postgres container: reproduced the exact reported error before the fix, passes after. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bdcdfc2dbe
commit
db733a6bf4
2 files changed
+105
-1
No files matched your search
@@ -423,7 +423,7 @@ func (s *Store) validate() error {
|
||||
func (s *Store) find(ctx context.Context, query string, arg any) (*User, error) {
|
||||
var user User
|
||||
err := s.pool.QueryRow(ctx, query, arg).Scan(
|
||||
&user.ID, &user.Username, &user.Email, &user.PasswordHash, &user.CreatedAt, &user.UpdatedAt,
|
||||
&user.ID, &user.Username, &user.Email, &user.PasswordHash, &user.Role, &user.CreatedAt, &user.UpdatedAt,
|
||||
)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
|
||||
Reference in new issue
Block a user