def search( self, search_base, search_filter, search_scope=ldap3.SUBTREE, dereference_aliases=ldap3.DEREF_ALWAYS, attributes=None, ): if "CN=LDAPInvalidDnError,DC=example,DC=com" in search_filter: raise LDAPInvalidDnError("Some error") if "CN=LDAPOperationsErrorResult,DC=example,DC=com" in search_filter: raise LDAPOperationsErrorResult("Some error") if "CN=wrong_result,DC=example,DC=com" in search_filter: self.result[self.RESULT] = RESULT_OPERATIONS_ERROR return if "CN=empty_search,DC=example,DC=com" in search_filter or "CN=empty_search,DC=example,DC=com" in search_base: self.result[self.DESCRIPTION] = "empty_search" return if "CN=empty_group,DC=example,DC=com" in search_base: self.result[self.DESCRIPTION] = "failed" return self.result[self.RESULT] = RESULT_SUCCESS self.result[self.DESCRIPTION] = "success" self.response = [{ "dn": search_base, "attributes": { "userAccountControl": False } }]
def default_modify(self, dn): if "CN=LDAPInvalidDnError,DC=example,DC=com" in dn: raise LDAPInvalidDnError("Some error") if "CN=wrong_result,DC=example,DC=com" in dn: self.result[self.RESULT] = RESULT_OPERATIONS_ERROR return self.result[self.RESULT] = RESULT_SUCCESS
def _test_bind_dn(self): user = self.config.bind_dn password = self.config.password ret = self._test_connection_bind( authentication=SIMPLE, user=user, password=password ) if not ret: msg = _('Bind DN or Password incorrect') raise LDAPInvalidDnError(msg)