An authorization test should state who is acting, which resource they are targeting, what action they request and why the result should be allowed or denied. “An administrator can open the dashboard” is only one case. It does not establish whether an ordinary user can read another account’s document, whether a former member retains access or whether an export endpoint applies the same rules as the screen.
The OWASP Authorization Cheat Sheet distinguishes authorization from authentication and recommends least privilege, denial by default and permission validation on every request. The test design below applies those principles to a fictional document workspace. Its matrix and examples are original editorial guidance, not a complete security assessment or a guarantee that all access-control faults will be found.
Describe the policy before the test code
Start with a short statement of intended behavior. In the example workspace, a member can read documents belonging to a project they currently belong to. A project editor can change those documents. A separate administrator can manage project membership. These statements may still contain ambiguity, but they are easier to challenge than a set of role names without resource context.
Ask who has authority to resolve the ambiguity. Does a project administrator automatically read every document? Can a document owner retain access after leaving the project? Can a suspended account download an export created earlier? A test should encode an agreed decision, not silently turn a developer’s guess into product policy.
Keep the decision record near the tests. When a policy changes, reviewers should be able to identify the expected changes in behavior and the corresponding cases. A failing test is useful only when people can explain why its expected result is still correct.
Create fixtures with meaningful relationships
Use at least two independent project contexts in the test environment. Give each its own documents and members. The point is not the number of fixtures but the difference between them: a member of Project A should not accidentally satisfy a permission check for a document in Project B.
Create identifiers through normal fixture setup where possible. Do not make all resources belong to one global administrator, because that can hide the relationships the policy is supposed to enforce. Include a member with read access, an editor, an unrelated authenticated account and an unauthenticated request where the application supports it.
Use synthetic document content. A distinctive marker in each protected resource lets a test detect accidental disclosure without depending only on a status code. If a denied response includes the document title or a body excerpt, a test that checks only for a nominal error may miss the information exposure.
Build the matrix from actions, not screens
List the operations that touch the resource. Reading a document, editing its title, downloading an attachment, generating an export and changing a sharing relationship are separate actions. A single screen can invoke several endpoints with different behavior.
For each action, identify the policy inputs. These might include project membership, a resource state or an approved role. Avoid expanding the matrix with irrelevant combinations simply to make it look thorough. Choose cases that change an input the policy actually uses, plus cases that should remain denied when information is absent or invalid.
| Actor and relationship | Read document | Edit document | Change membership |
|---|---|---|---|
| Current reader in the document’s project | Expected allow | Expected deny | Expected deny |
| Current editor in the document’s project | Expected allow | Expected allow | Depends on explicit administration policy |
| Member of a different project | Expected deny | Expected deny | Expected deny |
| Former project member | Expected deny unless an explicit exception exists | Expected deny | Expected deny |
These are example decisions for the fictional application. Replace them with the real policy before using the matrix. An application’s legitimate sharing model may differ, and the test suite should make that model visible.
Verify the resource as well as the response
For an allowed read, assert that the returned object is the intended resource and contains the fields the actor is permitted to see. For a denied read, check that protected content is absent. Do not assume that an error-shaped response cannot contain a useful piece of the forbidden record.
For a denied write, inspect the resulting state. The response may report a failure even though an earlier stage changed the database. A meaningful test verifies that the protected field did not change and that no unauthorized follow-up action was queued. This matters for operations that combine an update with a notification or export.
For an allowed write, confirm the permitted change without treating it as permission for every other field. If the operation allows editing a title, test what happens when the request also includes a membership or ownership field. The expected behavior should come from the request contract and authorization policy, not from the client interface hiding that field.
Exercise the server boundary directly
A user interface can hide controls to make a workflow understandable. The authorization decision still needs to hold when a request reaches the server without following that interface. In an authorized test environment, exercise the actual endpoint or application service boundary used to perform the operation.
Use the same authentication mechanism as the application expects, with disposable test accounts. Avoid a test helper that bypasses the very middleware or policy layer under review. If unit tests isolate the policy function, complement them with integration tests that show the function is actually called at the relevant boundary.
Document any paths not covered by the exercise. A batch import, background worker or legacy API may have its own access context. Finding that gap is useful; pretending the main web endpoint proves every other path is not. Assign the missing path a separate review task and an owner.
Test changes in access over time
Access is not always a static property. A member can leave a project, a share can expire or an account can be suspended. Create tests that establish access, change the relevant relationship and then attempt the operation again under the conditions the system promises to enforce.
Be precise about what happens to existing sessions and cached decisions. If the application documents a propagation interval, test against that behavior rather than assuming immediate enforcement everywhere. If no interval or behavior is defined, treat that as a design question. A test should not normalize an indefinite delay simply because it currently occurs.
Long-running operations deserve their own scenario. Suppose an export starts while a user has access and completes after the user is removed. Who can retrieve the result? Is access checked again at download time? The correct policy depends on the application, but the test suite should capture the chosen rule instead of inheriting it accidentally from storage behavior.
Include the missing-policy case
A newly added endpoint or action may not appear in the existing permission table. A useful test asks what happens when the system has no explicit matching grant. That is different from testing a known forbidden role against an established action.
Inspect the actual framework configuration and the way routes are registered. A policy function with sound defaults does not help if a new route never invokes it. Consider a review check that inventories protected routes or verifies a common enforcement boundary, then test an example route through that boundary.
Keep these checks maintainable. A large list of endpoint strings can become stale unless it is connected to the application’s route definitions or release review. The objective is to make an unreviewed exposure visible, not to create a second undocumented routing system inside the tests.
Make failures explain the broken relationship
A useful failure message identifies the actor class, action, resource context and expected decision. It should not print session tokens, passwords or full protected documents. The developer needs enough context to reproduce the case with the disposable fixtures, not a dump of sensitive state.
When a test reveals a defect, add the smallest regression case that captures the failure mode. Then examine whether the same enforcement pattern appears elsewhere. One missing resource relationship may indicate a shared helper problem, while a single unprotected endpoint may require a route-registration correction.
Review the tests alongside the policy whenever roles, sharing or account states change. Our guide to object-level API review develops the resource boundary further. The guide to access reviews that produce revocations addresses the operational side. A good authorization suite makes the intended relationships executable and exposes where that intention is still undefined.