-
Notifications
You must be signed in to change notification settings - Fork 0
⭐ Controllers
Terrence Daniels edited this page Aug 14, 2026
·
1 revision
6 controllers — articles, comments, favorites, profiles, user, users — the most bug-dense layer in this backend. Real, user-facing bugs, not style nits:
-
articles.js: no null-check on afavorited-username lookup (crashed into a generic 500 instead of a 404),createArticledidn't defaulttagList(crashed on a valid RealWorld payload that omits it), and a missingawaitonarticle.setAuthor(...)— a real race condition. -
comments.js:deleteCommentnever checked that the comment it was deleting actually belonged to the article named in the URL slug, unlike its siblings in the same file — meaning a client could delete a comment by ID through any article's URL. Fixed to match the file's own established pattern. -
user.ts:updateUser's password guard wasif (password !== undefined || password !== "")— a logical tautology, alwaystrueregardless of the value. EveryPUT /userrequest that omitted a password crashed with a 500 (bcrypt.hashthrows onundefined) — not silent corruption, a hard crash on the single most common update. Also found:emailsilently went missing fromPUT /userresponses unless the client happened to update it directly, and a blindObject.entries(user).forEach(...)let a client set any field, includingid/createdAt/updatedAt— narrowed to an explicitusername/bio/image/emailwhitelist. -
users.ts: login-issued JWTs baked inusername: undefined—signInsigned the raw login request body instead of the actual DB record. Verified by decoding a token post-revert and confirmingdecoded.usernamereally wasundefined. Also:signUpchecked email uniqueness but never username, and no DB constraint enforced it either — two accounts could silently share a username, breaking every username-based lookup elsewhere in the app. -
favorites.js: added unchanged — no bugs found.
Every fix above was proven meaningful the same way: deliberately reverted, watched fail against a real test, then restored. See Testing Strategy for the in-memory-SQLite approach that made testing 6 Sequelize-heavy controllers tractable.