3
3
4
4
See http://www.python-ldap.org/ for details.
5
5
6
- \$Id: slapdtest.py,v 1.4 2017/04/27 11:13:39 stroeder Exp $
6
+ \$Id: slapdtest.py,v 1.5 2017/04/27 12:24:50 stroeder Exp $
7
7
8
8
Python compability note:
9
9
This module only works with Python 2.7.x since
17
17
import subprocess
18
18
import logging
19
19
import unittest
20
+ import urllib
20
21
21
22
# determine log level
22
23
try :
@@ -114,11 +115,13 @@ class SlapdObject(object):
114
115
def __init__ (self ):
115
116
self ._proc = None
116
117
self ._port = find_available_tcp_port (LOCALHOST )
117
- self .ldap_uri = "ldap://%s:%d/" % (LOCALHOST , self ._port )
118
118
self ._log = _LOGGER
119
119
self .testrundir = os .path .join (self .TMPDIR , 'python-ldap-test' )
120
120
self ._slapd_conf = os .path .join (self .testrundir , "slapd.conf" )
121
121
self ._db_directory = os .path .join (self .testrundir , "openldap-data" )
122
+ self .ldap_uri = "ldap://%s:%d/" % (LOCALHOST , self ._port )
123
+ ldapi_path = os .path .join (self .testrundir , 'ldapi-%d' % self ._port )
124
+ self .ldapi_uri = "ldapi://%s" % urllib .quote_plus (ldapi_path )
122
125
123
126
def _gen_config (self ):
124
127
"""
@@ -177,9 +180,9 @@ def _start_slapd(self):
177
180
self ._log .info ("starting slapd" )
178
181
self ._proc = subprocess .Popen ([
179
182
self .PATH_SLAPD ,
180
- "-f" , self ._slapd_conf ,
181
- "-h" , self .ldap_uri ,
182
- "-d" , "0" ,
183
+ '-f' , self ._slapd_conf ,
184
+ '-h' , '%s' % ' ' . join (( self .ldap_uri , self . ldapi_uri )) ,
185
+ '-d' , '0' ,
183
186
])
184
187
185
188
def _wait_for_slapd (self ):
@@ -263,7 +266,7 @@ def ldapwhoami(self, extra_args=None):
263
266
"-x" ,
264
267
"-D" , self .root_dn ,
265
268
"-w" , self .root_pw ,
266
- "-H" , self .ldap_uri
269
+ "-H" , self .ldapi_uri
267
270
] + extra_args ,
268
271
stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
269
272
)
@@ -280,7 +283,7 @@ def ldapadd(self, ldif, extra_args=None):
280
283
"-x" ,
281
284
"-D" , self .root_dn ,
282
285
"-w" , self .root_pw ,
283
- "-H" , self .ldap_uri
286
+ "-H" , self .ldapi_uri
284
287
] + extra_args ,
285
288
stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
286
289
)
0 commit comments