Skip to main content
RBAC bugs usually come from drift between backend authorization rules and frontend visibility rules. This guide shows a repeatable Playwright pattern to test both.

What to Cover

  • Positive access: user can see and perform allowed actions.
  • Negative access: user cannot view page, button, or API-backed action.
  • Escalation attempts: direct URL navigation and API-triggering UI actions are blocked.

Model Roles as Playwright Projects

Use one project per role so each role has explicit storageState.
playwright.config.ts

Write a Permission Matrix

Encode expected permissions once, then reuse in tests.
tests/rbac/permissions.ts

Assert Both UI and Server Outcomes

tests/rbac/billing.spec.ts

High-Value RBAC Cases

  1. User downgraded from admin to viewer mid-session.
  2. Invite flow grants wrong default role.
  3. Protected API action succeeds from hidden-but-triggerable UI path.
  4. Cached permissions allow stale access after logout/login.
Run RBAC tests with strict isolation: no shared mutable account state between role projects.

Stably Features to Use for RBAC Coverage