Test admin endpoints: can an ordinary user call them?

Object level authorization asks "can user B see user A's order?". Function level authorization asks a different question: "can an ordinary user call DELETE /admin/users/42 at all?". It's number five on the OWASP API Security Top 10, and it usually hides in endpoints nobody thought to protect because "the UI doesn't show that button".

What to look for

Endpoints that only some roles should call:

  • anything under /admin, /internal, /manage, /ops,
  • user management: change role, disable user, reset someone else's password,
  • money and data: refunds, exports, bulk delete,
  • the same resource with a different method: GET /users/42 is fine, PATCH /users/42 {"role":"admin"} isn't.

Also check the routes the UI never calls. Browse the OpenAPI spec, or the server's route list, for endpoints that aren't in your collection yet.

One folder, one token variable

Put each privileged request in an Admin folder, with auth set to bearer {{token}} on the folder. Each request gets a small doc line saying which roles may call it, and a pre-request script stores that list:

JavaScript
// Pre-request script on "Disable user"
pm.variables.set('allowedRoles', 'admin');
JavaScript
// Pre-request script on "Refund order"
pm.variables.set('allowedRoles', 'admin,support');

One check for the whole folder

In the Admin folder's test script:

JavaScript
const allowed = pm.variables.get('allowedRoles').split(',');
const role = pm.iterationData.get('role');

if (allowed.includes(role)) {
  pm.test(`${role} may call ${pm.info.requestName}`, () => {
    pm.expect(pm.response.code).to.be.below(400);
  });
} else {
  pm.test(`${role} is refused ${pm.info.requestName}`, () => {
    pm.expect(pm.response.code).to.be.oneOf([403, 404]);
  });
}

404 is acceptable for "this doesn't exist for you"; some APIs prefer it so they don't reveal admin routes. 401 would mean the token wasn't accepted at all, which hides the real question, so it's not on the list.

One run per role

Keep the tokens in the environment (adminToken, supportToken, memberToken, guestToken, all secret), and give the run a data file with only the role names:

roles.csv
role
admin
support
member
guest

The Admin folder's pre-request script runs before each request in it. It picks the token for this iteration's role, and clears the allowed roles so a request that forgot to set them counts as admin-only:

JavaScript
const role = pm.iterationData.get('role');
pm.variables.set('token', pm.environment.get(role + 'Token'));
pm.variables.set('allowedRoles', 'admin');

The request's own pre-request script runs after the folder's, so its allowedRoles wins. Then:

Terminal
requestarium run-collection "Users API" --folder Admin --env Staging --data roles.csv

The report shows each request once per role, with names like "member is refused Disable user".

Don't forget the method

Function level checks often fail on the second method of a route. If GET /orders/{id} is open to members, add PUT, PATCH and DELETE on the same path to the Admin folder, with only the roles that may change orders.