summaryrefslogtreecommitdiffstats
path: root/tests/_ldap_livetest.py
diff options
context:
space:
mode:
authorAllan Feid <allanfeid@gmail.com>2013-03-11 23:11:52 -0400
committerAllan Feid <allanfeid@gmail.com>2013-03-21 10:00:07 -0400
commitaa6c01a062b00516c9d26f3e23bd04b1075c4e2f (patch)
tree7f7c2aeb1e8f7d9e5bf31af951a103f2cf95b6f5 /tests/_ldap_livetest.py
parentaa58233bd8ba174e07076444b0dc5fdb67f5a5e6 (diff)
downloadkeystone-aa6c01a062b00516c9d26f3e23bd04b1075c4e2f.tar.gz
keystone-aa6c01a062b00516c9d26f3e23bd04b1075c4e2f.tar.xz
keystone-aa6c01a062b00516c9d26f3e23bd04b1075c4e2f.zip
Add a dereference option for ldap
This allows proper dereferencing of aliased objects in an LDAP tree. Fixes Bug #1153786 Change-Id: Ia09a99b7bca1ab055eb0c6dfa34138beca15bff0
Diffstat (limited to 'tests/_ldap_livetest.py')
-rw-r--r--tests/_ldap_livetest.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/_ldap_livetest.py b/tests/_ldap_livetest.py
index d6a7a63d..5d9e96d0 100644
--- a/tests/_ldap_livetest.py
+++ b/tests/_ldap_livetest.py
@@ -19,7 +19,9 @@ import ldap.modlist
import nose.exc
import subprocess
+from keystone.common import ldap as ldap_common
from keystone import config
+from keystone import exception
from keystone.identity.backends import ldap as identity_ldap
from keystone import test
@@ -92,3 +94,72 @@ class LiveLDAPIdentity(test_backend_ldap.LDAPIdentity):
def test_user_enable_attribute_mask(self):
raise nose.exc.SkipTest('Test is for Active Directory Only')
+
+ def test_ldap_dereferencing(self):
+ alt_users_ldif = {'objectclass': ['top', 'organizationalUnit'],
+ 'ou': 'alt_users'}
+ alt_fake_user_ldif = {'objectclass': ['person', 'inetOrgPerson'],
+ 'cn': 'alt_fake1',
+ 'sn': 'alt_fake1'}
+ aliased_users_ldif = {'objectclass': ['alias', 'extensibleObject'],
+ 'aliasedobjectname': "ou=alt_users,%s" %
+ CONF.ldap.suffix}
+ create_object("ou=alt_users,%s" % CONF.ldap.suffix, alt_users_ldif)
+ create_object("%s=alt_fake1,ou=alt_users,%s" %
+ (CONF.ldap.user_id_attribute, CONF.ldap.suffix),
+ alt_fake_user_ldif)
+ create_object("ou=alt_users,%s" % CONF.ldap.user_tree_dn,
+ aliased_users_ldif)
+
+ CONF.ldap.query_scope = 'sub'
+ CONF.ldap.alias_dereferencing = 'never'
+ self.identity_api = identity_ldap.Identity()
+ self.assertRaises(exception.UserNotFound,
+ self.identity_api.get_user,
+ 'alt_fake1')
+
+ CONF.ldap.alias_dereferencing = 'searching'
+ self.identity_api = identity_ldap.Identity()
+ user_ref = self.identity_api.get_user('alt_fake1')
+ self.assertEqual(user_ref['id'], 'alt_fake1')
+
+ CONF.ldap.alias_dereferencing = 'always'
+ self.identity_api = identity_ldap.Identity()
+ user_ref = self.identity_api.get_user('alt_fake1')
+ self.assertEqual(user_ref['id'], 'alt_fake1')
+
+ def test_base_ldap_connection_deref_option(self):
+ deref = ldap_common.parse_deref('default')
+ ldap_wrapper = ldap_common.LdapWrapper(CONF.ldap.url,
+ CONF.ldap.page_size,
+ alias_dereferencing=deref)
+ self.assertEqual(ldap.get_option(ldap.OPT_DEREF),
+ ldap_wrapper.conn.get_option(ldap.OPT_DEREF))
+
+ deref = ldap_common.parse_deref('always')
+ ldap_wrapper = ldap_common.LdapWrapper(CONF.ldap.url,
+ CONF.ldap.page_size,
+ alias_dereferencing=deref)
+ self.assertEqual(ldap.DEREF_ALWAYS,
+ ldap_wrapper.conn.get_option(ldap.OPT_DEREF))
+
+ deref = ldap_common.parse_deref('finding')
+ ldap_wrapper = ldap_common.LdapWrapper(CONF.ldap.url,
+ CONF.ldap.page_size,
+ alias_dereferencing=deref)
+ self.assertEqual(ldap.DEREF_FINDING,
+ ldap_wrapper.conn.get_option(ldap.OPT_DEREF))
+
+ deref = ldap_common.parse_deref('never')
+ ldap_wrapper = ldap_common.LdapWrapper(CONF.ldap.url,
+ CONF.ldap.page_size,
+ alias_dereferencing=deref)
+ self.assertEqual(ldap.DEREF_NEVER,
+ ldap_wrapper.conn.get_option(ldap.OPT_DEREF))
+
+ deref = ldap_common.parse_deref('searching')
+ ldap_wrapper = ldap_common.LdapWrapper(CONF.ldap.url,
+ CONF.ldap.page_size,
+ alias_dereferencing=deref)
+ self.assertEqual(ldap.DEREF_SEARCHING,
+ ldap_wrapper.conn.get_option(ldap.OPT_DEREF))