Skip to content

Commit 5454aa9

Browse files
fix(frontend): stabilize RBAC forbidden checks with admin-route testid
Agent-Logs-Url: https://github.com/bg-playground/BGSTM/sessions/96c7b666-e2a6-40ba-9d39-1dadf63afe5f Co-authored-by: bg-playground <259109604+bg-playground@users.noreply.github.com>
1 parent 4880575 commit 5454aa9

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

frontend/src/components/AdminRoute.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const AdminRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
99
if (!isAuthenticated) return <Navigate to="/login" replace />;
1010
if (user?.role !== 'admin') {
1111
return (
12-
<div className="flex flex-col items-center justify-center min-h-[60vh] text-center">
12+
<div data-testid="admin-route-forbidden" className="flex flex-col items-center justify-center min-h-[60vh] text-center">
1313
<h1 className="text-4xl font-bold text-gray-800 mb-4">403</h1>
1414
<p className="text-lg text-gray-600">Access Denied — Admin only.</p>
1515
</div>

frontend/tests/e2e/rbac.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ test.describe('RBAC – Viewer role', () => {
2525
// 3. Redirect to login
2626
const url = page.url();
2727
const wasRedirected = !url.includes('/admin') || url.includes('/login');
28-
const showsForbidden = await page
29-
.getByText(/403|unauthorized|forbidden|access denied|not authorized/i)
30-
.isVisible()
31-
.catch(() => false);
28+
const showsForbidden = await page.getByTestId('admin-route-forbidden').isVisible().catch(() => false);
3229
const showsEmptyOrError = await page
3330
.getByText(/no users|error|something went wrong/i)
3431
.isVisible()
@@ -94,7 +91,7 @@ test.describe('RBAC – Admin role', () => {
9491
expect(page.url()).not.toMatch(/\/login/);
9592

9693
// Should NOT see a 403/forbidden page
97-
const isForbidden = await page.getByText(/403|forbidden|access denied/i).isVisible().catch(() => false);
94+
const isForbidden = await page.getByTestId('admin-route-forbidden').isVisible().catch(() => false);
9895
expect(isForbidden).toBe(false);
9996
});
100-
});
97+
});

0 commit comments

Comments
 (0)