def _init_server(self, reuse_existing=True): global reusable_server """Sets self.server to a test LDAP server and self.base to its base""" if reuse_existing: server = get_reusable_server() else: server = slapd.Slapd() # private server #server.set_debug() # enables verbose messages server.start() # no effect if already started self.server = server self.base = server.get_dn_suffix() return server
def setUp(self): from tardis.tardis_portal.tests.ldap_ldif import test_ldif import slapd global server if not slapd.Slapd.check_paths(): raise SkipTest() server = slapd.Slapd() server.set_port(38911) server.set_dn_suffix("dc=example, dc=com") server.start() base = server.get_dn_suffix() server.ldapadd("\n".join(test_ldif) + "\n") self.server = server
def setUp(self): global server if server is None: server = slapd.Slapd() server.start() base = server.get_dn_suffix() # insert some Foo* objects via ldapadd server.ldapadd("\n".join([ "dn: cn=Foo1,"+base, "objectClass: organizationalRole", "cn: Foo1", "", "dn: cn=Foo2,"+base, "objectClass: organizationalRole", "cn: Foo2", "", "dn: cn=Foo3,"+base, "objectClass: organizationalRole", "cn: Foo3", "", "dn: ou=Container,"+base, "objectClass: organizationalUnit", "ou: Container", "", "dn: cn=Foo4,ou=Container,"+base, "objectClass: organizationalRole", "cn: Foo4", "", ])+"\n") l = LDAPObject(server.get_url()) l.protocol_version = 3 l.set_option(ldap.OPT_REFERRALS,0) l.simple_bind_s(server.get_root_dn(), server.get_root_password()) self.ldap = l self.server = server
def get_reusable_server(): global reusable_server if reusable_server is None: reusable_server = slapd.Slapd() return reusable_server
import logging import slapd slapd = slapd.Slapd( suffix="dc=mydomain,dc=tld", root_cn="admin", root_pw="admin", port=5389, log_level=logging.INFO, schemas=( "core.ldif", "cosine.ldif", "nis.ldif", "inetorgperson.ldif", "../schemas/oauth2-openldap.ldif", "ldif/memberof.ldif", ), ) slapd.start() try: suffix_dc = slapd.suffix.split(",")[0][3:] slapd.ldapadd( "\n".join( [ "dn: " + slapd.suffix, "objectClass: dcObject", "objectClass: organization", "dc: " + suffix_dc,