Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 3 min read

Your Green Test Suite Proves Nothing Until You Break It

Open the file where your application limits a query to one customer. Find the line that does it. Delete that line and run your tests. If every test still passes, you have learned something worth more than a month of gre

Open the file where your application limits a query to one customer. Find the line that does it. Delete that line and run your tests.

If every test still passes, you have learned something worth more than a month of green checkmarks. The suite was never checking the boundary you believed it was checking.

I build to a standard that starts from this exact exercise. It came out of the Soulful Ledger backend, where one customer's records could never appear in another customer's results. A passing run was the first claim I had to make. Proof that the tests could fail was the second, and the second is the one that counts.

Why a green suite can mislead

A test suite is a list of claims about behavior. A green mark says the behavior still works. It says nothing about whether the test would have gone red if the behavior broke. A test written with a single customer in the database passes with or without a scoping clause, because only one customer's data is in the room.

Write the tests with two tenants

Create tenant A and tenant B, and give each its own records. Then write the tests aimed at the wrong entity.

As tenant A, request a record owned by tenant B. The correct result is nothing. No record, no partial match, and no error message that confirms the record exists.

This negative test is stronger than the positive one. "It works for the right entity" is a modest claim. "It returns nothing for the wrong entity, even when that entity's data would be the best possible answer" is the claim worth proving. If the feature ranks results, as search does, make tenant B's record the best match for tenant A's query and confirm it still does not appear.

Take scope from the session

The clause itself is short.

SELECT id, total, status
FROM invoices
WHERE tenant_id = $1
AND id = $2;

Two rules sit behind those four lines. The query is parameterized, with $1 and $2 in place of string interpolation, every time and without exceptions. And the value that fills $1 comes from the authenticated session on the server. It never comes from a request body, a URL the client controls, or anything an AI model produced.

Break it on purpose

Now the step most teams skip.

  1. Remove the tenant_id condition from the query.
  2. Run the suite.
  3. Confirm the cross-tenant tests go red.
  4. Restore the condition and confirm they return to green.

This is a mutation test done by hand. If step 3 shows no failures, the suite has a hole exactly where the risk lives, and you found it before a customer did. Repeat it for every query that enforces a boundary. Each one takes minutes.

Guard the chokepoint

Some tables should be touched by exactly one module. An audit log is the clearest example. Write a test that scans the codebase and fails if any other file queries that table, then break it on purpose by adding a stray query in a second file and watching the test catch it. A guard you have never seen fire is a guess.

The audit table deserves a permission as well as a test. Grant INSERT only, and explicitly revoke UPDATE and DELETE, so the log stays append-only even if application code is compromised. The permission holds when the code does not.

What changed in how I build

I no longer accept a security guarantee because a run passed. Every guarantee gets a test that could fail, and I watch it fail once before I trust it. The rest of the standard follows the same habit. Roles are checked on the server for every route. Sessions are revoked when MFA or a password changes. Reports separate what was proven by execution from what was only reasoned from reading the code.

Pick the one query in your project that guards the most sensitive boundary. Delete its scoping clause, run the suite, and see what happens. If you would like a second set of eyes on the result, I review this kind of work through the Security Audit and Hardening Service at merakislove.com.

Originally published on Substack: https://adammcclarin1.substack.com/p/your-green-test-suite-proves-nothing

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.