annotate MoinMoin/_tests/ldap_testbase.py @ 4617:8a3c0c726d66

remove some references to py 2.3/2.4 - 2.4 is the minimum now anyway
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 01 Mar 2009 04:11:08 +0100
parents 07862b0663fd
children
rev   line source
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 LDAPTestBase: LDAP testing support for py.test based unit tests
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 Features
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 --------
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 * setup_class
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 * automatic creation of a temporary LDAP server environment
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 * automatic creation of a LDAP server process (slapd)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 * teardown_class
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 * LDAP server process will be killed and termination will be waited for
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 * temporary LDAP environment will be removed
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 Usage
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 -----
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 Write your own test class and derive from LDAPTestBase:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 class TestLdap(LDAPTestBase):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 def testFunction(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 server_url = self.ldap_env.slapd.url
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24 lo = ldap.initialize(server_url)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 lo.simple_bind_s('', '')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27 Notes
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 -----
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 On Ubuntu 8.04 there is apparmor imposing some restrictions on /usr/sbin/slapd,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31 so you need to disable apparmor by invoking this as root:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 # /etc/init.d/apparmor stop
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 @copyright: 2008 by Thomas Waldmann
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 @license: GNU GPL, see COPYING for details.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
39 SLAPD_EXECUTABLE = 'slapd' # filename of LDAP server executable - if it is not
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
40 # in your PATH, you have to give full path/filename.
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
41
4249
b8ea98d74d8d Fixed LDAP auth: Use of MoinMoin.auth.handle_login instead of request.handle_auth / SLAPD without cleartext-support breaks tests
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3661
diff changeset
42 import os, shutil, tempfile, time, base64, md5
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 from StringIO import StringIO
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 import signal
4617
8a3c0c726d66 remove some references to py 2.3/2.4 - 2.4 is the minimum now anyway
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4326
diff changeset
45 import subprocess
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
46
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
47 try:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
48 import ldap, ldif, ldap.modlist # needs python-ldap
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
49 except ImportError:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
50 ldap = None
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
51
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
52
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
53 def check_environ():
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
54 """ Check the system environment whether we are able to run.
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
55 Either return some failure reason if we can't or None if everything
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
56 looks OK.
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
57 """
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
58 if ldap is None:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
59 return "You need python-ldap installed to use ldap_testbase."
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
60 slapd = False
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
61 try:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
62 p = subprocess.Popen([SLAPD_EXECUTABLE, '-V'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
63 pid = p.pid
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
64 rc = p.wait()
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
65 if pid and rc == 1:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
66 slapd = True # it works
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
67 except OSError, err:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
68 import errno
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
69 if not (err.errno == errno.ENOENT or
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
70 (err.errno == 3 and os.name == 'nt')):
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
71 raise
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
72 if not slapd:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
73 return "Can't start %s (see SLAPD_EXECUTABLE)." % SLAPD_EXECUTABLE
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
74 return None
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
75
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77 class Slapd(object):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 """ Manage a slapd process for testing purposes """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 def __init__(self,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 config=None, # config filename for -f
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
81 executable=SLAPD_EXECUTABLE,
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 debug_flags='', # None, # for -d stats,acl,args,trace,sync,config
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 proto='ldap', ip='127.0.0.1', port=3890, # use -h proto://ip:port
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84 service_name='' # defaults to -n executable:port, use None to not use -n
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 ):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 self.executable = executable
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87 self.config = config
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 self.debug_flags = debug_flags
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 self.proto = proto
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 self.ip = ip
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 self.port = port
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 self.url = '%s://%s:%d' % (proto, ip, port) # can be used for ldap.initialize() call
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 if service_name == '':
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 self.service_name = '%s:%d' % (executable, port)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 else:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 self.service_name = service_name
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 def start(self, timeout=0):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 """ start a slapd process and optionally wait up to timeout seconds until it responds """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 args = [self.executable, '-h', self.url, ]
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 if self.config is not None:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 args.extend(['-f', self.config])
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103 if self.debug_flags is not None:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 args.extend(['-d', self.debug_flags])
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 if self.service_name:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106 args.extend(['-n', self.service_name])
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 self.process = subprocess.Popen(args)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 started = None
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109 if timeout:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 lo = ldap.initialize(self.url)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 ldap.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3) # ldap v2 is outdated
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 started = False
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 wait_until = time.time() + timeout
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 while time.time() < wait_until:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 try:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 lo.simple_bind_s('', '')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 started = True
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 except ldap.SERVER_DOWN, err:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 time.sleep(0.1)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120 else:
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 break
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122 return started
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 def stop(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 """ stop this slapd process and wait until it has terminated """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 pid = self.process.pid
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 os.kill(pid, signal.SIGTERM)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 os.waitpid(pid, 0)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 class LdapEnvironment(object):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 """ Manage a (temporary) environment for running a slapd in it """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 # default DB_CONFIG bdb configuration file contents
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 DB_CONFIG = """\
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136 # STRANGE: if i use those settings, after the test slapd goes to 100% and doesn't terminate on SIGTERM
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 # Set the database in memory cache size.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138 #set_cachesize 0 10000000 1
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 # Set log values.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141 #set_lg_regionmax 262144
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 #set_lg_bsize 262144
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 #set_lg_max 10485760
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
145 #set_tas_spins 0
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 def __init__(self,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149 basedn,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150 rootdn, rootpw,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
151 instance=0, # use different values when running multiple LdapEnvironments
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
152 schema_dir='/etc/ldap/schema', # directory with schemas
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
153 coding='utf-8', # coding used for config files
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
154 timeout=10, # how long to wait for slapd starting [s]
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
155 ):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156 self.basedn = basedn
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
157 self.rootdn = rootdn
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
158 self.rootpw = rootpw
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159 self.instance = instance
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
160 self.schema_dir = schema_dir
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
161 self.coding = coding
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
162 self.ldap_dir = None
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
163 self.slapd_conf = None
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
164 self.timeout = timeout
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166 def create_env(self, slapd_config, db_config=DB_CONFIG):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
167 """ create a temporary LDAP server environment in a temp. directory,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168 including writing a slapd.conf (see configure_slapd) and a
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
169 DB_CONFIG there.
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171 # create directories
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 self.ldap_dir = tempfile.mkdtemp(prefix='LdapEnvironment-%d.' % self.instance)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 self.ldap_db_dir = os.path.join(self.ldap_dir, 'db')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174 os.mkdir(self.ldap_db_dir)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
176 # create DB_CONFIG for bdb backend
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 db_config_fname = os.path.join(self.ldap_db_dir, 'DB_CONFIG')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 f = open(db_config_fname, 'w')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 f.write(db_config)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 f.close()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
181
4249
b8ea98d74d8d Fixed LDAP auth: Use of MoinMoin.auth.handle_login instead of request.handle_auth / SLAPD without cleartext-support breaks tests
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3661
diff changeset
182 rootpw = '{MD5}' + base64.b64encode(md5.new(self.rootpw).digest())
b8ea98d74d8d Fixed LDAP auth: Use of MoinMoin.auth.handle_login instead of request.handle_auth / SLAPD without cleartext-support breaks tests
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3661
diff changeset
183
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 # create slapd.conf from content template in slapd_config
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
185 slapd_config = slapd_config % {
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
186 'ldap_dir': self.ldap_dir,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187 'ldap_db_dir': self.ldap_db_dir,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 'schema_dir': self.schema_dir,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
189 'basedn': self.basedn,
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190 'rootdn': self.rootdn,
4249
b8ea98d74d8d Fixed LDAP auth: Use of MoinMoin.auth.handle_login instead of request.handle_auth / SLAPD without cleartext-support breaks tests
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3661
diff changeset
191 'rootpw': rootpw,
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192 }
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193 if isinstance(slapd_config, unicode):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
194 slapd_config = slapd_config.encode(self.coding)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
195 self.slapd_conf = os.path.join(self.ldap_dir, "slapd.conf")
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
196 f = open(self.slapd_conf, 'w')
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
197 f.write(slapd_config)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
198 f.close()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
199
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
200 def start_slapd(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
201 """ start a slapd and optionally wait until it talks with us """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
202 self.slapd = Slapd(config=self.slapd_conf, port=3890+self.instance)
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
203 started = self.slapd.start(timeout=self.timeout)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
204 return started
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
205
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
206 def load_directory(self, ldif_content):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
207 """ load the directory with the ldif_content (str) """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
208 lo = ldap.initialize(self.slapd.url)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
209 ldap.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3) # ldap v2 is outdated
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
210 lo.simple_bind_s(self.rootdn, self.rootpw)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
211
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
212 class LDIFLoader(ldif.LDIFParser):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 def handle(self, dn, entry):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214 lo.add_s(dn, ldap.modlist.addModlist(entry))
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
215
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
216 loader = LDIFLoader(StringIO(ldif_content))
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217 loader.parse()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
219 def stop_slapd(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220 """ stop a slapd """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
221 self.slapd.stop()
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223 def destroy_env(self):
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224 """ remove the temporary LDAP server environment """
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 shutil.rmtree(self.ldap_dir)
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
226
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
227 try:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
228 import py.test
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
229
3661
2d5a325ae247 ldap tests: rename base class so py.test doesn't find it, skip tests if slapd is not started
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3651
diff changeset
230 class LDAPTstBase:
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
231 """ Test base class for py.test based tests which need a LDAP server to talk to.
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
232
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
233 Inherit your test class from this base class to test LDAP stuff.
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
234 """
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
235
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
236 # You MUST define these in your derived class:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
237 slapd_config = None # a string with your slapd.conf template
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
238 ldif_content = None # a string with your ldif contents
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
239 basedn = None # your base DN
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
240 rootdn = None # root DN
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
241 rootpw = None # root password
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
243 def setup_class(self):
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
244 """ Create LDAP server environment, start slapd """
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
245 self.ldap_env = LdapEnvironment(self.basedn, self.rootdn, self.rootpw)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
246 self.ldap_env.create_env(slapd_config=self.slapd_config)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
247 started = self.ldap_env.start_slapd()
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
248 if not started:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
249 py.test.skip("Failed to start %s process, please see your syslog / log files"
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
250 " (and check if stopping apparmor helps, in case you use it)." % SLAPD_EXECUTABLE)
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
251 self.ldap_env.load_directory(ldif_content=self.ldif_content)
3650
23851c20e53f add ldap testing framework, add ldap_login tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
252
3651
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
253 def teardown_class(self):
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
254 """ Stop slapd, remove LDAP server environment """
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
255 self.ldap_env.stop_slapd()
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
256 self.ldap_env.destroy_env()
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
257
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
258 except ImportError:
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
259 pass # obviously py.test not in use
df024fd0a129 LDAP tests: add checks for the environment needed to run the tests. skip test with reason if environment is unsuitable.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3650
diff changeset
260