Developer Tools

Turn a Role-Permission Matrix Into Tests That Catch Both Over-Granting and Under-Granting

You are helping me turn an access-control policy into tests that fail if any role can do more than it should (over-granting) or less than it should (under-granting). Most authorization test suites check only that permitted actions work. A role silently gaining delete rights then passes every test.

I will give you:
- ROLES: the list of roles, including anonymous/unauthenticated and any suspended or pending states.
- RESOURCES AND ACTIONS: what can be done (e.g. invoice: view, create, edit, delete, export).
- POLICY: the rules in whatever form we have (a table, prose, or code), including ownership rules ("members can edit their own drafts") and tenant boundaries.
- (Optional) the code or config that enforces it.

Produce:
1. A complete matrix: every role × resource × action, with the expected result ALLOW or DENY and the policy line that decides it. Mark every cell where the policy is silent or ambiguous as UNDECIDED, and list those as questions for me. Don't guess them.
2. Context variants for the cells where the answer depends on more than the role: own object vs. someone else's, same tenant vs. other tenant, resource in draft vs. published vs. archived. Each variant becomes its own row.
3. A test list that includes one test per DENY cell, not just per ALLOW cell. For each test, give the actor, the setup, the request, and the expected status code or error. Also give the side-effect assertion: after a denied delete, the object still exists.
4. Indirect paths worth testing for the riskiest DENY cells: bulk endpoints, export jobs, search results, GraphQL nested fields, webhooks, and IDs guessed from other tenants.
5. A suggested table-driven structure so new roles or actions fail loudly until someone fills in their row. For example, the test generator raises an error when the matrix has an empty cell.

When to use it: before you ship a new role, after a permissions refactor, or when an audit asks you to show that access rules are tested.

How to adapt it: for attribute-based policies, replace roles with the attribute combinations that matter. For APIs with field-level permissions, add fields as resources. If enforcement lives in several layers (gateway, service, database row-level security), say which layer each test targets.

Example input: roles admin, member, viewer, anonymous. Resource project with actions view, edit, delete, invite. Policy: "members can edit projects they belong to; only admins delete; viewers read-only."

Good output: a 4 × 4 matrix plus "member edits a project they don't belong to" and "member of tenant B views tenant A's project" rows. It flags as UNDECIDED whether members can invite, and asserts that the project survives after a viewer's DELETE request returns 403.

Sign in to upvote this prompt.