Commit 0866eaf1 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added email kwarg to get_user

parent fd7e312d
......@@ -326,7 +326,7 @@ class Keycloak():
self.__user_from_keycloak_user(keycloak_user)
for keycloak_user in keycloak_results]
def get_user(self, user_id: str = None, username: str = None, user=None):
def get_user(self, user_id: str = None, username: str = None, email: str = None, user=None):
'''
Retrives all available information about a user from the keycloak admin
interface. This must be used to retrieve complete user information, because
......@@ -343,6 +343,16 @@ class Keycloak():
if user_id is None:
raise KeyError('User with username %s does not exist' % username)
if email is not None and user_id is None:
with utils.lnr(logger, 'Could not use keycloak admin client'):
users = self._admin_client.get_users(query=dict(email=email))
if len(users) > 0:
user_id = users[0]['id']
if user_id is None:
raise KeyError('User with email %s does not exist' % email)
assert user_id is not None, 'Could not determine user from given kwargs'
try:
......
......@@ -307,7 +307,7 @@ class KeycloakMock:
last_name=user.last_name, user_id=user.user_id)
return None
def get_user(self, user_id=None, username=None):
def get_user(self, user_id=None, username=None, email=None):
if user_id is not None:
return User(**self.users[user_id])
elif username is not None:
......@@ -315,6 +315,11 @@ class KeycloakMock:
if user_values['username'] == username:
return User(**user_values)
raise KeyError('Only test user usernames are recognized')
elif email is not None:
for user_id, user_values in self.users.items():
if user_values['email'] == email:
return User(**user_values)
raise KeyError('Only test user emails are recognized')
else:
assert False, 'no token based get_user during tests'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment