Docs
How to test your app's business logic for holes
Business logic is the set of rules your app runs on: a customer sees only their own orders, only a manager approves a refund, a discount works once. Automated scanners look for known kinds of bugs; they usually do not know your rules, so they usually cannot tell you when one is broken. You test a rule by having a regular user try to break it.
1. Write the rules down
Ask your coding agent, in your repository:
List every rule this app enforces about who can see, change, approve, pay for or delete what, and every number that must add up. One line each, in plain words, with the file and line that enforces it, or “nothing enforces this”. Do not change any code.
Correct the list yourself. A rule you expected that is missing from it is your first finding.
2. Try to break each rule as a regular user
Do this on a copy of the app with its own test database, never the live app: several of these attempts create orders, change stock or send emails. On the live app, only try the first row (reading A's records as B), with test accounts you made for this. Never use real customers' accounts.
| Rule | How a test user tries to break it |
|---|---|
| Users see only their own records | As user B, open, list, export and search for user A's records. |
| Users change only their own records | As B, edit or delete A's record by putting its id in the address or the request. |
| Only an admin is an admin | As a regular user, add role or isAdmin to a profile update, or open admin pages by address. |
| Steps happen in order | Approve your own request, skip the payment step, or reuse a one-time discount or invite link. |
| Numbers stay true | Send a negative quantity, a changed price or a total the app should compute itself. |
| Limits hold | Go past a plan's limit, or act on a record after your access was removed. |
Many of these need the request, not the screen: the screen hides a button, the server still accepts the call. In the browser's developer tools, the Network tab shows each request; your coding agent can replay one with a changed id or field on the copy.
3. Write down what broke, with proof
- For each rule: held, or broke, with the exact request and response that broke it.
- A rule that held once can still break after the next change. Say which rules held, never that the app is safe.
4. Fix, then break it again
- Hand each broken rule to your coding agent with the proof, and have it fix the check on the server.
- Repeat the same attempt. Then keep it as an automated test that runs on every push.
Related: can one user see another user's data? and checking after every deploy.
What Pariter does
Pariter checks every change to your code against your app's business rules and tells you and your coding agent when one breaks. The rulebook and the self-check are free now, with no account: pariter.ai/docs/rulebook.md. The independent check on every push runs through Pariter's connector (add it): one proof alert is free, and the check on every push is not on sale yet. Leave your email and your app's address to hear when it is.