Fix get_all_users to fetch full KC representations and remove stale tests

KC 26+ does not return firstName/email from the paginated users list endpoint
regardless of briefRepresentation param. Switch to fetching each user's full
representation individually via GET /users/{id}, which always returns complete
data. This fixes the discrepancy scan showing false first_name/email mismatches
and the startup sync not populating last names.

Also remove two stale test_settings.py tests that validated default_billing_type,
which was removed as part of the billing_type cleanup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-18 14:11:34 -07:00
parent 525be3ba6d
commit 155a4c0d5a
2 changed files with 21 additions and 18 deletions

View File

@@ -345,23 +345,39 @@ class KeycloakClient:
logger.info("Keycloak user deleted: %s", keycloak_id)
def get_all_users(self) -> list[dict]:
"""Paginated fetch of all realm users (full representation)."""
"""Paginated fetch of all realm users (full representation).
KC 26+ may return brief representations from the list endpoint regardless
of the briefRepresentation param (firstName/email absent). We fetch each
user individually via GET /users/{id} which always returns full data.
"""
if not self.enabled:
return []
all_users = []
# Page through to collect all user IDs
ids = []
page_size = 100
first = 0
while True:
resp = self._request(
"GET", "/users", params={"first": first, "max": page_size, "briefRepresentation": "false"}
"GET", "/users", params={"first": first, "max": page_size}
)
batch = resp.json()
all_users.extend(batch)
ids.extend(u["id"] for u in batch)
if len(batch) < page_size:
break
first += page_size
return all_users
# Fetch full representation for each user
full_users = []
for uid in ids:
try:
user = self.get_user(uid)
if user:
full_users.append(user)
except KeycloakError:
pass
return full_users
def get_all_groups(self) -> list[dict]:
"""Fetch all top-level groups."""

View File

@@ -283,19 +283,6 @@ class TestUpdateAllSettings:
})
assert resp.status_code == 400
def test_validates_default_billing_type(self, admin_client):
resp = admin_client.put("/api/settings/all", json={
"default_billing_type": "invalid_type",
})
assert resp.status_code == 400
def test_valid_billing_types(self, admin_client):
for bt in ("core", "collaborator", "standing"):
resp = admin_client.put("/api/settings/all", json={
"default_billing_type": bt,
})
assert resp.status_code == 200
def test_validates_max_upload_size_mb(self, admin_client):
resp = admin_client.put("/api/settings/all", json={
"max_upload_size_mb": 0,