Repository navigation
Conversation
What:
Only run the client lookup in RealmRoleTabs when a clientId is present.
Why:
The useFetch callback was guarded by clientId, but the fetch itself was
not. For a realm role, clientId is undefined and the {id} URI template
of the client lookup collapses to the clients list endpoint, which
requires view-clients permission. Users who may manage realm roles
without that permission got a 403 that useFetch forwards to the error
boundary, leaving the whole realm-role page unusable. Regression
introduced in keycloak#32249.
How:
Return undefined instead of calling the admin client when there is no
clientId, and add render tests covering both paths: a realm role must
not trigger the client lookup, while a client role still resolves the
client and propagates its manage access flag.
Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
The error-boundary test can pass without verifying boundary behavior because mocks.showBoundary is disconnected and the header assertion does not observe the provider’s error state.
1 open issue
What changed in this PR
Fixes #55225 by avoiding unnecessary client lookups when viewing realm roles in the Admin Console, allowing role managers without client-view permissions to access the page.
Changes:
- Guard the client lookup with
clientId, preserving lookup behavior for client roles. - Add render tests for skipped realm-role lookups and propagation of client-role manage access.
| File | Description |
|---|---|
js/apps/admin-ui/src/realm-roles/RealmRoleTabs.tsx |
Skip the client request when no client ID is present. |
js/apps/admin-ui/src/realm-roles/__tests__/RealmRoleTabs.test.tsx |
Add regression tests for realm-role and client-role paths. |
Review effort: Balanced
edewit
left a comment
There was a problem hiding this comment.
Instead of a unit test it would be better to use playwright
What: Replace the RealmRoleTabs unit test with a Playwright spec under test/realm-roles/client-lookup.spec.ts. Why: Requested in the PR review: cover the regression with a Playwright test instead of a mocked unit test. The mock harness could not demonstrate the real failure mode where a role manager without view-clients permission receives a 403 from the clients collection endpoint that trips the error boundary and makes the realm role page unusable (keycloak#55225). How: The spec creates a realm with a role manager granted only view-realm, view-users and manage-realm, plus a client with a client role. The clients collection endpoint is intercepted to respond 403 as the server does for a user without view-clients. Opening and editing the realm role must render the role page and never send that request, while a client role must still resolve its client. Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
|
Reworked in e6e55c1: the mocked unit test is removed and replaced by a Playwright spec at It creates a realm with a role manager holding only Verification: eslint (type-aware), a scoped |
There was a problem hiding this comment.
🟡 Changes recommended
The regression test cannot reach the role page because its realm is disabled by default and its user lacks required profile fields, both of which block login.
2 open issues
1 resolved since last review
Review effort: Balanced
| let clientObjectId: string; | ||
|
|
||
| test.beforeAll(async () => { | ||
| await adminClient.createRealm(realmName); |
| const { id } = await adminClient.createUser({ | ||
| realm: realmName, | ||
| username: restrictedUser.username, | ||
| enabled: true, |
Fixes #55225
What
Guard the client lookup in
RealmRoleTabsso it only runs for client roles.Why
The
useFetchcallback was guarded byclientId, but the fetch itself was not. For a realm role,clientIdisundefinedand the{id}URI template ofadminClient.clients.findOne({ id: clientId })collapses to the clients list endpoint (GET /admin/realms/{realm}/clients/). That endpoint returns403for users who may manage realm roles withoutview-clients/query-clientspermission, anduseFetchforwards the error to the error boundary, which makes the whole realm-role page unusable. Regression introduced in #32249.How
Return
undefinedinstead of calling the admin client when there is noclientId, exactly as suggested in the issue. A new render test covers both paths:manageaccess flag.Verification
pnpm exec vitest runinjs/apps/admin-ui: 15 test files, 87 tests pass, including the 2 new ones; the new realm-role test fails without the fix (red-check).tsc --noEmit,eslintandprettier --checkpass on the changed files.