Example #1
0
    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))
Example #2
0
 def get_connection(self, user=None, password=None):
     if self.LDAP_URL.startswith('fake://'):
         conn = fakeldap.FakeLdap(self.LDAP_URL)
     else:
         conn = common_ldap.LdapWrapper(self.LDAP_URL)
     if user is None:
         user = self.LDAP_USER
     if password is None:
         password = self.LDAP_PASSWORD
     conn.simple_bind_s(user, password)
     return conn