Make Anchor compatible with ldap3>=2.0.7

Don't rely on main ldap3 namespace to contain all exceptions.

Change-Id: I5cc42beb97e1a81614a6d2505832d3aa1de4e0a7
This commit is contained in:
Stanisław Pitucha 2016-11-03 08:26:43 +11:00
parent 59c4e47133
commit b4be922aab
2 changed files with 6 additions and 5 deletions

View File

@ -15,6 +15,7 @@ from __future__ import absolute_import
import logging
import ldap3
from ldap3.core import exceptions as ldap3_exc
from ldap3.utils import dn
from anchor.auth import results
@ -65,10 +66,10 @@ def login(ra_name, user, secret):
user_attrs = ldc.response[0]['attributes']
user_groups = user_get_groups(user_attrs)
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')",
conf['host'], ra_name)
return None
except ldap3.LDAPBindError:
except ldap3_exc.LDAPBindError:
logger.info("failed ldap auth for user %s", user)
return None

View File

@ -16,7 +16,7 @@
import unittest
import ldap3
from ldap3.core import exceptions as ldap3_exc
import mock
from webob import exc as http_status
@ -98,7 +98,7 @@ class AuthLdapTests(tests.DefaultConfigMixin, unittest.TestCase):
jsonloader.conf.load_extensions()
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 self.assertRaises(http_status.HTTPUnauthorized):
@ -110,7 +110,7 @@ class AuthLdapTests(tests.DefaultConfigMixin, unittest.TestCase):
jsonloader.conf.load_extensions()
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 self.assertRaises(http_status.HTTPUnauthorized):