ldap-auth: fixed wrong Missing check
This commit is contained in:
parent
7aea1304de
commit
14cb9ac285
2 changed files with 30 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue