Before launching a car rental platform (one API and three web apps for customers, fleet partners and admins), I audited it from the outside. The test suite never imports the apps' code. It starts the real stack against a fresh database and attacks it the way users and attackers would: over HTTP, and in a real browser.
The audit produced 40 findings. The everyday bugs were expected. The interesting ones were the bugs that every unit test would have passed. Here are the ones worth sharing.
Money: the same refund, twice
Refunds could be sent from two places: the API, when a customer cancels, and the background worker that reconciles payments. Both read "refund pending", both called the payment gateway, and both could succeed.
Fix: a refund is claimed in the database before it's sent, with one conditional update: UPDATE refunds SET status = 'PROCESSING' WHERE id = $1 AND status = 'PENDING'. PostgreSQL applies that atomically, so exactly one process gets "1 row updated" and sends the refund. The other gets "0" and stops. A booking change also calculates its refund from the booking row read with SELECT … FOR UPDATE, so the same change sent twice waits its turn and refunds once.
Coupons: a limit that wasn't one
A coupon's usage limit was checked when the price was quoted and counted when the booking was confirmed. Two customers quoting at the same moment both saw "1 use left", and both got it.
Fix: at confirmation, lock the coupon row (SELECT … FOR UPDATE) and count the bookings that hold or have paid with it, then decide. The check and the act happen under the same lock.
Concurrency: twelve bookings stalled the API
Twelve simultaneous bookings exhausted the database connection pool and stalled every database-backed request for 30 seconds. That one got its own post: Twelve Bookings at Once Stalled the API.
Auth: trusting the first person to arrive
Registration accepted a phone number without proving ownership, which let someone register your number and keep a working password into your account after you signed in. Also its own post: Two Ways Strangers Could Own an Account.
Access: 403 says too much
Asking for another customer's booking returned 403 Forbidden, while a missing one returned 404 Not Found. That difference tells an attacker which booking ids exist. Fix: both are 404. It's a privacy trade-off: support can't tell "not yours" from "doesn't exist" from the status code alone, so the server log keeps the real reason.
Staleness: admins changed things nobody saw
The customer site cached the catalogue on a timer. When an admin disabled a car, it kept appearing for customers until the cache expired, and some data was cached for hours. Fix: cached reads are tagged, and the backend calls a secured revalidation route whenever the catalogue changes, so edits show up straight away.
Slugs that broke links
Renaming a car model regenerated its URL slug, and the old URL started returning 404: bad for customers' bookmarks and for search rankings. Fix: old slugs are stored and keep answering.
Smaller ones that add up
- Unknown fields were silently dropped from request bodies. Now they're rejected, so a typo in a client is an error, not a mystery. That's safe here because the API's only clients are our own apps, released alongside it. A public API would need versioning before going this strict.
- A malformed partner header crashed into a database error and a
500. Now it's a400. - The telematics webhook token had a fallback in the source code. It was a development placeholder, not a leaked production secret, but production config didn't require a real token, so a missing variable would have silently fallen back to a value anyone reading the code could see. That would have let anyone who knew a device id post fake positions and alerts. Production config now requires a real token, so the placeholder can only take effect in development.
Why outside-in
Unit tests check that each piece does what its author intended. These bugs lived between the pieces: two processes racing for one refund, a cache and an admin screen disagreeing, a sign-up flow and a sign-in flow that were each correct alone. You only see them when you drive the whole system the way the world will.
The suite stays. Each finding has a test named after it that states the correct behaviour, so a regression shows up as a failing test with an explanation attached.
- #Testing
- #Architecture