DEV Community

Testndo
Testndo

Posted on

Testing API Authorization with Synthetic Users and Test Data

An API can pass every functional test and still leak data. The request is valid, the response is 200, and the payload looks correct. The problem only appears when you ask who sent the request: a user reaching data that belongs to someone else.

Authorization defects are quiet. A broken login page fails loudly, but a missing ownership check returns normal-looking responses and nobody notices until a real account is exposed. Testing them takes a different setup than ordinary functional testing: dedicated test identities and data you fully control.

Build synthetic users for each role

Create a small set of test accounts that exist only in your test environment, one per role or permission level your API knows. A typical set:

  • An owner: a user who owns records and can act on them.
  • A member: a user in the same account or team, with fewer rights.
  • A guest or viewer: read-only access.
  • A suspended or expired account: valid credentials, no active entitlement.
  • An outsider: a valid user who belongs to a different account or tenant entirely.

The outsider is the one teams forget. Most authorization bugs are cross-account: user A reading or changing user B's data by guessing an identifier.

Use clearly fake identities (names like test-owner, domains like example.com) so nobody mistakes them for real people, and never run authorization tests with production user accounts.

Seed isolated test data

Synthetic users need data to act on. Seed a small, known dataset per test run: an account with a few records owned by the owner, a few shared with the member, and none visible to the outsider. Keep it isolated:

  • Each run creates its own records, so tests do not depend on leftovers from earlier runs.
  • Clean up after the run, or use a database that gets reset per run.
  • Avoid shared mutable records, because two tests editing the same row make results flaky and hide real failures.

Predictable identifiers help here. When you know exactly which record belongs to which user, a wrong response is obvious.

What to actually check

With the users and data in place, the checks are simple requests with expected outcomes:

  1. Object level. The outsider requests the owner's record by ID and must get 403 or 404, never 200 with data. Repeat with modified IDs (plus one, minus one, a random one) to catch sequential-ID guessing.
  2. Function level. The member calls an admin-only endpoint, such as deleting the account or inviting users, and must be refused.
  3. Field level. A permitted response should not carry fields the role cannot see, such as internal notes or another user's contact details. Read the whole body, not only the status code.
  4. Token handling. An expired token, a token for a different audience, or a tampered signature must be rejected everywhere, including less-used endpoints.

A useful pattern: send the same request as every synthetic user and compare. The response set tells you whether access rules are applied consistently across endpoints, and a new endpoint that skips the checks stands out immediately.

Put it in the pipeline

Authorization tests earn their keep when they run automatically. A modest suite against a seeded staging environment on every merge catches the common case: a developer adds an endpoint, copies a working one, and forgets the ownership check. The suite fails before the release does.

Start small. Cover the endpoints that touch the most sensitive data first, and grow the suite as the API grows. Ten reliable checks beat a hundred that nobody maintains.


Testndo is a digital transformation company in Egypt offering mobile app and website development, UI/UX design, software testing/QA and security testing.

Website: https://www.testndo.com

Top comments (0)