We Replaced 85 Brittle RBAC UI Tests With One 60-Line Permission Matrix
Learn how an engineering team replaced slow Playwright RBAC tests with a declarative API permission matrix to improve authorization testing.
The wire material describes how a software team replaced 85 brittle role-based access control (RBAC) UI tests with a single 60-line permission matrix. The team found that their 85 Playwright tests, which took 18 minutes to run in CI, missed a high-severity authorization bypass during a pentest. This was because UI tests checked what React rendered, not what Express allowed.
As the SaaS platform grew from two roles to five, the number of browser tests exploded to 85, each testing 17 sensitive actions for each role. The team realized that UI tests masked backend neglect and that frontend developers often forgot to enforce backend role restrictions in API code.
To address this, the team created a single source of truth, a permission matrix in `src/auth/permissionMatrix.ts`, mapping every API route to the exact list of roles allowed to call it. This matrix was consumed by two things: an Express/Fastify route guard middleware that refused to start in CI if a route was missing from the matrix, and a single data-driven Vitest/Playwright API test that looped over every row in the matrix and fired real HTTP requests with pre-minted JWTs for five roles (owner, admin, billing, member, viewer). The test asserted 403 for every disallowed role and non-403 for allowed roles.
The fail-closed middleware (`src/auth/enforcePolicy.ts`) ensures that no engineer can ship an unprotected endpoint by accident. If a route is not found in the permission matrix, the middleware returns a 403 error with a JSON response detailing which roles are allowed. This puts the role list right in the GitHub PR diff for security and QA reviewers to see.
With the permission matrix in place, the team replaced their 85 Playwright tests with a single 65-line API test (`tests/security/rbac-matrix.test.ts`). This test proved to be much faster, running in just 1.9 seconds. Additionally, the team added horizontal tenant isolation to the loop, proving that even an Owner cannot read or delete another customer's invoice or card.
Rewritten by urgent.news; may contain errors โ check the original.
Source: hackernoon.com
Read the original at hackernoon.com โ
More from HackerNoon on urgent.news
Report a problem with this story
Get the day's news by email. Daily, weekly or monthly. Sign up