Move fakeldap to tests
fakeldap is only used for testing, so it should be in keystone.tests. Change-Id: Ifff8a6e7cce76e528aa72e5a3a2e7d0fcc69396b
This commit is contained in:
parent
c3229dbb44
commit
993343320e
|
@ -19,7 +19,6 @@ import os.path
|
|||
import ldap
|
||||
from ldap import filter as ldap_filter
|
||||
|
||||
from keystone.common.ldap import fakeldap
|
||||
from keystone import exception
|
||||
from keystone.openstack.common import log as logging
|
||||
|
||||
|
@ -100,6 +99,21 @@ def ldap_scope(scope):
|
|||
'options': ', '.join(LDAP_SCOPES.keys())})
|
||||
|
||||
|
||||
_HANDLERS = {}
|
||||
|
||||
|
||||
def register_handler(prefix, handler):
|
||||
_HANDLERS[prefix] = handler
|
||||
|
||||
|
||||
def get_handler(conn_url):
|
||||
for prefix, handler in _HANDLERS.iteritems():
|
||||
if conn_url.startswith(prefix):
|
||||
return handler
|
||||
|
||||
return LdapWrapper
|
||||
|
||||
|
||||
class BaseLdap(object):
|
||||
DEFAULT_SUFFIX = "dc=example,dc=com"
|
||||
DEFAULT_OU = None
|
||||
|
@ -210,16 +224,15 @@ class BaseLdap(object):
|
|||
return mapping
|
||||
|
||||
def get_connection(self, user=None, password=None):
|
||||
if self.LDAP_URL.startswith('fake://'):
|
||||
conn = fakeldap.FakeLdap(self.LDAP_URL)
|
||||
else:
|
||||
conn = LdapWrapper(self.LDAP_URL,
|
||||
self.page_size,
|
||||
alias_dereferencing=self.alias_dereferencing,
|
||||
use_tls=self.use_tls,
|
||||
tls_cacertfile=self.tls_cacertfile,
|
||||
tls_cacertdir=self.tls_cacertdir,
|
||||
tls_req_cert=self.tls_req_cert)
|
||||
handler = get_handler(self.LDAP_URL)
|
||||
|
||||
conn = handler(self.LDAP_URL,
|
||||
self.page_size,
|
||||
alias_dereferencing=self.alias_dereferencing,
|
||||
use_tls=self.use_tls,
|
||||
tls_cacertfile=self.tls_cacertfile,
|
||||
tls_cacertdir=self.tls_cacertdir,
|
||||
tls_req_cert=self.tls_req_cert)
|
||||
|
||||
if user is None:
|
||||
user = self.LDAP_USER
|
||||
|
|
|
@ -157,7 +157,7 @@ class FakeLdap(object):
|
|||
|
||||
__prefix = 'ldap:'
|
||||
|
||||
def __init__(self, url):
|
||||
def __init__(self, url, *args, **kwargs):
|
||||
LOG.debug(_('FakeLdap initialize url=%s'), url)
|
||||
if url.startswith('fake://memory'):
|
||||
if url not in FakeShelves:
|
|
@ -22,13 +22,14 @@ import ldap
|
|||
|
||||
from keystone import assignment
|
||||
from keystone.common import cache
|
||||
from keystone.common.ldap import fakeldap
|
||||
from keystone.common import ldap as common_ldap
|
||||
from keystone.common import sql
|
||||
from keystone import config
|
||||
from keystone import exception
|
||||
from keystone import identity
|
||||
from keystone import tests
|
||||
from keystone.tests import default_fixtures
|
||||
from keystone.tests import fakeldap
|
||||
from keystone.tests import test_backend
|
||||
|
||||
|
||||
|
@ -339,6 +340,7 @@ class LDAPIdentity(tests.TestCase, BaseLDAPIdentity):
|
|||
self._set_config()
|
||||
self.clear_database()
|
||||
|
||||
common_ldap.register_handler('fake://', fakeldap.FakeLdap)
|
||||
self.load_backends()
|
||||
self.load_fixtures(default_fixtures)
|
||||
|
||||
|
@ -642,10 +644,17 @@ class LDAPIdentity(tests.TestCase, BaseLDAPIdentity):
|
|||
user_api = identity.backends.ldap.UserApi(CONF)
|
||||
self.stubs.Set(fakeldap, 'FakeLdap',
|
||||
self.mox.CreateMock(fakeldap.FakeLdap))
|
||||
common_ldap.register_handler('fake://', fakeldap.FakeLdap)
|
||||
# we have to track all calls on 'conn' to make sure that
|
||||
# conn.simple_bind_s is not called
|
||||
conn = self.mox.CreateMockAnything()
|
||||
conn = fakeldap.FakeLdap(CONF.ldap.url).AndReturn(conn)
|
||||
conn = fakeldap.FakeLdap(CONF.ldap.url,
|
||||
0,
|
||||
alias_dereferencing=None,
|
||||
tls_cacertdir=None,
|
||||
tls_cacertfile=None,
|
||||
tls_req_cert=2,
|
||||
use_tls=False).AndReturn(conn)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
user_api.get_connection(user=None, password=None)
|
||||
|
|
Loading…
Reference in New Issue