O que negative-test faz?
Goal: prove the system rejects bad input and bad states safely. Test the failure path, not only the happy path.
Follow references/core-rules.md, references/automation-workflow.md, references/severity-model.md. Write the report in the format of references/testcase-template.md. Prefix IDs with NEG-. For every detected language, also apply references/languages/<language>.md (index: references/languages/README.md).
Rules
- Validation must happen on the server. Client-side validation is UX, not security. A field validated only on the client is a
VALIDATIONfinding, at least High for sensitive fields. - For every input, check: type, presence, length/size, format, range, allowed values, ownership, uniqueness.
- Every negative case must check four things: (a) no crash, (b) the correct status or error message, (c) no sensitive data in the error, (d) state is unchanged or rolled back, and the user can recover.
Input matrix (apply it to every field and parameter)
| Class | Values to try |
|---|---|
| Missing | field absent, null, undefined, "", " " (whitespace), [], {} |
| Type | string↔number, "123" vs 123, boolean as "true", array where object expected, nested object where scalar expected |
| Size | 0, 1, max-1, max, max+1, 10× max, 1 MB string, 10k-item array, deeply nested JSON (1000 levels) |
| Numeric | 0, -1, -0, 0.1+0.2, 1e308, NaN, Infinity, 2^31, 2^53+1, too many decimal places for currency |
| Format | bad email/phone/URL/UUID/date, 2026-02-30, timezone-less timestamp, leap day, DST change, far past/future dates |
| Characters | Unicode, emoji 👍🏽, RTL text, zero-width chars, homoglyphs, \0 null byte, CRLF \r\n, very long single word |
| Injection-ish | ' OR 1=1--, <script>, {{7*7}}, ../../etc/passwd, ; ls, ${jndi:...}. Detail lives in security-test; here just confirm it's rejected or escaped |
| Enum | unknown value, wrong case, old or deprecated value |
| Identity | ID of a resource that doesn't exist, was deleted, or belongs to another user |
| Duplicates | same request twice, double-click submit, same unique value (email, SKU), replayed webhook |
| Files | 0-byte file, huge file, wrong extension, spoofed MIME, corrupted image, zip bomb, filename with ../ or unicode |
Checklist by layer
Backend / API (BE)
- Schema validation (Zod, Joi, class-validator, Pydantic, Bean Validation) on every body, query, param, and header.
- Unknown fields are rejected or stripped. No mass assignment of
role,isAdmin,price,userId,status. - Invalid JSON returns 400, not 500.
- Wrong
Content-Typereturns 415 or 400. - Pagination:
page=-1,limit=0,limit=100000, cursors that don't exist. - Sort/filter params checked against an allowlist of columns.
- Missing, expired, or malformed auth token gives 401. Valid token but wrong role gives 403. Other user's resource gives 404 or 403 consistently.
- Rate limit returns 429 with a
Retry-Afterheader. - Error messages don't reveal stack traces, SQL, internal paths, or whether an account exists (on login or reset).
Frontend web (FE)
- Each form field shows an inline error and the submit button is disabled or guarded while submitting (stops double submit).
- Server-side validation errors are mapped back to the right fields.
- Empty states for lists and search with no results.
- Error boundary catches render errors, so one widget failing doesn't white-screen the page.
- Back, forward, refresh mid-flow, a session expiring mid-form, and multiple tabs.
- Untrusted strings render as text, not via
dangerouslySetInnerHTMLorv-html.
Mobile (MOB)
- Keyboard types and input masks don't stop the user from pasting valid values.
- Rotation, split screen, and font scaling at 200% with long text.
- Rapid double taps on buttons that trigger navigation or a submit.
- Component unmounts mid-request: no setState-on-unmounted warning or crash. Requests use AbortController.
- Low storage, low memory, and the app killed in the background during an upload.
- Permission denied, and permission revoked while the app is in use.
- Out-of-order responses: an older search response must not overwrite a newer one.
Admin panel (ADM)
- Admin forms get the same server validation as user forms. Admin is not a trusted input source.
- Bulk operations with mixed valid and invalid rows report row-level errors and don't silently skip rows.
- CSV import: wrong delimiter, BOM, formula injection (
=HYPERLINK(...),+cmd,@SUM), missing headers, a 100k-row file. - Destructive actions need confirmation and can't be triggered by a GET.
- Editing a record someone else edited at the same time is handled (optimistic locking or a last-write warning).
Database (DB)
- NOT NULL, CHECK, UNIQUE, and FK constraints exist so the DB catches what the app misses (defence in depth).
- Column lengths match API max lengths, so a valid API input can't fail with a DB truncation error.
- Decimal or integer-cents for money, never float.
- Timestamps stored in UTC with timezone (
timestamptz). - A unique-violation or FK error is translated to 409 or 422, not 500.
- Soft-deleted rows are excluded from uniqueness and lookups where they should be.
Concurrency and race cases
- Two requests at once on the same resource: double spend, oversell inventory, duplicate coupon use.
- Request cancellation and retry after timeout.
- Rapid toggle (like/unlike, follow/unfollow) ends in a consistent final state.
Automation hint
Generate table-driven tests from the input matrix in the project's framework, e.g. it.each(cases), @pytest.mark.parametrize, or property-based tests (vendor property-based-testing) for fuzz-style coverage.
Output per test
ID | Scenario | Input | Expected | Actual | Pass/Fail | Follow-up. Add it to testcase.md.
Scope, prerequisites, and missing tools
Don't use it for dependency or network failure handling (fallback-test), business-rule correctness (logical-test), or a full security review (security-test). Injection strings here only confirm input is rejected or escaped.
Prerequisites: read access to the repository. Optional: the project's own test runner and the scanners listed in the language guides. Nothing extra needs to be installed; every check also works by reading the code.
If something is missing: if a tool, the test runner, or a running app isn't available, or a step is blocked, record it as NOT RUN: <reason> and continue statically. Always finish by writing the report.
Example finding row
| ID | Layer | Type | Finding | Location / Evidence | Failure scenario | Fix | Status |
|---|---|---|---|---|---|---|---|
| NEG-BE-004 | BE | VALIDATION | quantity accepts negatives | api/orders.py:41 no bounds check | quantity=-5 → total −49.95, order accepted | conint(ge=1, le=10) in the Pydantic model | Open |