Merge "Make Anchor compatible with ldap3>=2.0.7"
This commit is contained in:
commit
24ba8fc0c8
|
@ -15,6 +15,7 @@ from __future__ import absolute_import
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import ldap3
|
import ldap3
|
||||||
|
from ldap3.core import exceptions as ldap3_exc
|
||||||
from ldap3.utils import dn
|
from ldap3.utils import dn
|
||||||
|
|
||||||
from anchor.auth import results
|
from anchor.auth import results
|
||||||
|
@ -65,10 +66,10 @@ def login(ra_name, user, secret):
|
||||||
user_attrs = ldc.response[0]['attributes']
|
user_attrs = ldc.response[0]['attributes']
|
||||||
user_groups = user_get_groups(user_attrs)
|
user_groups = user_get_groups(user_attrs)
|
||||||
return results.AuthDetails(username=user, groups=user_groups)
|
return results.AuthDetails(username=user, groups=user_groups)
|
||||||
except ldap3.LDAPSocketOpenError:
|
except ldap3_exc.LDAPSocketOpenError:
|
||||||
logger.error("cannot connect to LDAP host '%s' (authority '%s')",
|
logger.error("cannot connect to LDAP host '%s' (authority '%s')",
|
||||||
conf['host'], ra_name)
|
conf['host'], ra_name)
|
||||||
return None
|
return None
|
||||||
except ldap3.LDAPBindError:
|
except ldap3_exc.LDAPBindError:
|
||||||
logger.info("failed ldap auth for user %s", user)
|
logger.info("failed ldap auth for user %s", user)
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import ldap3
|
from ldap3.core import exceptions as ldap3_exc
|
||||||
import mock
|
import mock
|
||||||
from webob import exc as http_status
|
from webob import exc as http_status
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ class AuthLdapTests(tests.DefaultConfigMixin, unittest.TestCase):
|
||||||
jsonloader.conf.load_extensions()
|
jsonloader.conf.load_extensions()
|
||||||
config = "anchor.jsonloader.conf._config"
|
config = "anchor.jsonloader.conf._config"
|
||||||
|
|
||||||
mock_connection.side_effect = ldap3.LDAPBindError()
|
mock_connection.side_effect = ldap3_exc.LDAPBindError()
|
||||||
|
|
||||||
with mock.patch.dict(config, self.sample_conf):
|
with mock.patch.dict(config, self.sample_conf):
|
||||||
with self.assertRaises(http_status.HTTPUnauthorized):
|
with self.assertRaises(http_status.HTTPUnauthorized):
|
||||||
|
@ -110,7 +110,7 @@ class AuthLdapTests(tests.DefaultConfigMixin, unittest.TestCase):
|
||||||
jsonloader.conf.load_extensions()
|
jsonloader.conf.load_extensions()
|
||||||
config = "anchor.jsonloader.conf._config"
|
config = "anchor.jsonloader.conf._config"
|
||||||
|
|
||||||
mock_connection.side_effect = ldap3.LDAPSocketOpenError()
|
mock_connection.side_effect = ldap3_exc.LDAPSocketOpenError()
|
||||||
|
|
||||||
with mock.patch.dict(config, self.sample_conf):
|
with mock.patch.dict(config, self.sample_conf):
|
||||||
with self.assertRaises(http_status.HTTPUnauthorized):
|
with self.assertRaises(http_status.HTTPUnauthorized):
|
||||||
|
|
Loading…
Reference in New Issue