Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fastapi_keycloak/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ def get_user(self, user_id: str = None, query: str = "") -> KeycloakUser:
response = self._admin_request(
url=f"{self.users_uri}?{query}", method=HTTPMethod.GET
)
if not response.json():
raise UserNotFound(
status_code = status.HTTP_404_NOT_FOUND,
reason=f"User query with filters of [{query}] did no match any users"
)
return KeycloakUser(**response.json()[0])
else:
response = self._admin_request(
Expand Down
9 changes: 7 additions & 2 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,5 +451,10 @@ def test_user_not_found_exception(self, idp):

with pytest.raises(
UserNotFound
): # Expect the get to fail due to anon existant user
u = idp.get_user(user_id="some_non_existant_user_id")
): # Expect the get to fail due to a non existant user
u = idp.get_user(user_id="some_non_existant_user_id")

with pytest.raises(
UserNotFound
): # Expect the get to fail due to a failed query search
u = idp.get_user(username="some_non_existant_username")