# HG changeset patch # User Marcin Kuzminski # Date 2016-06-08 12:03:02 # Node ID d027fa2ebfa54905a485b91acf5864f13bfa38fb # Parent d340216ac94a56551a1dea71ebcdf0f53f978c2b ldap-auth: fixed wrong Missing check diff --git a/rhodecode/authentication/plugins/auth_ldap.py b/rhodecode/authentication/plugins/auth_ldap.py --- a/rhodecode/authentication/plugins/auth_ldap.py +++ b/rhodecode/authentication/plugins/auth_ldap.py @@ -46,8 +46,9 @@ log = logging.getLogger(__name__) try: import ldap except ImportError: - # means that python-ldap is not installed - ldap = Missing() + # means that python-ldap is not installed, we use Missing object to mark + # ldap lib is Missing + ldap = Missing def plugin_factory(plugin_id, *args, **kwds): @@ -182,7 +183,7 @@ class AuthLdap(object): tls_kind='PLAIN', tls_reqcert='DEMAND', ldap_version=3, search_scope='SUBTREE', attr_login='uid', ldap_filter='(&(objectClass=user)(!(objectClass=computer)))'): - if isinstance(ldap, Missing): + if ldap == Missing: raise LdapImportError("Missing or incompatible ldap library") self.ldap_version = ldap_version diff --git a/rhodecode/tests/lib/auth_modules/test_auth_modules.py b/rhodecode/tests/lib/auth_modules/test_auth_modules.py --- a/rhodecode/tests/lib/auth_modules/test_auth_modules.py +++ b/rhodecode/tests/lib/auth_modules/test_auth_modules.py @@ -155,3 +155,29 @@ class TestRhodeCodeAuthPlugin(object): self.password_generator_mock = password_generator_patch.start() self.password_generator_mock.return_value = 'new-password' self.finalizers.append(password_generator_patch.stop) + + +def test_missing_ldap(): + from rhodecode.model.validators import Missing + + try: + import ldap_not_existing + except ImportError: + # means that python-ldap is not installed + ldap_not_existing = Missing + + # missing is singleton + assert ldap_not_existing == Missing + + +def test_import_ldap(): + from rhodecode.model.validators import Missing + + try: + import ldap + except ImportError: + # means that python-ldap is not installed + ldap = Missing + + # missing is singleton + assert False is (ldap == Missing)