Skip to content

Commit

Permalink
get_user behavior in ldapdriver
Browse files Browse the repository at this point in the history
* Addresses bug 744462

Rather than ldapdriver.get_user() returning None for non-existent
user, this change implements exception.LDAPUserNotFound to more
closely match the behavior of other drivers (db).

Change was made in public method only, and _check_user_exists()
which uses get_user() now catches and returns None if applicable.
Implemented test of NotFound exception in base auth test class.

Change-Id: Ia13af759931ca0c7327d54184730537bafbe52ae
  • Loading branch information
j-griffith authored and vishvananda committed Feb 14, 2012
1 parent 46e194f commit fa295d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nova/auth/ldapdriver.py
Expand Up @@ -223,6 +223,8 @@ def inner(self, arg, **kwargs):
def get_user(self, uid):
"""Retrieve user by id"""
attr = self.__get_ldap_user(uid)
if attr is None:
raise exception.LDAPUserNotFound(user_id=uid)
return self.__to_user(attr)

@sanitize
Expand Down Expand Up @@ -495,7 +497,10 @@ def modify_user(self, uid, access_key=None, secret_key=None, admin=None):

def __user_exists(self, uid):
"""Check if user exists"""
return self.get_user(uid) is not None
try:
return self.get_user(uid) is not None
except exception.LDAPUserNotFound:
return False

def __ldap_user_exists(self, uid):
"""Check if the user exists in ldap"""
Expand Down
5 changes: 5 additions & 0 deletions nova/tests/test_auth.py
Expand Up @@ -394,6 +394,11 @@ def test_can_call_modify_user_but_do_nothing(self):
self.assertEqual(old_user.secret, user.secret)
self.assertEqual(old_user.is_admin(), user.is_admin())

def test_get_nonexistent_user_raises_notfound_exception(self):
self.assertRaises(exception.NotFound,
self.manager.get_user,
'joeblow')


class AuthManagerLdapTestCase(_AuthManagerBaseTestCase):
auth_driver = 'nova.auth.ldapdriver.FakeLdapDriver'
Expand Down

0 comments on commit fa295d1

Please sign in to comment.