summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjohn-griffith <john.griffith@solidfire.com>2012-02-02 22:15:58 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2012-02-13 16:39:10 -0800
commitfa295d1278ef43fe2e90902006a5d073d78173ad (patch)
tree132973e349bcfe30d7208dd1f603e0f74dd56247
parent46e194fdb1ad3675490fd22a6d71e6db7225a4f2 (diff)
get_user behavior in ldapdriver
* 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
-rw-r--r--nova/auth/ldapdriver.py7
-rw-r--r--nova/tests/test_auth.py5
2 files changed, 11 insertions, 1 deletions
diff --git a/nova/auth/ldapdriver.py b/nova/auth/ldapdriver.py
index 4173ecbd9..e1fa70d65 100644
--- a/nova/auth/ldapdriver.py
+++ b/nova/auth/ldapdriver.py
@@ -223,6 +223,8 @@ class LdapDriver(object):
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
@@ -495,7 +497,10 @@ class LdapDriver(object):
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"""
diff --git a/nova/tests/test_auth.py b/nova/tests/test_auth.py
index a80da43f4..e645b3698 100644
--- a/nova/tests/test_auth.py
+++ b/nova/tests/test_auth.py
@@ -394,6 +394,11 @@ class _AuthManagerBaseTestCase(test.TestCase):
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'