enable ldap tests for py3
by moving to pyldap and a new py3 friendly version of ldappool, we can now run keystone's ldap tests with py3. Change-Id: I0da97db0859079e3a134c6ec1de0c4b4f16f7035
This commit is contained in:
parent
7463a0cbce
commit
465c3e4036
|
@ -13,24 +13,6 @@
|
|||
# under the License.
|
||||
|
||||
import oslo_i18n
|
||||
import six
|
||||
|
||||
|
||||
if six.PY3:
|
||||
# NOTE(dstanek): This block will monkey patch libraries that are not
|
||||
# yet supported in Python3. We do this that that it is possible to
|
||||
# execute any tests at all. Without monkey patching modules the
|
||||
# tests will fail with import errors.
|
||||
|
||||
import sys
|
||||
from unittest import mock # noqa: our import detection is naive?
|
||||
|
||||
sys.modules['ldap'] = mock.Mock()
|
||||
sys.modules['ldap.controls'] = mock.Mock()
|
||||
sys.modules['ldap.dn'] = mock.Mock()
|
||||
sys.modules['ldap.filter'] = mock.Mock()
|
||||
sys.modules['ldap.modlist'] = mock.Mock()
|
||||
sys.modules['ldappool'] = mock.Mock()
|
||||
|
||||
|
||||
# NOTE(dstanek): oslo_i18n.enable_lazy() must be called before
|
||||
|
|
|
@ -422,7 +422,7 @@ class CommonLdapTestCase(unit.BaseTestCase):
|
|||
'cn': ['junk'],
|
||||
'sn': [uuid.uuid4().hex],
|
||||
'mail': [uuid.uuid4().hex],
|
||||
'binary_attr': ['\x00\xFF\x00\xFF']
|
||||
'binary_attr': [b'\x00\xFF\x00\xFF']
|
||||
}
|
||||
), ]
|
||||
py_result = ks_ldap.convert_ldap_result(result)
|
||||
|
|
|
@ -80,7 +80,6 @@ def _internal_attr(attr_name, value_or_values):
|
|||
name, val, i = part[0]
|
||||
name = core.utf8_decode(name)
|
||||
name = name.upper()
|
||||
name = core.utf8_encode(name)
|
||||
norm.append([(name, val, i)])
|
||||
return core.utf8_decode(ldap.dn.dn2str(norm))
|
||||
|
||||
|
@ -299,7 +298,8 @@ class FakeLdap(core.LDAPHandler):
|
|||
if server_fail:
|
||||
raise ldap.SERVER_DOWN
|
||||
whos = ['cn=Admin', CONF.ldap.user]
|
||||
if who in whos and cred in ['password', CONF.ldap.password]:
|
||||
if (core.utf8_decode(who) in whos and
|
||||
core.utf8_decode(cred) in ['password', CONF.ldap.password]):
|
||||
return
|
||||
|
||||
try:
|
||||
|
@ -316,7 +316,7 @@ class FakeLdap(core.LDAPHandler):
|
|||
core.utf8_decode(who))
|
||||
raise ldap.INAPPROPRIATE_AUTH
|
||||
|
||||
if cred != db_password:
|
||||
if cred != core.utf8_encode(db_password):
|
||||
LOG.debug('bind fail: password for who=%s does not match',
|
||||
core.utf8_decode(who))
|
||||
raise ldap.INVALID_CREDENTIALS
|
||||
|
@ -524,7 +524,8 @@ class FakeLdap(core.LDAPHandler):
|
|||
match_attrs = attrs.copy()
|
||||
match_attrs[id_attr] = [id_val]
|
||||
attrs_checked = set()
|
||||
if not filterstr or _match_query(filterstr, match_attrs,
|
||||
if not filterstr or _match_query(core.utf8_decode(filterstr),
|
||||
match_attrs,
|
||||
attrs_checked):
|
||||
if (filterstr and
|
||||
(scope != ldap.SCOPE_BASE) and
|
||||
|
@ -532,7 +533,7 @@ class FakeLdap(core.LDAPHandler):
|
|||
raise AssertionError('No objectClass in search filter')
|
||||
# filter the attributes by attrlist
|
||||
attrs = {k: v for k, v in attrs.items()
|
||||
if not attrlist or k in attrlist}
|
||||
if not attrlist or k in core.utf8_decode(attrlist)}
|
||||
objects.append((dn, attrs))
|
||||
|
||||
return objects
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
keystone.tests.unit.common.test_ldap
|
||||
keystone.tests.unit.identity.backends.test_ldap
|
||||
keystone.tests.unit.test_backend_ldap
|
||||
keystone.tests.unit.test_backend_ldap_pool
|
||||
keystone.tests.unit.test_v3_auth
|
||||
keystone.tests.unit.test_v3_credential
|
||||
keystone.tests.unit.test_v3_oauth1
|
||||
|
|
Loading…
Reference in New Issue