Debian Codegraph @

test/testMockASyncStrategy.py

raw
1 """
2 """
3
4 # Created on 2015.02.3
5 #
6 # Author: Giovanni Cannata
7 #
8 # Copyright 2015 - 2020 Giovanni Cannata
9 #
10 # This file is part of ldap3.
11 #
12 # ldap3 is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU Lesser General Public License as published
14 # by the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
16 #
17 # ldap3 is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU Lesser General Public License for more details.
21 #
22 # You should have received a copy of the GNU Lesser General Public License
23 # along with ldap3 in the COPYING and COPYING.LESSER files.
24 # If not, see <http://www.gnu.org/licenses/>.
25
26
27 import unittest
28
29 from ldap3 import Server, Connection, MOCK_ASYNC, MODIFY_ADD, MODIFY_REPLACE, MODIFY_DELETE, OFFLINE_EDIR_9_1_4, BASE, LEVEL, SUBTREE, AUTO_BIND_NO_TLS, NONE
30 from ldap3.core.exceptions import LDAPInvalidCredentialsResult, LDAPNoSuchObjectResult
31 from ldap3.protocol.rfc4512 import SchemaInfo, DsaInfo
32 from ldap3.protocol.schemas.edir914 import edir_9_1_4_schema, edir_9_1_4_dsa_info
33 from test.config import random_id
34
35 testcase_id = ''
36
37
38 class Test(unittest.TestCase):
39 def setUp(self):
40 global testcase_id
41 testcase_id = random_id()
42 # The mock server can be defined in two different ways, so tests are duplicated, connection_3 is without schema
43 schema = SchemaInfo.from_json(edir_9_1_4_schema)
44 info = DsaInfo.from_json(edir_9_1_4_dsa_info, schema)
45 server_1 = Server.from_definition('MockSyncServer', info, schema)
46 self.connection_1 = Connection(server_1, user='cn=user1,ou=test,o=lab', password='test1111', client_strategy=MOCK_ASYNC)
47 self.connection_1b = Connection(server_1, user='cn=user1,ou=test,o=lab', password='test1111', client_strategy=MOCK_ASYNC)
48 self.connection_1c = Connection(server_1, user='cn=user1,ou=test,o=lab', password='test1111', client_strategy=MOCK_ASYNC, raise_exceptions=True)
49 server_2 = Server('dummy', get_info=OFFLINE_EDIR_9_1_4)
50 self.connection_2 = Connection(server_2, user='cn=user2,ou=test,o=lab', password='test2222', client_strategy=MOCK_ASYNC)
51 self.connection_2b = Connection(server_2, user='cn=user2,ou=test,o=lab', password='test2222', client_strategy=MOCK_ASYNC)
52 self.connection_2c = Connection(server_2, user='cn=user2,ou=test,o=lab', password='test2222', client_strategy=MOCK_ASYNC, raise_exceptions=True)
53 server_3 = Server('dummy') # no schema
54 self.connection_3 = Connection(server_3, user='cn=user3,ou=test,o=lab', password='test3333', client_strategy=MOCK_ASYNC)
55 self.connection_3b = Connection(server_3, user='cn=user3,ou=test,o=lab', password='test3333', client_strategy=MOCK_ASYNC)
56 self.connection_3c = Connection(server_3, user='cn=user3,ou=test,o=lab', password='test3333', client_strategy=MOCK_ASYNC, raise_exceptions=True)
57 # creates fixtures
58 self.connection_1.strategy.add_entry('cn=user0,o=lab', {'userPassword': 'test0000', 'sn': 'user0_sn', 'revision': 0})
59 self.connection_2.strategy.add_entry('cn=user0,o=lab', {'userPassword': 'test0000', 'sn': 'user0_sn', 'revision': 0})
60 self.connection_3.strategy.add_entry('cn=user0,o=lab', {'userPassword': 'test0000', 'sn': 'user0_sn', 'revision': 0})
61 self.connection_1.strategy.add_entry('cn=user1,ou=test,o=lab', {'userPassword': 'test1111', 'sn': 'user1_sn', 'revision': 1})
62 self.connection_2.strategy.add_entry('cn=user1,ou=test,o=lab', {'userPassword': 'test1111', 'sn': 'user1_sn', 'revision': 1})
63 self.connection_3.strategy.add_entry('cn=user1,ou=test,o=lab', {'userPassword': 'test1111', 'sn': 'user1_sn', 'revision': 1})
64 self.connection_1.strategy.add_entry('cn=user2,ou=test,o=lab', {'userPassword': 'test2222', 'sn': 'user2_sn', 'revision': 2})
65 self.connection_2.strategy.add_entry('cn=user2,ou=test,o=lab', {'userPassword': 'test2222', 'sn': 'user2_sn', 'revision': 2})
66 self.connection_3.strategy.add_entry('cn=user2,ou=test,o=lab', {'userPassword': 'test2222', 'sn': 'user2_sn', 'revision': 2})
67 self.connection_1.strategy.add_entry('cn=user3,ou=test,o=lab', {'userPassword': 'test3333', 'sn': 'user3_sn', 'revision': 3})
68 self.connection_2.strategy.add_entry('cn=user3,ou=test,o=lab', {'userPassword': 'test3333', 'sn': 'user3_sn', 'revision': 3})
69 self.connection_3.strategy.add_entry('cn=user3,ou=test,o=lab', {'userPassword': 'test3333', 'sn': 'user3_sn', 'revision': 3})
70 self.connection_1.strategy.add_entry('cn=user4,ou=test,o=lab', {'userPassword': 'test4444', 'sn': 'user4_sn', 'revision': 4, 'title': ['title1', 'title2', 'title3']})
71 self.connection_2.strategy.add_entry('cn=user4,ou=test,o=lab', {'userPassword': 'test4444', 'sn': 'user4_sn', 'revision': 4, 'title': ['title1', 'title2', 'title3']})
72 self.connection_3.strategy.add_entry('cn=user4,ou=test,o=lab', {'userPassword': 'test4444', 'sn': 'user4_sn', 'revision': 4, 'title': ['title1', 'title2', 'title3']})
73
74 def tearDown(self):
75 self.connection_1.unbind()
76 self.assertFalse(self.connection_1.bound)
77 self.connection_2.unbind()
78 self.assertFalse(self.connection_2.bound)
79 self.connection_3.unbind()
80 self.assertFalse(self.connection_3.bound)
81
82 def test_open_1(self):
83 self.connection_1.open()
84 self.assertFalse(self.connection_1.closed)
85
86 def test_open_2(self):
87 self.connection_2.open()
88 self.assertFalse(self.connection_2.closed)
89
90 def test_open_3(self):
91 self.connection_3.open()
92 self.assertFalse(self.connection_3.closed)
93
94 def test_bind_1(self):
95 self.connection_1.open()
96 self.connection_1.bind()
97 self.assertTrue(self.connection_1.bound)
98
99 def test_bind_2(self):
100 self.connection_2.open()
101 self.connection_2.bind()
102 self.assertTrue(self.connection_2.bound)
103
104 def test_bind_3(self):
105 self.connection_3.open()
106 self.connection_3.bind()
107 self.assertTrue(self.connection_3.bound)
108
109 def test_invalid_bind_1(self):
110 self.connection_1.password = 'wrong'
111 self.connection_1.open()
112 self.connection_1.bind()
113 self.assertFalse(self.connection_1.bound)
114
115 def test_invalid_bind_2(self):
116 self.connection_2.password = 'wrong'
117 self.connection_2.open()
118 self.connection_2.bind()
119 self.assertFalse(self.connection_2.bound)
120
121 def test_invalid_bind_3(self):
122 self.connection_3.password = 'wrong'
123 self.connection_3.open()
124 self.connection_3.bind()
125 self.assertFalse(self.connection_3.bound)
126
127 def test_invalid_bind_exception_1(self):
128 self.connection_1c.password = 'wrong'
129 self.connection_1c.open()
130 try:
131 self.connection_1c.bind()
132 self.fail('exception not raised')
133 except LDAPInvalidCredentialsResult:
134 pass
135
136 def test_invalid_bind_exception_2(self):
137 self.connection_2c.password = 'wrong'
138 self.connection_2c.open()
139 try:
140 self.connection_2c.bind()
141 self.fail('exception not raised')
142 except LDAPInvalidCredentialsResult:
143 pass
144
145 def test_invalid_bind_exception_3(self):
146 self.connection_3c.password = 'wrong'
147 self.connection_3c.open()
148 try:
149 self.connection_3c.bind()
150 self.fail('exception not raised')
151 except LDAPInvalidCredentialsResult:
152 pass
153
154 def test_unbind_1(self):
155 self.connection_1.open()
156 self.assertFalse(self.connection_1.closed)
157 self.connection_1.bind()
158 self.assertTrue(self.connection_1.bound)
159 self.connection_1.unbind()
160 self.assertFalse(self.connection_1.bound)
161 self.assertTrue(self.connection_1.closed)
162
163 def test_unbind_2(self):
164 self.connection_2.open()
165 self.assertFalse(self.connection_2.closed)
166 self.connection_2.bind()
167 self.assertTrue(self.connection_2.bound)
168 self.connection_2.unbind()
169 self.assertFalse(self.connection_2.bound)
170 self.assertTrue(self.connection_2.closed)
171
172 def test_unbind_3(self):
173 self.connection_3.open()
174 self.assertFalse(self.connection_3.closed)
175 self.connection_3.bind()
176 self.assertTrue(self.connection_3.bound)
177 self.connection_3.unbind()
178 self.assertFalse(self.connection_3.bound)
179 self.assertTrue(self.connection_3.closed)
180
181 def test_add_user_1(self):
182 self.connection_1.strategy.add_entry('cn=user4,ou=test,o=lab', {'userPassword': 'test4444'})
183 self.connection_1.rebind('cn=user4,ou=test,o=lab', 'test4444')
184 self.assertTrue(self.connection_1.bound)
185
186 def test_add_user_2(self):
187 self.connection_2.strategy.add_entry('cn=user4,ou=test,o=lab', {'userPassword': 'test4444'})
188 self.connection_2.rebind('cn=user4,ou=test,o=lab', 'test4444')
189 self.assertTrue(self.connection_2.bound)
190
191 def test_add_user_3(self):
192 self.connection_3.strategy.add_entry('cn=user4,ou=test,o=lab', {'userPassword': 'test4444'})
193 self.connection_3.rebind('cn=user4,ou=test,o=lab', 'test4444')
194 self.assertTrue(self.connection_3.bound)
195
196 def test_remove_user_1(self):
197 self.connection_1.strategy.remove_entry('cn=user2,ou=test,o=lab')
198 self.connection_1.bind()
199 self.assertTrue(self.connection_1.bound)
200 self.connection_1.rebind('cn=user2,ou=test,o=lab', 'test9876')
201 self.assertFalse(self.connection_1.bound)
202
203 def test_remove_user_2(self):
204 self.connection_2.strategy.remove_entry('cn=user1,ou=test,o=lab')
205 self.connection_2.bind()
206 self.assertTrue(self.connection_2.bound)
207 self.connection_2.rebind('cn=user1,ou=test,o=lab', 'test9876')
208 self.assertFalse(self.connection_2.bound)
209
210 def test_remove_user_3(self):
211 self.connection_3.strategy.remove_entry('cn=user1,ou=test,o=lab')
212 self.connection_3.bind()
213 self.assertTrue(self.connection_3.bound)
214 self.connection_3.rebind('cn=user1,ou=test,o=lab', 'test1111')
215 self.assertFalse(self.connection_3.bound)
216
217 def test_delete_1(self):
218 self.connection_1.bind()
219 result = self.connection_1.delete('cn=user1,ou=test,o=lab')
220 if not self.connection_1.strategy.sync:
221 _, result = self.connection_1.get_response(result)
222 else:
223 result = self.connection_1.result
224
225 self.assertTrue(result['description'], 'success')
226 self.assertTrue('cn=user1,ou=test,o=lab' not in self.connection_1.strategy.entries)
227
228 def test_delete_2(self):
229 self.connection_2.bind()
230 result = self.connection_2.delete('cn=user2,ou=test,o=lab')
231 if not self.connection_2.strategy.sync:
232 _, result = self.connection_2.get_response(result)
233 else:
234 result = self.connection_2.result
235 self.assertTrue(['description'], 'success')
236 self.assertTrue('cn=user2,ou=test,o=lab' not in self.connection_2.strategy.entries)
237
238 def test_delete_3(self):
239 self.connection_3.bind()
240 result = self.connection_3.delete('cn=user3,ou=test,o=lab')
241 if not self.connection_3.strategy.sync:
242 _, result = self.connection_3.get_response(result)
243 else:
244 result = self.connection_3.result
245 self.assertTrue(result['description'], 'success')
246 self.assertTrue('cn=user3,ou=test,o=lab' not in self.connection_3.strategy.entries)
247
248 def test_add_entry_1(self):
249 dn = 'cn=user5,ou=test,o=lab'
250 self.connection_1.bind()
251 result = self.connection_1.add(dn, ['inetOrgPerson', 'top'], {'sn': 'user5_sn'})
252 if not self.connection_1.strategy.sync:
253 _, result = self.connection_1.get_response(result)
254 else:
255 result = self.connection_1.result
256 self.assertTrue(result['description'], 'success')
257 self.assertTrue(dn in self.connection_1.strategy.entries)
258 self.connection_1b.bind()
259 self.assertTrue(dn in self.connection_1b.strategy.entries)
260
261 def test_add_entry_2(self):
262 dn = 'cn=user5,ou=test,o=lab'
263 self.connection_2.bind()
264 result = self.connection_2.add(dn, ['inetOrgPerson', 'top'], {'sn': 'user5_sn'})
265 if not self.connection_2.strategy.sync:
266 _, result = self.connection_2.get_response(result)
267 else:
268 result = self.connection_2.result
269 self.assertTrue(result['description'], 'success')
270 self.assertTrue(dn in self.connection_2.strategy.entries)
271 self.connection_2b.bind()
272 self.assertTrue(dn in self.connection_2b.strategy.entries)
273
274 def test_add_entry_3(self):
275 dn = 'cn=user5,ou=test,o=lab'
276 self.connection_3.bind()
277 result = self.connection_3.add(dn, ['inetOrgPerson', 'top'], {'sn': 'user5_sn'})
278 if not self.connection_3.strategy.sync:
279 _, result = self.connection_3.get_response(result)
280 else:
281 result = self.connection_3.result
282 self.assertTrue(result['description'], 'success')
283 self.assertTrue(dn in self.connection_3.strategy.entries)
284 self.connection_3b.bind()
285 self.assertTrue(dn in self.connection_3b.strategy.entries)
286
287 def test_add_entry_already_exists_1(self):
288 dn = 'cn=user5,ou=test,o=lab'
289 self.connection_1.bind()
290 self.connection_1.strategy.add_entry(dn, {'objectClass': ['inetOrgPerson', 'top'], 'sn': 'user5_sn'})
291 result = self.connection_1.add(dn, ['inetOrgPerson', 'top'], {'sn': 'user5_sn'})
292 if not self.connection_1.strategy.sync:
293 _, result = self.connection_1.get_response(result)
294 else:
295 result = self.connection_1.result
296 self.assertEqual(result['description'], 'entryAlreadyExists')
297
298 def test_add_entry_already_exists_2(self):
299 dn = 'cn=user5,ou=test,o=lab'
300 self.connection_2.bind()
301 self.connection_2.strategy.add_entry(dn, {'objectClass': ['inetOrgPerson', 'top'], 'sn': 'user5_sn'})
302 result = self.connection_2.add(dn, ['inetOrgPerson', 'top'], {'sn': 'user5_sn'})
303 if not self.connection_2.strategy.sync:
304 _, result = self.connection_2.get_response(result)
305 else:
306 result = self.connection_2.result
307 self.assertEqual(result['description'], 'entryAlreadyExists')
308
309 def test_add_entry_already_exists_3(self):
310 dn = 'cn=user5,ou=test,o=lab'
311 self.connection_3.bind()
312 self.connection_3.strategy.add_entry(dn, {'objectClass': ['inetOrgPerson', 'top'], 'sn': 'user5_sn'})
313 result = self.connection_3.add(dn, ['inetOrgPerson', 'top'], {'sn': 'user5_sn'})
314 if not self.connection_3.strategy.sync:
315 _, result = self.connection_3.get_response(result)
316 else:
317 result = self.connection_3.result
318 self.assertEqual(result['description'], 'entryAlreadyExists')
319
320 def test_delete_entry_nonexisting_1(self):
321 dn = 'cn=user5,ou=test,o=lab'
322 self.connection_1.bind()
323 self.assertTrue(dn not in self.connection_1.strategy.entries)
324 result = self.connection_1.delete(dn)
325 if not self.connection_1.strategy.sync:
326 _, result = self.connection_1.get_response(result)
327 else:
328 result = self.connection_1.result
329 self.assertEqual(result['description'], 'noSuchObject')
330
331 def test_delete_entry_nonexisting_2(self):
332 dn = 'cn=user5,ou=test,o=lab'
333 self.connection_2.bind()
334 self.assertTrue(dn not in self.connection_2.strategy.entries)
335 result = self.connection_2.delete(dn)
336 if not self.connection_2.strategy.sync:
337 _, result = self.connection_2.get_response(result)
338 else:
339 result = self.connection_2.result
340 self.assertEqual(result['description'], 'noSuchObject')
341
342 def test_delete_entry_nonexisting_3(self):
343 dn = 'cn=user5,ou=test,o=lab'
344 self.connection_3.bind()
345 self.assertTrue(dn not in self.connection_3.strategy.entries)
346 result = self.connection_3.delete(dn)
347 if not self.connection_3.strategy.sync:
348 _, result = self.connection_3.get_response(result)
349 else:
350 result = self.connection_3.result
351 self.assertEqual(result['description'], 'noSuchObject')
352
353 def test_compare_entry_1(self):
354 dn = 'cn=user4,ou=test,o=lab'
355 self.connection_1.bind()
356 result = self.connection_1.compare(dn, 'sn', 'user4_sn')
357 if not self.connection_1.strategy.sync:
358 _, result = self.connection_1.get_response(result)
359 else:
360 result = self.connection_1.result
361 self.assertTrue(result['description'], 'compareTrue')
362 result = self.connection_1.compare(dn, 'sn', 'bad_sn')
363 if not self.connection_1.strategy.sync:
364 _, result = self.connection_1.get_response(result)
365 else:
366 result = self.connection_1.result
367 self.assertTrue(result['description'], 'compareFalse')
368
369 def test_compare_entry_2(self):
370 dn = 'cn=user4,ou=test,o=lab'
371 self.connection_2.bind()
372 result = self.connection_2.compare(dn, 'sn', 'user4_sn')
373 if not self.connection_2.strategy.sync:
374 _, result = self.connection_2.get_response(result)
375 else:
376 result = self.connection_2.result
377 self.assertTrue(result['description'], 'compareTrue')
378 result = self.connection_2.compare(dn, 'sn', 'bad_sn')
379 if not self.connection_2.strategy.sync:
380 _, result = self.connection_2.get_response(result)
381 else:
382 result = self.connection_2.result
383 self.assertTrue(result['description'], 'compareFalse')
384
385 def test_compare_entry_3(self):
386 dn = 'cn=user4,ou=test,o=lab'
387 self.connection_3.bind()
388 result = self.connection_3.compare(dn, 'sn', 'user4_sn')
389 if not self.connection_3.strategy.sync:
390 _, result = self.connection_3.get_response(result)
391 else:
392 result = self.connection_3.result
393 self.assertTrue(result['description'], 'compareTrue')
394 result = self.connection_3.compare(dn, 'sn', 'bad_sn')
395 if not self.connection_3.strategy.sync:
396 _, result = self.connection_3.get_response(result)
397 else:
398 result = self.connection_3.result
399 self.assertTrue(result['description'], 'compareFalse')
400
401 def test_move_dn_1(self):
402 dn = 'cn=user4,ou=test,o=lab'
403 self.connection_1.bind()
404 result = self.connection_1.modify_dn(dn, relative_dn='cn=user4', new_superior='ou=moved,o=lab')
405 if not self.connection_1.strategy.sync:
406 _, result = self.connection_1.get_response(result)
407 else:
408 result = self.connection_1.result
409 self.assertTrue(result['description'], 'success')
410 self.assertTrue('cn=user4,ou=moved,o=lab' in self.connection_1.strategy.entries)
411 self.assertFalse(dn in self.connection_1.strategy.entries)
412
413 def test_move_dn_2(self):
414 dn = 'cn=user4,ou=test,o=lab'
415 self.connection_2.bind()
416 result = self.connection_2.modify_dn(dn, relative_dn='cn=user4', new_superior='ou=moved,o=lab')
417 if not self.connection_2.strategy.sync:
418 _, result = self.connection_2.get_response(result)
419 else:
420 result = self.connection_2.result
421 self.assertTrue(result['description'], 'success')
422 self.assertTrue('cn=user4,ou=moved,o=lab' in self.connection_2.strategy.entries)
423 self.assertFalse(dn in self.connection_2.strategy.entries)
424
425 def test_move_dn_3(self):
426 dn = 'cn=user4,ou=test,o=lab'
427 self.connection_3.bind()
428 result = self.connection_3.modify_dn(dn, relative_dn='cn=user4', new_superior='ou=moved,o=lab')
429 if not self.connection_3.strategy.sync:
430 _, result = self.connection_3.get_response(result)
431 else:
432 result = self.connection_3.result
433 self.assertTrue(result['description'], 'success')
434 self.assertTrue('cn=user4,ou=moved,o=lab' in self.connection_3.strategy.entries)
435 self.assertFalse(dn in self.connection_3.strategy.entries)
436
437 def test_rename_dn_1(self):
438 dn = 'cn=user4,ou=test,o=lab'
439 self.connection_1.bind()
440 result = self.connection_1.modify_dn(dn, relative_dn='cn=user_renamed')
441 if not self.connection_1.strategy.sync:
442 _, result = self.connection_1.get_response(result)
443 else:
444 result = self.connection_1.result
445 self.assertTrue(result['description'], 'success')
446 self.assertTrue('cn=user_renamed,ou=test,o=lab' in self.connection_1.strategy.entries)
447 self.assertFalse(dn in self.connection_1.strategy.entries)
448
449 def test_rename_dn_2(self):
450 dn = 'cn=user4,ou=test,o=lab'
451 self.connection_2.bind()
452 result = self.connection_2.modify_dn(dn, relative_dn='cn=user_renamed')
453 if not self.connection_2.strategy.sync:
454 _, result = self.connection_2.get_response(result)
455 else:
456 result = self.connection_2.result
457 self.assertTrue(result['description'], 'success')
458 self.assertTrue('cn=user_renamed,ou=test,o=lab' in self.connection_2.strategy.entries)
459 self.assertFalse(dn in self.connection_2.strategy.entries)
460
461 def test_rename_dn_3(self):
462 dn = 'cn=user4,ou=test,o=lab'
463 self.connection_3.bind()
464 result = self.connection_3.modify_dn(dn, relative_dn='cn=user_renamed')
465 if not self.connection_3.strategy.sync:
466 _, result = self.connection_3.get_response(result)
467 else:
468 result = self.connection_3.result
469 self.assertTrue(result['description'], 'success')
470 self.assertTrue('cn=user_renamed,ou=test,o=lab' in self.connection_3.strategy.entries)
471 self.assertFalse(dn in self.connection_3.strategy.entries)
472
473 def test_modify_add_existing_singlevalue_1(self):
474 dn = 'cn=user4,ou=test,o=lab'
475 self.connection_1.bind()
476 result = self.connection_1.modify(dn, {'sn': (MODIFY_ADD, ['sn_added'])})
477 if not self.connection_1.strategy.sync:
478 _, result = self.connection_1.get_response(result)
479 else:
480 result = self.connection_1.result
481 self.assertTrue(result['description'], 'success')
482 self.assertTrue(b'sn_added' in self.connection_1.strategy.entries[dn]['sn'])
483
484 def test_modify_add_existing_singlevalue_2(self):
485 dn = 'cn=user4,ou=test,o=lab'
486 self.connection_2.bind()
487 result = self.connection_2.modify(dn, {'sn': (MODIFY_ADD, ['sn_added'])})
488 if not self.connection_2.strategy.sync:
489 _, result = self.connection_2.get_response(result)
490 else:
491 result = self.connection_2.result
492 self.assertTrue(result['description'], 'success')
493 self.assertTrue(b'sn_added' in self.connection_2.strategy.entries[dn]['sn'])
494
495 def test_modify_add_existing_singlevalue_3(self):
496 dn = 'cn=user4,ou=test,o=lab'
497 self.connection_3.bind()
498 result = self.connection_3.modify(dn, {'sn': (MODIFY_ADD, ['sn_added'])})
499 if not self.connection_3.strategy.sync:
500 _, result = self.connection_3.get_response(result)
501 else:
502 result = self.connection_3.result
503 self.assertTrue(result['description'], 'success')
504 self.assertTrue(b'sn_added' in self.connection_3.strategy.entries[dn]['sn'])
505
506 def test_modify_add_nonexisting_singlevalue_1(self):
507 dn = 'cn=user4,ou=test,o=lab'
508 self.connection_1.bind()
509 result = self.connection_1.modify(dn, {'title': (MODIFY_ADD, ['title_added'])})
510 if not self.connection_1.strategy.sync:
511 _, result = self.connection_1.get_response(result)
512 else:
513 result = self.connection_1.result
514 self.assertTrue(result['description'], 'success')
515 self.assertTrue(b'title_added' in self.connection_1.strategy.entries[dn]['title'])
516
517 def test_modify_add_nonexisting_singlevalue_2(self):
518 dn = 'cn=user4,ou=test,o=lab'
519 self.connection_2.bind()
520 result = self.connection_2.modify(dn, {'title': (MODIFY_ADD, ['title_added'])})
521 if not self.connection_2.strategy.sync:
522 _, result = self.connection_2.get_response(result)
523 else:
524 result = self.connection_2.result
525 self.assertTrue(result['description'], 'success')
526 self.assertTrue(b'title_added' in self.connection_2.strategy.entries[dn]['title'])
527
528 def test_modify_add_nonexisting_singlevalue_3(self):
529 dn = 'cn=user4,ou=test,o=lab'
530 self.connection_3.bind()
531 result = self.connection_3.modify(dn, {'title': (MODIFY_ADD, ['title_added'])})
532 if not self.connection_3.strategy.sync:
533 _, result = self.connection_3.get_response(result)
534 else:
535 result = self.connection_3.result
536 self.assertTrue(result['description'], 'success')
537 self.assertTrue(b'title_added' in self.connection_3.strategy.entries[dn]['title'])
538
539 def test_modify_add_existing_multivalue_1(self):
540 dn = 'cn=user4,ou=test,o=lab'
541 self.connection_1.bind()
542 result = self.connection_1.modify(dn, {'sn': (MODIFY_ADD, ['sn_added1', 'sn_added2'])})
543 if not self.connection_1.strategy.sync:
544 _, result = self.connection_1.get_response(result)
545 else:
546 result = self.connection_1.result
547 self.assertTrue(result['description'], 'success')
548 self.assertTrue(b'sn_added1' in self.connection_1.strategy.entries[dn]['sn'])
549 self.assertTrue(b'sn_added2' in self.connection_1.strategy.entries[dn]['sn'])
550
551 def test_modify_add_existing_multivalue_2(self):
552 dn = 'cn=user4,ou=test,o=lab'
553 self.connection_2.bind()
554 result = self.connection_2.modify(dn, {'sn': (MODIFY_ADD, ['sn_added1', 'sn_added2'])})
555 if not self.connection_2.strategy.sync:
556 _, result = self.connection_2.get_response(result)
557 else:
558 result = self.connection_2.result
559 self.assertTrue(result['description'], 'success')
560 self.assertTrue(b'sn_added1' in self.connection_2.strategy.entries[dn]['sn'])
561 self.assertTrue(b'sn_added2' in self.connection_2.strategy.entries[dn]['sn'])
562
563 def test_modify_add_existing_multivalue_3(self):
564 dn = 'cn=user4,ou=test,o=lab'
565 self.connection_3.bind()
566 result = self.connection_3.modify(dn, {'sn': (MODIFY_ADD, ['sn_added1', 'sn_added2'])})
567 if not self.connection_3.strategy.sync:
568 _, result = self.connection_3.get_response(result)
569 else:
570 result = self.connection_3.result
571 self.assertTrue(result['description'], 'success')
572 self.assertTrue(b'sn_added1' in self.connection_3.strategy.entries[dn]['sn'])
573 self.assertTrue(b'sn_added2' in self.connection_3.strategy.entries[dn]['sn'])
574
575 def test_modify_add_nonexisting_multivalue_1(self):
576 dn = 'cn=user4,ou=test,o=lab'
577 self.connection_1.bind()
578 result = self.connection_1.modify(dn, {'title': (MODIFY_ADD, ['title_added1', 'title_added2'])})
579 if not self.connection_1.strategy.sync:
580 _, result = self.connection_1.get_response(result)
581 else:
582 result = self.connection_1.result
583 self.assertTrue(result['description'], 'success')
584 self.assertTrue(b'title_added1' in self.connection_1.strategy.entries[dn]['title'])
585 self.assertTrue(b'title_added2' in self.connection_1.strategy.entries[dn]['title'])
586
587 def test_modify_add_nonexisting_multivalue_2(self):
588 dn = 'cn=user4,ou=test,o=lab'
589 self.connection_2.bind()
590 result = self.connection_2.modify(dn, {'title': (MODIFY_ADD, ['title_added1', 'title_added2'])})
591 if not self.connection_2.strategy.sync:
592 _, result = self.connection_2.get_response(result)
593 else:
594 result = self.connection_2.result
595 self.assertTrue(result['description'], 'success')
596 self.assertTrue(b'title_added1' in self.connection_2.strategy.entries[dn]['title'])
597 self.assertTrue(b'title_added2' in self.connection_2.strategy.entries[dn]['title'])
598
599 def test_modify_add_nonexisting_multivalue_3(self):
600 dn = 'cn=user4,ou=test,o=lab'
601 self.connection_3.bind()
602 result = self.connection_3.modify(dn, {'title': (MODIFY_ADD, ['title_added1', 'title_added2'])})
603 if not self.connection_3.strategy.sync:
604 _, result = self.connection_3.get_response(result)
605 else:
606 result = self.connection_3.result
607 self.assertTrue(result['description'], 'success')
608 self.assertTrue(b'title_added1' in self.connection_3.strategy.entries[dn]['title'])
609 self.assertTrue(b'title_added2' in self.connection_3.strategy.entries[dn]['title'])
610
611 def test_modify_delete_nonexisting_attribute_1(self):
612 dn = 'cn=user4,ou=test,o=lab'
613 self.connection_1.bind()
614 result = self.connection_1.modify(dn, {'initials': (MODIFY_DELETE, ['initials1', 'initials2'])})
615 if not self.connection_1.strategy.sync:
616 _, result = self.connection_1.get_response(result)
617 else:
618 result = self.connection_1.result
619 self.assertEqual(result['description'], 'noSuchAttribute')
620
621 def test_modify_delete_nonexisting_attribute_2(self):
622 dn = 'cn=user4,ou=test,o=lab'
623 self.connection_2.bind()
624 result = self.connection_2.modify(dn, {'initials': (MODIFY_DELETE, ['initials1', 'initials2'])})
625 if not self.connection_2.strategy.sync:
626 _, result = self.connection_2.get_response(result)
627 else:
628 result = self.connection_2.result
629 self.assertEqual(result['description'], 'noSuchAttribute')
630
631 def test_modify_delete_nonexisting_attribute_3(self):
632 dn = 'cn=user4,ou=test,o=lab'
633 self.connection_3.bind()
634 result = self.connection_3.modify(dn, {'initials': (MODIFY_DELETE, ['initials1', 'initials2'])})
635 if not self.connection_3.strategy.sync:
636 _, result = self.connection_3.get_response(result)
637 else:
638 result = self.connection_3.result
639 self.assertEqual(result['description'], 'noSuchAttribute')
640
641 def test_modify_delete_existing_singlevalue_1(self):
642 dn = 'cn=user4,ou=test,o=lab'
643 self.connection_1.bind()
644 result = self.connection_1.modify(dn, {'title': (MODIFY_DELETE, ['title1'])})
645 if not self.connection_1.strategy.sync:
646 _, result = self.connection_1.get_response(result)
647 else:
648 result = self.connection_1.result
649 self.assertEqual(result['description'], 'success')
650
651 def test_modify_delete_existing_singlevalue_2(self):
652 dn = 'cn=user4,ou=test,o=lab'
653 self.connection_2.bind()
654 result = self.connection_2.modify(dn, {'sn': (MODIFY_DELETE, ['user4_sn'])})
655 if not self.connection_2.strategy.sync:
656 _, result = self.connection_2.get_response(result)
657 else:
658 result = self.connection_2.result
659 self.assertEqual(result['description'], 'success')
660
661 def test_modify_delete_existing_singlevalue_3(self):
662 dn = 'cn=user4,ou=test,o=lab'
663 self.connection_3.bind()
664 result = self.connection_3.modify(dn, {'sn': (MODIFY_DELETE, ['user4_sn'])})
665 if not self.connection_3.strategy.sync:
666 _, result = self.connection_3.get_response(result)
667 else:
668 result = self.connection_3.result
669 self.assertEqual(result['description'], 'success')
670
671 def test_modify_delete_existing_multivalue_1(self):
672 dn = 'cn=user4,ou=test,o=lab'
673 self.connection_1.bind()
674 result = self.connection_1.modify(dn, {'title': (MODIFY_DELETE, ['title1', 'title2'])})
675 if not self.connection_1.strategy.sync:
676 _, result = self.connection_1.get_response(result)
677 else:
678 result = self.connection_1.result
679 self.assertEqual(result['description'], 'success')
680 self.assertTrue(self.connection_1.strategy.entries[dn]['title'] == [b'title3'])
681
682 def test_modify_delete_existing_multivalue_2(self):
683 dn = 'cn=user4,ou=test,o=lab'
684 self.connection_2.bind()
685 result = self.connection_2.modify(dn, {'title': (MODIFY_DELETE, ['title1', 'title2'])})
686 if not self.connection_2.strategy.sync:
687 _, result = self.connection_2.get_response(result)
688 else:
689 result = self.connection_2.result
690 self.assertEqual(result['description'], 'success')
691 self.assertTrue(self.connection_2.strategy.entries[dn]['title'] == [b'title3'])
692
693 def test_modify_delete_existing_multivalue_3(self):
694 dn = 'cn=user4,ou=test,o=lab'
695 self.connection_3.bind()
696 result = self.connection_3.modify(dn, {'title': (MODIFY_DELETE, ['title1', 'title2'])})
697 if not self.connection_3.strategy.sync:
698 _, result = self.connection_3.get_response(result)
699 else:
700 result = self.connection_3.result
701 self.assertEqual(result['description'], 'success')
702 self.assertTrue(self.connection_3.strategy.entries[dn]['title'] == [b'title3'])
703
704 def test_modify_replace_existing_singlevalue_1(self):
705 dn = 'cn=user4,ou=test,o=lab'
706 self.connection_1.bind()
707 result = self.connection_1.modify(dn, {'sn': (MODIFY_REPLACE, ['user_test_sn'])})
708 if not self.connection_1.strategy.sync:
709 _, result = self.connection_1.get_response(result)
710 else:
711 result = self.connection_1.result
712 self.assertEqual(result['description'], 'success')
713 self.assertTrue(b'user_test_sn' in self.connection_1.strategy.entries[dn]['sn'])
714 self.assertEqual(len(self.connection_1.strategy.entries[dn]['sn']), 1)
715
716 def test_modify_replace_existing_singlevalue_2(self):
717 dn = 'cn=user4,ou=test,o=lab'
718 self.connection_2.bind()
719 result = self.connection_2.modify(dn, {'sn': (MODIFY_REPLACE, ['user_test_sn'])})
720 if not self.connection_2.strategy.sync:
721 _, result = self.connection_2.get_response(result)
722 else:
723 result = self.connection_2.result
724 self.assertEqual(result['description'], 'success')
725 self.assertTrue(b'user_test_sn' in self.connection_2.strategy.entries[dn]['sn'])
726 self.assertEqual(len(self.connection_2.strategy.entries[dn]['sn']), 1)
727
728 def test_modify_replace_existing_singlevalue_3(self):
729 dn = 'cn=user4,ou=test,o=lab'
730 self.connection_3.bind()
731 result = self.connection_3.modify(dn, {'sn': (MODIFY_REPLACE, ['user_test_sn'])})
732 if not self.connection_3.strategy.sync:
733 _, result = self.connection_3.get_response(result)
734 else:
735 result = self.connection_3.result
736 self.assertEqual(result['description'], 'success')
737 self.assertTrue(b'user_test_sn' in self.connection_3.strategy.entries[dn]['sn'])
738 self.assertEqual(len(self.connection_3.strategy.entries[dn]['sn']), 1)
739
740 def test_modify_replace_existing_multivalue_1(self):
741 dn = 'cn=user4,ou=test,o=lab'
742 self.connection_1.bind()
743 result = self.connection_1.modify(dn, {'title': (MODIFY_REPLACE, ['title4', 'title5'])})
744 if not self.connection_1.strategy.sync:
745 _, result = self.connection_1.get_response(result)
746 else:
747 result = self.connection_1.result
748 self.assertEqual(result['description'], 'success')
749 self.assertFalse(b'title1' in self.connection_1.strategy.entries[dn]['title'])
750 self.assertFalse(b'title2' in self.connection_1.strategy.entries[dn]['title'])
751 self.assertFalse(b'title3' in self.connection_1.strategy.entries[dn]['title'])
752 self.assertTrue(b'title4' in self.connection_1.strategy.entries[dn]['title'])
753 self.assertTrue(b'title5' in self.connection_1.strategy.entries[dn]['title'])
754 self.assertEqual(len(self.connection_1.strategy.entries[dn]['title']), 2)
755
756 def test_modify_replace_existing_multivalue_2(self):
757 dn = 'cn=user4,ou=test,o=lab'
758 self.connection_2.bind()
759 result = self.connection_2.modify(dn, {'title': (MODIFY_REPLACE, ['title4', 'title5'])})
760 if not self.connection_2.strategy.sync:
761 _, result = self.connection_2.get_response(result)
762 else:
763 result = self.connection_2.result
764 self.assertEqual(result['description'], 'success')
765 self.assertFalse(b'title1' in self.connection_2.strategy.entries[dn]['title'])
766 self.assertFalse(b'title2' in self.connection_2.strategy.entries[dn]['title'])
767 self.assertFalse(b'title3' in self.connection_2.strategy.entries[dn]['title'])
768 self.assertTrue(b'title4' in self.connection_2.strategy.entries[dn]['title'])
769 self.assertTrue(b'title5' in self.connection_2.strategy.entries[dn]['title'])
770 self.assertEqual(len(self.connection_2.strategy.entries[dn]['title']), 2)
771
772 def test_modify_replace_existing_multivalue_3(self):
773 dn = 'cn=user4,ou=test,o=lab'
774 self.connection_3.bind()
775 result = self.connection_3.modify(dn, {'title': (MODIFY_REPLACE, ['title4', 'title5'])})
776 if not self.connection_3.strategy.sync:
777 _, result = self.connection_3.get_response(result)
778 else:
779 result = self.connection_3.result
780 self.assertEqual(result['description'], 'success')
781 self.assertFalse(b'title1' in self.connection_3.strategy.entries[dn]['title'])
782 self.assertFalse(b'title2' in self.connection_3.strategy.entries[dn]['title'])
783 self.assertFalse(b'title3' in self.connection_3.strategy.entries[dn]['title'])
784 self.assertTrue(b'title4' in self.connection_3.strategy.entries[dn]['title'])
785 self.assertTrue(b'title5' in self.connection_3.strategy.entries[dn]['title'])
786 self.assertEqual(len(self.connection_3.strategy.entries[dn]['title']), 2)
787
788 def test_modify_replace_existing_novalue_1(self):
789 dn = 'cn=user4,ou=test,o=lab'
790 self.connection_1.bind()
791 result = self.connection_1.modify(dn, {'title': (MODIFY_REPLACE, [])})
792 if not self.connection_1.strategy.sync:
793 _, result = self.connection_1.get_response(result)
794 else:
795 result = self.connection_1.result
796 self.assertEqual(result['description'], 'success')
797 self.assertFalse(b'title' in self.connection_1.strategy.entries[dn])
798
799 def test_modify_replace_existing_novalue_2(self):
800 dn = 'cn=user4,ou=test,o=lab'
801 self.connection_2.bind()
802 result = self.connection_2.modify(dn, {'title': (MODIFY_REPLACE, [])})
803 if not self.connection_2.strategy.sync:
804 _, result = self.connection_2.get_response(result)
805 else:
806 result = self.connection_2.result
807 self.assertEqual(result['description'], 'success')
808 self.assertFalse(b'title' in self.connection_2.strategy.entries[dn])
809
810 def test_modify_replace_existing_novalue_3(self):
811 dn = 'cn=user4,ou=test,o=lab'
812 self.connection_3.bind()
813 result = self.connection_3.modify(dn, {'title': (MODIFY_REPLACE, [])})
814 if not self.connection_3.strategy.sync:
815 _, result = self.connection_3.get_response(result)
816 else:
817 result = self.connection_3.result
818 self.assertEqual(result['description'], 'success')
819 self.assertFalse(b'title' in self.connection_3.strategy.entries[dn])
820
821 def test_modify_replace_not_existing_novalue_1(self):
822 dn = 'cn=user4,ou=test,o=lab'
823 self.connection_1.bind()
824 result = self.connection_1.modify(dn, {'initials': (MODIFY_REPLACE, [])})
825 if not self.connection_1.strategy.sync:
826 _, result = self.connection_1.get_response(result)
827 else:
828 result = self.connection_1.result
829 self.assertEqual(result['description'], 'success')
830 self.assertFalse(b'initials' in self.connection_1.strategy.entries[dn])
831
832 def test_modify_replace_not_existing_novalue_2(self):
833 dn = 'cn=user4,ou=test,o=lab'
834 self.connection_2.bind()
835 result = self.connection_2.modify(dn, {'initials': (MODIFY_REPLACE, [])})
836 if not self.connection_2.strategy.sync:
837 _, result = self.connection_2.get_response(result)
838 else:
839 result = self.connection_2.result
840 self.assertEqual(result['description'], 'success')
841 self.assertFalse(b'initials' in self.connection_2.strategy.entries[dn])
842
843 def test_modify_replace_not_existing_novalue_3(self):
844 dn = 'cn=user4,ou=test,o=lab'
845 self.connection_3.bind()
846 result = self.connection_3.modify(dn, {'initials': (MODIFY_REPLACE, [])})
847 if not self.connection_3.strategy.sync:
848 _, result = self.connection_3.get_response(result)
849 else:
850 result = self.connection_3.result
851 self.assertEqual(result['description'], 'success')
852 self.assertFalse(b'initials' in self.connection_3.strategy.entries[dn])
853
854 def test_modify_replace_not_existing_singlevalue_1(self):
855 dn = 'cn=user4,ou=test,o=lab'
856 self.connection_1.bind()
857 result = self.connection_1.modify(dn, {'initials': (MODIFY_REPLACE, ['initials1'])})
858 if not self.connection_1.strategy.sync:
859 _, result = self.connection_1.get_response(result)
860 else:
861 result = self.connection_1.result
862 self.assertEqual(result['description'], 'success')
863 self.assertTrue(b'initials1' in self.connection_1.strategy.entries[dn]['initials'])
864
865 def test_modify_replace_not_existing_singlevalue_2(self):
866 dn = 'cn=user4,ou=test,o=lab'
867 self.connection_2.bind()
868 result = self.connection_2.modify(dn, {'initials': (MODIFY_REPLACE, ['initials1'])})
869 if not self.connection_2.strategy.sync:
870 _, result = self.connection_2.get_response(result)
871 else:
872 result = self.connection_2.result
873 self.assertEqual(result['description'], 'success')
874 self.assertTrue(b'initials1' in self.connection_2.strategy.entries[dn]['initials'])
875
876 def test_modify_replace_not_existing_singlevalue_3(self):
877 dn = 'cn=user4,ou=test,o=lab'
878 self.connection_3.bind()
879 result = self.connection_3.modify(dn, {'initials': (MODIFY_REPLACE, ['initials1'])})
880 if not self.connection_3.strategy.sync:
881 _, result = self.connection_3.get_response(result)
882 else:
883 result = self.connection_3.result
884 self.assertEqual(result['description'], 'success')
885 self.assertTrue(b'initials1' in self.connection_3.strategy.entries[dn]['initials'])
886
887 def test_modify_replace_not_existing_multivalue_1(self):
888 dn = 'cn=user4,ou=test,o=lab'
889 self.connection_1.bind()
890 result = self.connection_1.modify(dn, {'initials': (MODIFY_REPLACE, ['initials1', 'initials2'])})
891 if not self.connection_1.strategy.sync:
892 _, result = self.connection_1.get_response(result)
893 else:
894 result = self.connection_1.result
895 self.assertEqual(result['description'], 'success')
896 self.assertTrue(b'initials1' in self.connection_1.strategy.entries[dn]['initials'])
897 self.assertTrue(b'initials2' in self.connection_1.strategy.entries[dn]['initials'])
898
899 def test_modify_replace_not_existing_multivalue_2(self):
900 dn = 'cn=user4,ou=test,o=lab'
901 self.connection_2.bind()
902 result = self.connection_2.modify(dn, {'initials': (MODIFY_REPLACE, ['initials1', 'initials2'])})
903 if not self.connection_2.strategy.sync:
904 _, result = self.connection_2.get_response(result)
905 else:
906 result = self.connection_2.result
907 self.assertEqual(result['description'], 'success')
908 self.assertTrue(b'initials1' in self.connection_2.strategy.entries[dn]['initials'])
909 self.assertTrue(b'initials2' in self.connection_2.strategy.entries[dn]['initials'])
910
911 def test_modify_replace_not_existing_multivalue_3(self):
912 dn = 'cn=user4,ou=test,o=lab'
913 self.connection_3.bind()
914 result = self.connection_3.modify(dn, {'initials': (MODIFY_REPLACE, ['initials1', 'initials2'])})
915 if not self.connection_3.strategy.sync:
916 _, result = self.connection_3.get_response(result)
917 else:
918 result = self.connection_3.result
919 self.assertEqual(result['description'], 'success')
920 self.assertTrue(b'initials1' in self.connection_3.strategy.entries[dn]['initials'])
921 self.assertTrue(b'initials2' in self.connection_3.strategy.entries[dn]['initials'])
922
923 def test_search_exact_match_single_attribute_1(self):
924 self.connection_1.bind()
925 result = self.connection_1.search('o=lab', '(cn=user1)', search_scope=SUBTREE, attributes=['cn', 'sn'])
926 response = self.connection_1.response
927 if not self.connection_1.strategy.sync:
928 response, result = self.connection_1.get_response(result)
929 else:
930 result = self.connection_1.result
931 self.assertEqual(result['description'], 'success')
932 self.assertEqual('user1', response[0]['attributes']['cn'][0])
933
934 def test_search_exact_match_single_attribute_2(self):
935 self.connection_2.bind()
936 result = self.connection_2.search('o=lab', '(cn=user2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
937 response = self.connection_2.response
938 if not self.connection_2.strategy.sync:
939 response, result = self.connection_2.get_response(result)
940 else:
941 result = self.connection_2.result
942 self.assertEqual(result['description'], 'success')
943 self.assertEqual('user2', response[0]['attributes']['cn'][0])
944
945 def test_search_exact_match_single_attribute_3(self):
946 self.connection_3.bind()
947 result = self.connection_3.search('o=lab', '(cn=user3)', search_scope=SUBTREE, attributes=['cn', 'sn'])
948 response = self.connection_3.response
949 if not self.connection_3.strategy.sync:
950 response, result = self.connection_3.get_response(result)
951 else:
952 result = self.connection_3.result
953 self.assertEqual(result['description'], 'success')
954 self.assertEqual('user3', response[0]['attributes']['cn'][0])
955
956 def test_search_exact_match_case_insensitive_single_attribute_1(self):
957 self.connection_1.bind()
958 result = self.connection_1.search('o=lab', '(cn=UsEr1)', search_scope=SUBTREE, attributes=['cn', 'sn'])
959 response = self.connection_1.response
960 if not self.connection_1.strategy.sync:
961 response, result = self.connection_1.get_response(result)
962 else:
963 result = self.connection_1.result
964 self.assertEqual(result['description'], 'success')
965 self.assertEqual('user1', response[0]['attributes']['cn'][0])
966
967 def test_search_exact_match_case_insensitive_single_attribute_2(self):
968 self.connection_2.bind()
969 result = self.connection_2.search('o=lab', '(cn=UsEr2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
970 response = self.connection_2.response
971 if not self.connection_2.strategy.sync:
972 response, result = self.connection_2.get_response(result)
973 else:
974 result = self.connection_2.result
975 self.assertEqual(result['description'], 'success')
976 self.assertEqual('user2', response[0]['attributes']['cn'][0])
977
978 def test_search_exact_match_case_insensitive_single_attribute_3(self):
979 self.connection_3.bind()
980 result = self.connection_3.search('o=lab', '(cn=UsEr3)', search_scope=SUBTREE, attributes=['cn', 'sn'])
981 response = self.connection_3.response
982 if not self.connection_3.strategy.sync:
983 response, result = self.connection_3.get_response(result)
984 else:
985 result = self.connection_3.result
986 self.assertEqual(result['description'], 'success')
987 self.assertEqual('user3', response[0]['attributes']['cn'][0])
988
989 def test_search_presence_single_attribute_1(self):
990 self.connection_1.bind()
991 result = self.connection_1.search('o=lab', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'sn'])
992 response = self.connection_1.response
993 if not self.connection_1.strategy.sync:
994 response, result = self.connection_1.get_response(result)
995 else:
996 result = self.connection_1.result
997 self.assertEqual(result['description'], 'success')
998 self.assertTrue('user' in response[0]['attributes']['cn'][0])
999
1000 def test_search_presence_single_attribute_2(self):
1001 self.connection_2.bind()
1002 result = self.connection_2.search('o=lab', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1003 response = self.connection_2.response
1004 if not self.connection_2.strategy.sync:
1005 response, result = self.connection_2.get_response(result)
1006 else:
1007 result = self.connection_2.result
1008 self.assertEqual(result['description'], 'success')
1009 self.assertTrue('user' in response[0]['attributes']['cn'][0])
1010
1011 def test_search_presence_single_attribute_3(self):
1012 self.connection_3.bind()
1013 result = self.connection_3.search('o=lab', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1014 response = self.connection_3.response
1015 if not self.connection_3.strategy.sync:
1016 response, result = self.connection_3.get_response(result)
1017 else:
1018 result = self.connection_3.result
1019 self.assertEqual(result['description'], 'success')
1020 self.assertTrue('user' in response[0]['attributes']['cn'][0])
1021
1022 def test_search_presence_and_filter_1(self):
1023 self.connection_1.bind()
1024 result = self.connection_1.search('o=lab', '(&(cn=*)(|(sn=user0_sn)(sn=user1_sn)))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1025 response = self.connection_1.response
1026 if not self.connection_1.strategy.sync:
1027 response, result = self.connection_1.get_response(result)
1028 else:
1029 result = self.connection_1.result
1030 self.assertEqual(result['description'], 'success')
1031 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1'])
1032
1033 self.connection_1b.bind()
1034 result = self.connection_1b.search('o=lab', '(&(cn=*)(|(sn=user0_sn)(sn=user1_sn)))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1035 response = self.connection_1b.response
1036 if not self.connection_1b.strategy.sync:
1037 response, result = self.connection_1b.get_response(result)
1038 else:
1039 result = self.connection_1b.result
1040 self.assertEqual(result['description'], 'success')
1041 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1'])
1042
1043 def test_search_presence_and_filter_2(self):
1044 self.connection_2.bind()
1045 result = self.connection_2.search('o=lab', '(&(cn=*)(|(sn=user0_sn)(sn=user1_sn)))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1046 response = self.connection_2.response
1047 if not self.connection_2.strategy.sync:
1048 response, result = self.connection_2.get_response(result)
1049 else:
1050 result = self.connection_2.result
1051 self.assertEqual(result['description'], 'success')
1052 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1'])
1053
1054 self.connection_2b.bind()
1055 result = self.connection_2b.search('o=lab', '(&(cn=*)(|(sn=user0_sn)(sn=user1_sn)))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1056 response = self.connection_2b.response
1057 if not self.connection_2b.strategy.sync:
1058 response, result = self.connection_2b.get_response(result)
1059 else:
1060 result = self.connection_2b.result
1061 self.assertEqual(result['description'], 'success')
1062 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1'])
1063
1064 def test_search_presence_and_filter_3(self):
1065 self.connection_3.bind()
1066 result = self.connection_3.search('o=lab', '(&(cn=*)(|(sn=user0_sn)(sn=user1_sn)))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1067 response = self.connection_3.response
1068 if not self.connection_3.strategy.sync:
1069 response, result = self.connection_3.get_response(result)
1070 else:
1071 result = self.connection_3.result
1072 self.assertEqual(result['description'], 'success')
1073 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1'])
1074
1075 self.connection_3b.bind()
1076 result = self.connection_3b.search('o=lab', '(&(cn=*)(|(sn=user0_sn)(sn=user1_sn)))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1077 response = self.connection_3b.response
1078 if not self.connection_3b.strategy.sync:
1079 response, result = self.connection_3b.get_response(result)
1080 else:
1081 result = self.connection_3b.result
1082 self.assertEqual(result['description'], 'success')
1083 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1'])
1084
1085 def test_search_incorrect_base_1(self):
1086 self.connection_1.bind()
1087 result = self.connection_1.search('o=nonexistant', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1088 if not self.connection_1.strategy.sync:
1089 _, result = self.connection_1.get_response(result)
1090 else:
1091 result = self.connection_1.result
1092 self.assertEqual(result['description'], 'noSuchObject')
1093
1094 def test_search_incorrect_base_2(self):
1095 self.connection_2.bind()
1096 result = self.connection_2.search('o=nonexistant', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1097 if not self.connection_2.strategy.sync:
1098 _, result = self.connection_2.get_response(result)
1099 else:
1100 result = self.connection_2.result
1101 self.assertEqual(result['description'], 'noSuchObject')
1102
1103 def test_search_incorrect_base_3(self):
1104 self.connection_3.bind()
1105 result = self.connection_3.search('o=nonexistant', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1106 if not self.connection_3.strategy.sync:
1107 _, result = self.connection_3.get_response(result)
1108 else:
1109 result = self.connection_3.result
1110 self.assertEqual(result['description'], 'noSuchObject')
1111
1112 def test_search_incorrect_base_exception_1(self):
1113 self.connection_1c.bind()
1114 try:
1115 result = self.connection_1c.search('o=nonexistant', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1116 if not self.connection_1c.strategy.sync:
1117 _, result = self.connection_1c.get_response(result)
1118 self.fail('exception not raised')
1119 except LDAPNoSuchObjectResult:
1120 pass
1121
1122 def test_search_incorrect_base_exception_2(self):
1123 self.connection_2c.bind()
1124 try:
1125 result = self.connection_2c.search('o=nonexistant', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1126 if not self.connection_2c.strategy.sync:
1127 _, result = self.connection_2c.get_response(result)
1128 self.fail('exception not raised')
1129 except LDAPNoSuchObjectResult:
1130 pass
1131
1132 def test_search_incorrect_base_exception_3(self):
1133 self.connection_3c.bind()
1134 try:
1135 result = self.connection_3c.search('o=nonexistant', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1136 if not self.connection_3c.strategy.sync:
1137 _, result = self.connection_3c.get_response(result)
1138 self.fail('exception not raised')
1139 except LDAPNoSuchObjectResult:
1140 pass
1141
1142 def test_search_presence_and_filter_no_entries_found_1(self):
1143 self.connection_1.bind()
1144 result = self.connection_1.search('o=lab', '(&(cn=*)(sn=user_nonexistant))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1145 response = self.connection_1.response
1146 if not self.connection_1.strategy.sync:
1147 response, result = self.connection_1.get_response(result)
1148 else:
1149 result = self.connection_1.result
1150 self.assertEqual(result['description'], 'success')
1151 self.assertEqual(len(response), 0)
1152
1153 def test_search_presence_and_filter_no_entries_found_2(self):
1154 self.connection_2.bind()
1155 result = self.connection_2.search('o=lab', '(&(cn=*)(sn=user_nonexistant))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1156 response = self.connection_2.response
1157 if not self.connection_2.strategy.sync:
1158 response, result = self.connection_2.get_response(result)
1159 else:
1160 result = self.connection_2.result
1161 self.assertEqual(result['description'], 'success')
1162 self.assertEqual(len(response), 0)
1163
1164 def test_search_presence_and_filter_no_entries_found_3(self):
1165 self.connection_3.bind()
1166 result = self.connection_3.search('o=lab', '(&(cn=*)(sn=user_nonexistant))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1167 response = self.connection_3.response
1168 if not self.connection_3.strategy.sync:
1169 response, result = self.connection_3.get_response(result)
1170 else:
1171 result = self.connection_3.result
1172 self.assertEqual(result['description'], 'success')
1173 self.assertEqual(len(response), 0)
1174
1175 def test_search_exact_match_not_filter_1(self):
1176 self.connection_1.bind()
1177 result = self.connection_1.search('o=lab', '(!(sn=user0_sn))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1178 response = self.connection_1.response
1179 if not self.connection_1.strategy.sync:
1180 response, result = self.connection_1.get_response(result)
1181 else:
1182 result = self.connection_1.result
1183 self.assertEqual(result['description'], 'success')
1184 self.assertNotEqual(response[0]['attributes']['cn'][0], 'user0')
1185
1186 def test_search_exact_match_not_filter_2(self):
1187 self.connection_2.bind()
1188 result = self.connection_2.search('o=lab', '(!(sn=user0_sn))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1189 response = self.connection_2.response
1190 if not self.connection_2.strategy.sync:
1191 response, result = self.connection_2.get_response(result)
1192 else:
1193 result = self.connection_2.result
1194 self.assertEqual(result['description'], 'success')
1195 self.assertNotEqual(response[0]['attributes']['cn'][0], 'user0')
1196
1197 def test_search_exact_match_not_filter_3(self):
1198 self.connection_3.bind()
1199 result = self.connection_3.search('o=lab', '(!(sn=user0_sn))', search_scope=SUBTREE, attributes=['cn', 'sn'])
1200 response = self.connection_3.response
1201 if not self.connection_3.strategy.sync:
1202 response, result = self.connection_3.get_response(result)
1203 else:
1204 result = self.connection_3.result
1205 self.assertEqual(result['description'], 'success')
1206 self.assertNotEqual(response[0]['attributes']['cn'][0], 'user0')
1207
1208 def test_search_greater_or_equal_than_string_1(self):
1209 self.connection_1.bind()
1210 result = self.connection_1.search('o=lab', '(userPassword>=test2222)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1211 response = self.connection_1.response
1212 if not self.connection_1.strategy.sync:
1213 response, result = self.connection_1.get_response(result)
1214 else:
1215 result = self.connection_1.result
1216 self.assertEqual(result['description'], 'success')
1217 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2', 'user3', 'user4'])
1218
1219 def test_search_greater_or_equal_than_string_2(self):
1220 self.connection_2.bind()
1221 result = self.connection_2.search('o=lab', '(userPassword>=test2222)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1222 response = self.connection_2.response
1223 if not self.connection_2.strategy.sync:
1224 response, result = self.connection_2.get_response(result)
1225 else:
1226 result = self.connection_2.result
1227 self.assertEqual(result['description'], 'success')
1228 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2', 'user3', 'user4'])
1229
1230 def test_search_greater_or_equal_than_string_3(self):
1231 self.connection_3.bind()
1232 result = self.connection_3.search('o=lab', '(userPassword>=test2222)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1233 response = self.connection_3.response
1234 if not self.connection_3.strategy.sync:
1235 response, result = self.connection_3.get_response(result)
1236 else:
1237 result = self.connection_3.result
1238 self.assertEqual(result['description'], 'success')
1239 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2', 'user3', 'user4'])
1240
1241 def test_search_greater_or_equal_than_int_1(self):
1242 self.connection_1.bind()
1243 result = self.connection_1.search('o=lab', '(revision>=2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1244 response = self.connection_1.response
1245 if not self.connection_1.strategy.sync:
1246 response, result = self.connection_1.get_response(result)
1247 else:
1248 result = self.connection_1.result
1249 self.assertEqual(result['description'], 'success')
1250 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2', 'user3', 'user4'])
1251
1252 def test_search_greater_or_equal_than_int_2(self):
1253 self.connection_2.bind()
1254 result = self.connection_2.search('o=lab', '(revision>=2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1255 response = self.connection_2.response
1256 if not self.connection_2.strategy.sync:
1257 response, result = self.connection_2.get_response(result)
1258 else:
1259 result = self.connection_2.result
1260 self.assertEqual(result['description'], 'success')
1261 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2', 'user3', 'user4'])
1262
1263 def test_search_greater_or_equal_than_int_3(self):
1264 self.connection_3.bind()
1265 result = self.connection_3.search('o=lab', '(revision>=2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1266 response = self.connection_3.response
1267 if not self.connection_3.strategy.sync:
1268 response, result = self.connection_3.get_response(result)
1269 else:
1270 result = self.connection_3.result
1271 self.assertEqual(result['description'], 'success')
1272 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2', 'user3', 'user4'])
1273
1274 def test_search_less_or_equal_than_string_1(self):
1275 self.connection_1.bind()
1276 result = self.connection_1.search('o=lab', '(userPassword<=test2222)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1277 response = self.connection_1.response
1278 if not self.connection_1.strategy.sync:
1279 response, result = self.connection_1.get_response(result)
1280 else:
1281 result = self.connection_1.result
1282 self.assertEqual(result['description'], 'success')
1283 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1', 'user2'])
1284
1285 def test_search_less_or_equal_than_string_2(self):
1286 self.connection_2.bind()
1287 result = self.connection_2.search('o=lab', '(userPassword<=test2222)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1288 response = self.connection_2.response
1289 if not self.connection_2.strategy.sync:
1290 response, result = self.connection_2.get_response(result)
1291 else:
1292 result = self.connection_2.result
1293 self.assertEqual(result['description'], 'success')
1294 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1', 'user2'])
1295
1296 def test_search_less_or_equal_than_string_3(self):
1297 self.connection_3.bind()
1298 result = self.connection_3.search('o=lab', '(userPassword<=test2222)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1299 response = self.connection_3.response
1300 if not self.connection_3.strategy.sync:
1301 response, result = self.connection_3.get_response(result)
1302 else:
1303 result = self.connection_3.result
1304 self.assertEqual(result['description'], 'success')
1305 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1', 'user2'])
1306
1307 def test_search_less_or_equal_than_int_1(self):
1308 self.connection_1.bind()
1309 result = self.connection_1.search('o=lab', '(revision<=2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1310 response = self.connection_1.response
1311 if not self.connection_1.strategy.sync:
1312 response, result = self.connection_1.get_response(result)
1313 else:
1314 result = self.connection_1.result
1315 self.assertEqual(result['description'], 'success')
1316 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1', 'user2'])
1317
1318 def test_search_less_or_equal_than_int_2(self):
1319 self.connection_2.bind()
1320 result = self.connection_2.search('o=lab', '(revision<=2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1321 response = self.connection_2.response
1322 if not self.connection_2.strategy.sync:
1323 response, result = self.connection_2.get_response(result)
1324 else:
1325 result = self.connection_2.result
1326 self.assertEqual(result['description'], 'success')
1327 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1', 'user2'])
1328
1329 def test_search_less_or_equal_than_int_3(self):
1330 self.connection_3.bind()
1331 result = self.connection_3.search('o=lab', '(revision<=2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1332 response = self.connection_3.response
1333 if not self.connection_3.strategy.sync:
1334 response, result = self.connection_3.get_response(result)
1335 else:
1336 result = self.connection_3.result
1337 self.assertEqual(result['description'], 'success')
1338 self.assertTrue(response[0]['attributes']['cn'][0] in ['user0', 'user1', 'user2'])
1339
1340 def test_search_substring_1(self):
1341 self.connection_1.bind()
1342 result = self.connection_1.search('o=lab', '(cn=*ser*2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1343 response = self.connection_1.response
1344 if not self.connection_1.strategy.sync:
1345 response, result = self.connection_1.get_response(result)
1346 else:
1347 result = self.connection_1.result
1348 self.assertEqual(result['description'], 'success')
1349 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2'])
1350
1351 def test_search_substring_2(self):
1352 self.connection_2.bind()
1353 result = self.connection_2.search('o=lab', '(cn=*ser*2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1354 response = self.connection_2.response
1355 if not self.connection_2.strategy.sync:
1356 response, result = self.connection_2.get_response(result)
1357 else:
1358 result = self.connection_2.result
1359 self.assertEqual(result['description'], 'success')
1360 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2'])
1361
1362 def test_search_substring_3(self):
1363 self.connection_3.bind()
1364 result = self.connection_3.search('o=lab', '(cn=*ser*2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1365 response = self.connection_3.response
1366 if not self.connection_3.strategy.sync:
1367 response, result = self.connection_3.get_response(result)
1368 else:
1369 result = self.connection_3.result
1370 self.assertEqual(result['description'], 'success')
1371 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2'])
1372
1373 def test_search_case_insensitive_substring_1(self):
1374 self.connection_1.bind()
1375 result = self.connection_1.search('o=lab', '(cn=*SeR*2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1376 response = self.connection_1.response
1377 if not self.connection_1.strategy.sync:
1378 response, result = self.connection_1.get_response(result)
1379 else:
1380 result = self.connection_1.result
1381 self.assertEqual(result['description'], 'success')
1382 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2'])
1383
1384 def test_search_case_insensitive_substring_2(self):
1385 self.connection_2.bind()
1386 result = self.connection_2.search('o=lab', '(cn=*SeR*2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1387 response = self.connection_2.response
1388 if not self.connection_2.strategy.sync:
1389 response, result = self.connection_2.get_response(result)
1390 else:
1391 result = self.connection_2.result
1392 self.assertEqual(result['description'], 'success')
1393 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2'])
1394
1395 def test_search_case_insensitive_substring_3(self):
1396 self.connection_3.bind()
1397 result = self.connection_3.search('o=lab', '(cn=*SeR*2)', search_scope=SUBTREE, attributes=['cn', 'sn'])
1398 response = self.connection_3.response
1399 if not self.connection_3.strategy.sync:
1400 response, result = self.connection_3.get_response(result)
1401 else:
1402 result = self.connection_3.result
1403 self.assertEqual(result['description'], 'success')
1404 self.assertTrue(response[0]['attributes']['cn'][0] in ['user2'])
1405
1406 def test_search_presence_singlevalue_attribute_1(self):
1407 self.connection_1.bind()
1408 result = self.connection_1.search('o=lab', '(revision=*)', search_scope=SUBTREE, attributes=['cn', 'revision'])
1409 response = self.connection_1.response
1410 if not self.connection_1.strategy.sync:
1411 response, result = self.connection_1.get_response(result)
1412 else:
1413 result = self.connection_1.result
1414 self.assertEqual(result['description'], 'success')
1415
1416 self.assertTrue(isinstance(response[0]['attributes']['revision'], int))
1417
1418 def test_search_presence_singlevalue_attribute_2(self):
1419 self.connection_2.bind()
1420 result = self.connection_2.search('o=lab', '(revision=*)', search_scope=SUBTREE, attributes=['cn', 'revision'])
1421 response = self.connection_2.response
1422 if not self.connection_2.strategy.sync:
1423 response, result = self.connection_2.get_response(result)
1424 else:
1425 result = self.connection_2.result
1426 self.assertEqual(result['description'], 'success')
1427 self.assertTrue(isinstance(response[0]['attributes']['revision'], int))
1428
1429 def test_search_presence_singlevalue_attribute_3(self):
1430 self.connection_3.bind()
1431 result = self.connection_3.search('o=lab', '(revision=*)', search_scope=SUBTREE, attributes=['cn', 'revision'])
1432 response = self.connection_3.response
1433 if not self.connection_3.strategy.sync:
1434 response, result = self.connection_3.get_response(result)
1435 else:
1436 result = self.connection_3.result
1437 self.assertEqual(result['description'], 'success')
1438 self.assertTrue(isinstance(response[0]['attributes']['revision'], list)) # no schema so attributes are returned as lists
1439
1440 def test_search_paged_1(self):
1441 self.connection_1.bind()
1442 response = []
1443 for resp in self.connection_1.extend.standard.paged_search('o=lab', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'revision'], paged_size=2, paged_criticality=True):
1444 response.append(resp)
1445
1446 self.assertEqual(len(response), 5)
1447
1448 def test_search_paged_2(self):
1449 self.connection_2.bind()
1450 response = []
1451 for resp in self.connection_2.extend.standard.paged_search('o=lab', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'revision'], paged_size=2, paged_criticality=True):
1452 response.append(resp)
1453
1454 self.assertEqual(len(response), 5)
1455
1456 def test_search_paged_3(self):
1457 self.connection_3.bind()
1458 response = []
1459 for resp in self.connection_3.extend.standard.paged_search('o=lab', '(cn=*)', search_scope=SUBTREE, attributes=['cn', 'revision'], paged_size=2, paged_criticality=True):
1460 response.append(resp)
1461
1462 self.assertEqual(len(response), 5)