Debian Codegraph @

dirsrvtests/tests/suites/vlv/regression_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2026 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9 import pytest, time
10 import os
11 import glob
12 import ldap
13 import pwd
14 from shutil import copyfile, rmtree
15 from datetime import datetime
16 from contextlib import contextmanager, suppress
17 from lib389.tasks import *
18 from lib389.utils import *
19 from lib389.dseutils import get_ldapurl_from_serverid
20 from test389.topologies import topology_m2, topology_st
21 from lib389.replica import *
22 from lib389._constants import *
23 from lib389.properties import TASK_WAIT
24 from lib389.index import *
25 from lib389.mappingTree import *
26 from lib389.backend import *
27 from lib389.dirsrv_log import DirsrvAccessLog
28 from lib389.idm.user import UserAccounts, UserAccount
29 from lib389.idm.organization import Organization
30 from ldap.controls.vlv import VLVRequestControl
31 from ldap.controls.sss import SSSRequestControl
32 from lib389.replica import BootstrapReplicationManager, Replicas, ReplicationManager
33 from lib389.agreement import Agreements
34 from lib389.cli_ctl.dblib import run_dbscan
35 from lib389.idm.organizationalunit import OrganizationalUnits
36
37
38
39
40 pytestmark = pytest.mark.tier1
41
42 logging.getLogger(__name__).setLevel(logging.DEBUG)
43 log = logging.getLogger(__name__)
44 DEBUGGING = os.getenv("DEBUGGING", default=False)
45
46 STARTING_UID_INDEX = 1000
47 # VLV search always returns first the entry before the target,
48 # and the entry uid=demo_user,ou=people,dc=example,dc=com
49 # is before the uid=testuserNNNN,dc=example,dc=com entries
50 # so VLV_SEARCH_OFFSET (The difference between the vlv index
51 # and the NNNN value) is:
52 VLV_SEARCH_OFFSET = STARTING_UID_INDEX - 2
53
54 DEMO_PW = 'secret12'
55
56 # A VLV Index with invalid vlvSrch:
57 # ( Using objectClass: extensibleobject instead of objectClass: vlvSrch )
58 BAD_DSE_DATA = """dn: cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config
59 objectClass: top
60 objectClass: extensibleobject
61 cn: vlvSrch
62 vlvBase: dc=example,dc=com
63 vlvFilter: (uid=*)
64 vlvScope: 2
65 modifiersName: cn=directory manager
66 createTimestamp: 20240110175704Z
67 modifyTimestamp: 20240110175704Z
68 numSubordinates: 1
69
70 dn: cn=vlvIdx,cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config
71 objectClass: top
72 objectClass: vlvIndex
73 cn: vlvIdx
74 vlvSort: cn
75 creatorsName: cn=directory manager
76 modifiersName: cn=directory manager
77 createTimestamp: 20240110175704Z
78 modifyTimestamp: 20240110175704Z
79 """
80
81
82 def open_new_ldapi_conn(dsinstance):
83 ldapurl, certdir = get_ldapurl_from_serverid(dsinstance)
84 assert 'ldapi://' in ldapurl
85 conn = ldap.initialize(ldapurl)
86 conn.sasl_interactive_bind_s("", ldap.sasl.external())
87 return conn
88
89
90 def check_vlv_search(conn, **kwargs):
91 before_count = kwargs.get('before_count', 1)
92 after_count = kwargs.get('after_count', 3)
93 offset = kwargs.get('offset', 3501)
94 basedn = kwargs.get('basedn', DEFAULT_SUFFIX)
95
96 log.info('Testing that VLV search is returning the expected entries: '
97 f'basedn={basedn} '
98 f'before_count={before_count} '
99 f'after_count={after_count} '
100 f'offset={offset}')
101 vlv_control = VLVRequestControl(criticality=True,
102 before_count=before_count,
103 after_count=after_count,
104 offset=offset,
105 content_count=0,
106 greater_than_or_equal=None,
107 context_id=None)
108
109 sss_control = SSSRequestControl(criticality=True, ordering_rules=['cn'])
110 result = conn.search_ext_s(
111 base=basedn,
112 scope=ldap.SCOPE_SUBTREE,
113 filterstr='(uid=*)',
114 serverctrls=[vlv_control, sss_control]
115 )
116 imin = offset + VLV_SEARCH_OFFSET - before_count
117 imax = offset + VLV_SEARCH_OFFSET + after_count
118
119 for i, (dn, entry) in enumerate(result, start=imin):
120 assert i <= imax
121 expected_rdn = f'uid=testuser{i},'
122 log.debug(f'found {dn} should starts with {expected_rdn}')
123 assert dn.lower().startswith(expected_rdn)
124
125
126 def add_user(inst, users, uid):
127 user_properties = {
128 'uid': f'testuser{uid}',
129 'cn': f'testuser{uid}',
130 'sn': 'user',
131 'uidNumber': str(uid),
132 'gidNumber': str(uid),
133 'homeDirectory': f'/home/testuser{uid}'
134 }
135 users.create(properties=user_properties)
136
137
138 def add_users(inst, users_num, suffix=DEFAULT_SUFFIX):
139 users = UserAccounts(inst, suffix)
140 log.info(f'Adding {users_num} users')
141 for i in range(0, users_num):
142 uid = STARTING_UID_INDEX + i
143 add_user(inst, users, uid)
144
145
146 def create_vlv_search_and_index(inst, basedn=DEFAULT_SUFFIX, bename='userRoot',
147 scope=ldap.SCOPE_SUBTREE, prefix="vlv", vlvsort="cn"):
148 vlv_searches = VLVSearch(inst)
149 vlv_search_properties = {
150 "objectclass": ["top", "vlvSearch"],
151 "cn": f"{prefix}Srch",
152 "vlvbase": basedn,
153 "vlvfilter": "(uid=*)",
154 "vlvscope": str(scope),
155 }
156 vlv_searches.create(
157 basedn=f"cn={bename},cn=ldbm database,cn=plugins,cn=config",
158 properties=vlv_search_properties
159 )
160
161 vlv_index = VLVIndex(inst)
162 vlv_index_properties = {
163 "objectclass": ["top", "vlvIndex"],
164 "cn": f"{prefix}Idx",
165 "vlvsort": vlvsort,
166 }
167 vlv_index.create(
168 basedn=f"cn={prefix}Srch,cn={bename},cn=ldbm database,cn=plugins,cn=config",
169 properties=vlv_index_properties
170 )
171 return vlv_searches, vlv_index
172
173
174 def remove_entries(inst, basedn, filter):
175 # Remove all entries matching the criteriae.
176 conn = open_new_ldapi_conn(inst.serverid)
177 entries = conn.search_s(basedn, ldap.SCOPE_SUBTREE, filter)
178 for entry in entries:
179 conn.delete_s(entry[0])
180
181
182 def cleanup(inst):
183 # Remove the left over from previous tests.
184 remove_entries(inst, "cn=config", "(objectclass=vlvIndex)")
185 remove_entries(inst, "cn=config", "(objectclass=vlvSearch)")
186 remove_entries(inst, DEFAULT_SUFFIX, "(cn=testuser*)")
187
188 class BackendHandler:
189 def __init__(self, inst, bedict, scope=ldap.SCOPE_ONELEVEL):
190 self.inst = inst
191 self.bedict = bedict
192 self.bes = Backends(inst)
193 self.scope = scope
194 self.data = {}
195
196 def find_backend(self, bename):
197 for be in self.bes.list():
198 if be.get_attr_val_utf8_l('cn') == bename:
199 return be
200 return None
201
202 def cleanup(self):
203 benames = list(self.bedict.keys())
204 benames.reverse()
205 for bename in benames:
206 be = self.find_backend(bename)
207 if be:
208 be.delete()
209
210 def setup(self):
211 # Create backends, add vlv index and populate the backends.
212 for bename,suffix in self.bedict.items():
213 be = self.bes.create(properties={
214 'cn': bename,
215 'nsslapd-suffix': suffix,
216 })
217 # Add suffix entry
218 Organization(self.inst, dn=suffix).create(properties={ 'o': bename, })
219 # Configure vlv
220 vlv_search, vlv_index = create_vlv_search_and_index(
221 self.inst, basedn=suffix,
222 bename=bename, scope=self.scope,
223 prefix=f'vlv_1lvl_{bename}')
224 # Reindex
225 reindex_task = Tasks(self.inst)
226 assert reindex_task.reindex(
227 suffix=suffix,
228 attrname=vlv_index.rdn,
229 args={TASK_WAIT: True},
230 vlv=True
231 ) == 0
232 # Add ou=People entry
233 OrganizationalUnits(self.inst, suffix).create(properties={'ou': 'People'})
234 # Add another ou that will be deleted before the export
235 # so that import will change the vlv search basedn entryid
236 ou2 = OrganizationalUnits(self.inst, suffix).create(properties={'ou': 'dummy ou'})
237 # Add a demo user so that vlv_check is happy
238 dn = f'uid=demo_user,ou=people,{suffix}'
239 UserAccount(self.inst, dn=dn).create( properties= {
240 'uid': 'demo_user',
241 'cn': 'Demo user',
242 'sn': 'Demo user',
243 'uidNumber': '99998',
244 'gidNumber': '99998',
245 'homeDirectory': '/var/empty',
246 'loginShell': '/bin/false',
247 'userpassword': DEMO_PW })
248 # Add regular user
249 add_users(self.inst, 10, suffix=suffix)
250 # Removing ou2
251 ou2.delete()
252 # And export
253 tasks = Tasks(self.inst)
254 ldif = f'{self.inst.get_ldif_dir()}/db-{bename}.ldif'
255 assert tasks.exportLDIF(suffix=suffix,
256 output_file=ldif,
257 args={TASK_WAIT: True}) == 0
258 # Add the various parameters in topology_st.belist
259 self.data[bename] = { 'be': be,
260 'suffix': suffix,
261 'ldif': ldif,
262 'vlv_search' : vlv_search,
263 'vlv_index' : vlv_index,
264 'dn' : dn}
265
266
267 @pytest.fixture
268 def vlv_setup_with_two_backend(topology_st, request):
269 inst = topology_st.standalone
270 beh = BackendHandler(inst, { 'be1': 'o=be1', 'be2': 'o=be2' })
271
272 def fin():
273 # Cleanup function
274 if not DEBUGGING and inst.exists() and inst.status():
275 beh.cleanup()
276
277 request.addfinalizer(fin)
278
279 # Make sure that our backend are not already present.
280 beh.cleanup()
281
282 # Add userRoot backend to the backend list
283 be0 = beh.find_backend('userroot')
284 be0ldif = f'{inst.get_ldif_dir()}/db-userroot.ldif'
285 assert Tasks(inst).exportLDIF(suffix=DEFAULT_SUFFIX,
286 output_file=be0ldif,
287 args={TASK_WAIT: True}) == 0
288 beh.data['userroot'] = { 'be': be0,
289 'suffix': DEFAULT_SUFFIX,
290 'ldif': be0ldif, }
291 # Then add two new backends
292 beh.setup()
293 topology_st.beh = beh
294 topology_st.belist = list(beh.data.values())
295 return topology_st
296
297
298 @pytest.fixture
299 def vlv_setup_nested_backends(topology_st, request):
300 inst = topology_st.standalone
301 beh = BackendHandler(inst, { 'be1': 'o=be1', 'be2': 'o=be2,o=be1' }, scope=ldap.SCOPE_SUBTREE)
302
303 def fin():
304 # Cleanup function
305 if not DEBUGGING and inst.exists() and inst.status():
306 beh.cleanup()
307
308 request.addfinalizer(fin)
309
310 # Make sure that our backend are not already present.
311 beh.cleanup()
312 beh.setup()
313 topology_st.beh = beh
314 return topology_st
315
316
317 @pytest.fixture
318 def vlv_setup_with_uid_mr(topology_st, request):
319 inst = topology_st.standalone
320 bename = 'be1'
321 besuffix = f'o={bename}'
322 beh = BackendHandler(inst, { bename: besuffix })
323
324 def fin():
325 # Cleanup function
326 if not DEBUGGING and inst.exists() and inst.status():
327 beh.cleanup()
328
329 request.addfinalizer(fin)
330
331 # Make sure that our backend are not already present.
332 beh.cleanup()
333
334 # Then add the new backend
335 beh.setup()
336
337 index = Index(inst, f'cn=uid,cn=index,cn={bename},cn=ldbm database,cn=plugins,cn=config')
338 index.add('nsMatchingRule', '2.5.13.2')
339 reindex_task = Tasks(inst)
340 assert reindex_task.reindex(
341 suffix=besuffix,
342 attrname='uid',
343 args={TASK_WAIT: True}
344 ) == 0
345
346 topology_st.beh = beh
347 return topology_st
348
349
350
351 @pytest.fixture
352 def freeipa(topology_st):
353 # generate a standalone instance with same vlv config than freeipa
354 inst = topology_st.standalone
355 datadir = os.path.join(os.path.dirname(__file__), '../../data/freeipa/issue6136')
356 # Stop instance
357 inst.stop()
358 # Copy schema
359 for file in glob.glob(f'{datadir}/schema/*.ldif'):
360 target = f'{inst.schemadir}/{os.path.basename(file)}'
361 log.info(f'Copying Schema {file} to {target}')
362 copyfile(file, target)
363 # append dse
364 file = f'{datadir}/dse.ldif'
365 target = f'{inst.confdir}/{os.path.basename(file)}'
366 log.info(f'Appending ldif {file} to dse {target}')
367 with open(file, 'r') as fin:
368 with open(target, 'a') as fout:
369 fout.write(fin.read())
370 # import ipaca
371 # Make the ldif filke readable by ns-slapd process
372 file_ref = f'{datadir}/ipaca.ldif'
373 file = f'{inst.ds_paths.ldif_dir}/ipaca.ldif'
374 log.info(f'Copying ldif {file_ref} to {file}')
375 copyfile(file_ref, file)
376 dirsrv = pwd.getpwnam('dirsrv')
377 os.chown(file, dirsrv.pw_uid, dirsrv.pw_gid)
378 # Then import it
379 log.info(f'Importing ldif {file} to ipaca')
380 assert inst.ldif2db('ipaca', None, None, None, file)
381 # restart instance
382 inst.restart()
383 return topology_st
384
385
386 def test_bulk_import_when_the_backend_with_vlv_was_recreated(topology_m2):
387 """
388 Testing bulk import when the backend with VLV was recreated.
389 If the test passes without the server crash, 47966 is verified.
390
391 :id: 37d42d12-2544-49a0-81ef-7dbfb69edc0f
392 :setup: Replication with two suppliers.
393 :steps:
394 1. Generate vlvSearch entry
395 2. Generate vlvIndex entry
396 3. Delete the backend instance on Supplier 2
397 4. Delete the agreement, replica, and mapping tree, too.
398 5. Recreate the backend and the VLV index on Supplier 2.
399 6. Recreating vlvSrchDn and vlvIndexDn on Supplier 2.
400 :expectedresults:
401 1. Should Success.
402 2. Should Success.
403 3. Should Success.
404 4. Should Success.
405 5. Should Success.
406 6. Should Success.
407 """
408 M1 = topology_m2.ms["supplier1"]
409 M2 = topology_m2.ms["supplier2"]
410 # generate vlvSearch entry
411 properties_for_search = {
412 "objectclass": ["top", "vlvSearch"],
413 "cn": "vlvSrch",
414 "vlvbase": DEFAULT_SUFFIX,
415 "vlvfilter": "(|(objectclass=*)(objectclass=ldapsubentry))",
416 "vlvscope": "2",
417 }
418 vlv_searches = VLVSearch(M2)
419 userroot_vlvsearch = vlv_searches.create(
420 basedn="cn=userRoot,cn=ldbm database,cn=plugins,cn=config",
421 properties=properties_for_search,
422 )
423 assert "cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config" in M2.getEntry(
424 "cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config").dn
425 # generate vlvIndex entry
426 properties_for_index = {
427 "objectclass": ["top", "vlvIndex"],
428 "cn": "vlvIdx",
429 "vlvsort": "cn ou sn",
430 }
431 vlv_index = VLVIndex(M2)
432 userroot_index = vlv_index.create(
433 basedn="cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config",
434 properties=properties_for_index,
435 )
436 assert "cn=vlvIdx,cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config" in M2.getEntry(
437 "cn=vlvIdx,cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config").dn
438 # Delete the backend instance on Supplier 2."
439 userroot_index.delete()
440 userroot_vlvsearch.delete_all()
441 # delete the agreement, replica, and mapping tree, too.
442 repl = ReplicationManager(DEFAULT_SUFFIX)
443 repl.remove_supplier(M2)
444 MappingTrees(M2).list()[0].delete()
445 Backends(M2).list()[0].delete()
446 # Recreate the backend and the VLV index on Supplier 2.
447 M2.backend.create(DEFAULT_SUFFIX, {BACKEND_NAME: "userRoot"})
448 M2.mappingtree.create(DEFAULT_SUFFIX, "userRoot")
449 # Recreating vlvSrchDn and vlvIndexDn on Supplier 2.
450 vlv_searches.create(
451 basedn="cn=userRoot,cn=ldbm database,cn=plugins,cn=config",
452 properties=properties_for_search,
453 )
454 vlv_index.create(
455 basedn="cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config",
456 properties=properties_for_index,
457 )
458 M2.restart()
459 repl.join_supplier(M1, M2)
460 repl.test_replication(M1, M2, 30)
461 repl.test_replication(M2, M1, 30)
462 entries = M2.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(uid=*)")
463 assert len(entries) > 0
464 entries = M2.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(objectclass=*)")
465 entries = M2.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(objectclass=*)")
466
467
468 def test_vlv_recreation_reindex(topology_st):
469 """Test VLV recreation and reindexing.
470
471 :id: 29f4567f-4ac0-410f-bc99-a32e217a939f
472 :setup: Standalone instance.
473 :steps:
474 1. Create new VLVs and do the reindex.
475 2. Test the new VLVs.
476 3. Remove the existing VLVs.
477 4. Create new VLVs (with the same name).
478 5. Perform online re-indexing of the new VLVs.
479 6. Test the new VLVs.
480 :expectedresults:
481 1. Should Success.
482 2. Should Success.
483 3. Should Success.
484 4. Should Success.
485 5. Should Success.
486 6. Should Success.
487 """
488
489 inst = topology_st.standalone
490 reindex_task = Tasks(inst)
491
492 # Create and test VLVs
493 vlv_search, vlv_index = create_vlv_search_and_index(inst)
494 assert reindex_task.reindex(
495 suffix=DEFAULT_SUFFIX,
496 attrname=vlv_index.rdn,
497 args={TASK_WAIT: True},
498 vlv=True
499 ) == 0
500
501 add_users(inst, 5000)
502
503 conn = open_new_ldapi_conn(inst.serverid)
504 assert len(conn.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(uid=*)")) > 0
505 check_vlv_search(conn)
506
507 # Remove and recreate VLVs
508 vlv_index.delete()
509 vlv_search.delete()
510
511 vlv_search, vlv_index = create_vlv_search_and_index(inst)
512 assert reindex_task.reindex(
513 suffix=DEFAULT_SUFFIX,
514 attrname=vlv_index.rdn,
515 args={TASK_WAIT: True},
516 vlv=True
517 ) == 0
518
519 conn = open_new_ldapi_conn(inst.serverid)
520 assert len(conn.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(uid=*)")) > 0
521 check_vlv_search(conn)
522
523
524 def get_db_filename(vlvname, prefix='', iscache=False):
525 # Normalize the vlv db name
526 chars = set('abcdefghijklmnopqrstuvwxyz0123456789')
527 vlvname = ''.join(c for c in vlvname.lower() if c in chars)
528 bename = 'userRoot'
529 cache = ''
530 if iscache:
531 cache = '~recno-cache/'
532 if get_default_db_lib() == "mdb":
533 bename = bename.lower()
534 return f'{prefix}{bename}/{cache}vlv#{vlvname}.db'
535
536
537 def verify_keys_in_subdb(vlvname, inst, count):
538 """
539 Verify that vlv index as the expected number of keys.
540 """
541 dblib = get_default_db_lib()
542 dbfile = get_db_filename(vlvname, prefix=f'{inst.dbdir}/')
543 output = run_dbscan(['-D', dblib, '-f', dbfile])
544 # Count all lines except the MDB environment ones.
545 found = output.count('\n') - output.count('MDB environment')
546 if found != count:
547 log.info(f'Running: dbscan -D {dblib} -f "{dbfile}"')
548 log.info(f'dbscan output for vlv {vlvname} is: {output}')
549 assert found == count
550
551
552 def verify_vlv_subdb_names(vlvname, inst, count=None):
553 """
554 Verify that vlv index and cache sub database names are conistent on lmdb.
555 """
556 dblib = get_default_db_lib()
557 if dblib == "bdb":
558 # Let the time to sync bdb txn log to the db
559 prefix = ''
560 time.sleep(60)
561 else:
562 prefix = f'{inst.dbdir}/'
563 output = run_dbscan(['-D', dblib, '-L', inst.dbdir])
564 vlvsubdbs = []
565 nbvlvindex = 0
566 for line in output.split("\n"):
567 if not line:
568 continue
569 fname = line.split()[0]
570 if 'vlv#' in fname:
571 vlvsubdbs.append(fname)
572 if '/~recno-cache/' not in fname:
573 nbvlvindex += 1
574 log.info(f'vlv sub databases are: {vlvsubdbs}')
575
576 assert get_db_filename(vlvname, prefix=prefix) in vlvsubdbs
577 if dblib == "mdb":
578 assert get_db_filename(vlvname, prefix=prefix, iscache=True) in vlvsubdbs
579 assert len(vlvsubdbs) == 2 * nbvlvindex
580 else:
581 assert len(vlvsubdbs) == nbvlvindex
582 if count:
583 verify_keys_in_subdb(vlvname, inst, count)
584
585
586 def bootstrap_replication(M1, M2):
587 """
588 Setup a replication manager entry on M2 and update the
589 M1 -> M2 replication agreement to use it.
590 """
591 # Create a repl manager entry on M2
592 repl_manager_password = "Secret12"
593 brm = BootstrapReplicationManager(M2)
594 brm.create(properties={
595 'cn': brm.common_name,
596 'userPassword': repl_manager_password
597 })
598 # Let M1 -> M2 agreement use that entry
599 replica1 = Replicas(M1).get(DEFAULT_SUFFIX)
600 replica2 = Replicas(M2).get(DEFAULT_SUFFIX)
601 agmt = replica1.get_agreements().list()[0]
602 agmt.replace_many(("nsds5ReplicaBindDN", brm.dn),
603 ("nsds5ReplicaCredentials", repl_manager_password))
604 replica2.remove_all('nsDS5ReplicaBindDNGroup')
605 # Assign the entry to the replica
606 replica2.replace('nsDS5ReplicaBindDN', brm.dn)
607
608
609 def remove_database(inst):
610 # remove the database
611 inst.stop()
612 for file in glob.glob(f'{inst.dbdir}/*'):
613 if os.path.islink(file):
614 continue
615 if os.path.isfile(file):
616 os.remove(file)
617 if os.path.isdir(file):
618 rmtree(file)
619 inst.start()
620
621
622 @pytest.mark.skipif(get_default_db_lib() == "bdb", reason="Not supported over bdb")
623 def test_vlv_cache_subdb_names(topology_m2):
624 """
625 Testing that vlv index cache sub database name is consistent.
626
627 :id: 7a138006-aa24-11ee-9d5f-482ae39447e5
628 :setup: Replication with two suppliers.
629 :steps:
630 1. Generate vlvSearch and vlvIndex entries
631 2. Add users and wait that they get replicated.
632 3. Check subdb names and perform vlv searches
633 4. Destroy supplierr2 database and restart
634 5. Recreate M2 tree with a new user
635 6. Reinit M2 from M1
636 7. Check subdb names and perform vlv searches
637 :expectedresults:
638 1. Should Success.
639 2. Should Success.
640 3. Should Success.
641 4. Should Success.
642 5. Should Success.
643 6. Should Success.
644 7. Should Success.
645 """
646
647 NUM_USERS = 50
648 M1 = topology_m2.ms["supplier1"]
649 M2 = topology_m2.ms["supplier2"]
650 repl = ReplicationManager(DEFAULT_SUFFIX)
651
652 # Clean test_bulk_import_when_the_backend_with_vlv_was_recreated leftover that cause trouble
653 entries = [ UserAccount(M1, dn=f'uid=testuser{uid},DEFAULT_SUFFIX') for uid in
654 range(STARTING_UID_INDEX, STARTING_UID_INDEX+NUM_USERS) ]
655 entries.append(VLVIndex(M2, dn='cn=vlvIdx,cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config'))
656 entries.append(VLVSearch(M2, dn='cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config'))
657 for entry in entries:
658 if entry.exists():
659 entry.delete()
660 repl.wait_for_replication(M1, M2)
661 # Restart the instance to workaround https://github.com/389ds/389-ds-base/issues/6029
662 if get_default_db_lib() == "bdb":
663 M2.restart()
664
665 # generate vlvSearch and vlvIndex entries
666 vlv_search, vlv_index = create_vlv_search_and_index(M2)
667 vlvname = vlv_index.get_attr_val_utf8_l('cn')
668 assert "cn=vlvIdx,cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config" in M2.getEntry(
669 "cn=vlvIdx,cn=vlvSrch,cn=userRoot,cn=ldbm database,cn=plugins,cn=config").dn
670 reindex_task = Tasks(M2)
671 assert reindex_task.reindex(
672 suffix=DEFAULT_SUFFIX,
673 attrname=vlv_index.rdn,
674 args={TASK_WAIT: True},
675 vlv=True
676 ) == 0
677
678 # Add users and wait that they get replicated.
679 add_users(M1, NUM_USERS)
680 repl.wait_for_replication(M1, M2)
681
682 # Check subdb names and perform vlv searches
683 conn = open_new_ldapi_conn(M2.serverid)
684 count = len(conn.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(uid=*)"))
685 assert count > 0
686 check_vlv_search(conn, offset=23)
687 verify_vlv_subdb_names(vlvname, M2, count=count)
688
689 # Destroy the database and restart
690 # (Ensure that the db is really destroyed.
691 # Avoid getting tricked if database is not properly cleared by the reimport)
692 # by a double bug (index keys not properly reset)
693 M2.stop()
694 remove_database(M2)
695 M2.start()
696
697 # Recreate tree with a new user on M2 (To check that its key get removed)
698 # This user is not replicated towards M1 because the db has been
699 # recreated with a different generation number
700 Domain(M2, DEFAULT_SUFFIX).create(properties={'dc': 'example'})
701 OrganizationalUnits(M2, DEFAULT_SUFFIX).create(properties={'ou': 'People'})
702 users = UserAccounts(M2, DEFAULT_SUFFIX)
703 add_user(M2, users, 2*STARTING_UID_INDEX)
704 bootstrap_replication(M1, M2)
705
706 # Reinit M2 from M1
707 agmt = Agreements(M1).list()[0]
708 agmt.begin_reinit()
709 (done, error) = agmt.wait_reinit()
710 assert done is True
711 assert error is False
712
713 # Check subdb names and perform vlv searches
714 conn = open_new_ldapi_conn(M2.serverid)
715 count = len(conn.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(uid=*)"))
716 assert count > 0
717 check_vlv_search(conn, offset=23)
718 verify_vlv_subdb_names(vlvname, M2, count=count)
719
720
721 @contextmanager
722 def custom_dse(*args, **kwds):
723 """ A Constext manager to handle a special configuration.
724 That restores the original config when exiting out of the context.
725
726 Usage:
727 with custom_dse(inst) as newdsename, olddsename:
728 update(newdsename)
729 inst.start()
730 action ...
731 """
732 inst = args[0]
733 olddsename = f'{inst.ds_paths.config_dir}/dse.ldif.vlvtc1'
734 newdsename = f'{inst.ds_paths.config_dir}/dse.ldif'
735 inst.stop()
736 assert os.path.isfile(newdsename)
737 os.replace(newdsename, olddsename)
738 copyfile(olddsename, newdsename)
739 try:
740 yield (newdsename, olddsename)
741 finally:
742 inst.stop()
743 if os.path.isfile(olddsename):
744 os.remove(newdsename)
745 os.rename(olddsename, newdsename)
746 inst.start()
747
748
749 def test_vlv_start_with_bad_dse(topology_st):
750 """
751 Testing that server does not crash if dse.ldif is in disorder.
752
753 :id: ceb3e9e0-b607-11ee-845a-482ae39447e5
754 :setup: Standalone
755 :steps:
756 1. Append vlvIndex entries then vlvSearch entry in the dse.ldif
757 2. Restart the server
758 :expectedresults:
759 1. Should Success.
760 2. Should Success.
761 """
762 inst = topology_st.standalone
763 # Use a context to ensure that the instance config is restored and instance
764 # restarted at the end of the test.
765 with custom_dse(inst) as (newdsename, olddsename):
766 # Step 1: Append vlvIndex entries then vlvSearch entry in the dse.ldif
767 with open(newdsename, 'at') as dse:
768 dse.write(BAD_DSE_DATA)
769 # Step 2: Restart the server
770 inst.start()
771
772 @pytest.mark.skipif(get_default_db_lib() == "bdb", reason="bdb may hang because of github #6029")
773 @pytest.mark.parametrize("prefix", ( 'vlv', 'vl-v' ))
774 @pytest.mark.parametrize("basedn", ( DEFAULT_SUFFIX, f'ou=People,{DEFAULT_SUFFIX}' ))
775 def test_vlv_reindex(topology_st, prefix, basedn):
776 """Test VLV reindexing.
777
778 :id: d5dc0d8e-cbe6-11ee-95b1-482ae39447e5
779 :parametrized: yes
780 :setup: Standalone instance.
781 :steps:
782 1. Cleanup leftover from previous tests
783 2. Add users
784 3. Create new VLVs and do the reindex.
785 4. Test the new VLVs.
786 5. Restart the server and test again the VLVs
787 :expectedresults:
788 1. Should Success.
789 2. Should Success.
790 3. Should Success.
791 4. Should Success.
792 5. Should Success.
793 """
794
795 NUM_USERS = 50
796 inst = topology_st.standalone
797 reindex_task = Tasks(inst)
798
799 # Clean previous tests leftover that cause trouble
800 cleanup(inst)
801
802 add_users(inst, NUM_USERS)
803
804 # Create and reindex VLVs
805 vlv_search, vlv_index = create_vlv_search_and_index(inst, prefix=prefix, basedn=basedn)
806 assert reindex_task.reindex(
807 suffix=DEFAULT_SUFFIX,
808 attrname=vlv_index.rdn,
809 args={TASK_WAIT: True},
810 vlv=True
811 ) == 0
812
813 conn = open_new_ldapi_conn(inst.serverid)
814 count = len(conn.search_s(basedn, ldap.SCOPE_SUBTREE, "(uid=*)"))
815 assert count > 0
816 verify_vlv_subdb_names(vlv_index.rdn, inst, count=count)
817 check_vlv_search(conn, offset=23, basedn=basedn)
818
819 # Restart and check again
820 inst.restart()
821 conn = open_new_ldapi_conn(inst.serverid)
822 count = len(conn.search_s(basedn, ldap.SCOPE_SUBTREE, "(uid=*)"))
823 assert count > 0
824 verify_vlv_subdb_names(vlv_index.rdn, inst, count=count)
825 check_vlv_search(conn, offset=23, basedn=basedn)
826
827
828 @pytest.mark.skipif(get_default_db_lib() == "bdb", reason="bdb may hang because of github #6029")
829 @pytest.mark.parametrize("prefix", ( 'vlv', 'vl-v' ))
830 @pytest.mark.parametrize("basedn", ( DEFAULT_SUFFIX, f'ou=People,{DEFAULT_SUFFIX}' ))
831 def test_vlv_offline_import(topology_st, prefix, basedn):
832 """Test VLV after off line import.
833
834 :id: 8732d7a8-e851-11ee-9d63-482ae39447e5
835 :parametrized: yes
836 :setup: Standalone instance.
837 :steps:
838 1. Cleanup leftover from previous tests
839 2. Add users
840 3. Create new VLVs and do the reindex.
841 4. Test the new VLVs.
842 5. Export userRoot backend
843 6. Stop the instance
844 7. Perform off-line import
845 8. Restart instance and check the vlvs
846
847
848 :expectedresults:
849 1. Should Success.
850 2. Should Success.
851 3. Should Success.
852 4. Should Success.
853 5. Should Success.
854 6. Should Success.
855 7. Should Success.
856 8. Should Success.
857 """
858
859 NUM_USERS = 50
860 inst = topology_st.standalone
861 tasks = Tasks(inst)
862
863 # Clean previous tests leftover that cause trouble
864 cleanup(inst)
865
866 add_users(inst, NUM_USERS)
867
868 # Create and reindex VLVs
869 vlv_search, vlv_index = create_vlv_search_and_index(inst, prefix=prefix, basedn=basedn)
870 assert tasks.reindex(
871 suffix=DEFAULT_SUFFIX,
872 attrname=vlv_index.rdn,
873 args={TASK_WAIT: True},
874 vlv=True
875 ) == 0
876
877 conn = open_new_ldapi_conn(inst.serverid)
878 count = len(conn.search_s(basedn, ldap.SCOPE_SUBTREE, "(uid=*)"))
879 assert count > 0
880 verify_vlv_subdb_names(vlv_index.rdn, inst, count=count)
881 check_vlv_search(conn, offset=23, basedn=basedn)
882
883 # Export to ldif
884 ldif = f'{inst.get_ldif_dir()}/db.ldif'
885 assert tasks.exportLDIF(
886 suffix=DEFAULT_SUFFIX,
887 output_file=ldif,
888 args={TASK_WAIT: True}
889 ) == 0
890
891 # Perform off-line import
892 inst.stop()
893 assert inst.ldif2db('userRoot', None, None, None, ldif)
894
895 # Restart and check again the vlv
896 inst.start()
897 conn = open_new_ldapi_conn(inst.serverid)
898 count = len(conn.search_s(basedn, ldap.SCOPE_SUBTREE, "(uid=*)"))
899 assert count > 0
900 verify_vlv_subdb_names(vlv_index.rdn, inst, count=count)
901 check_vlv_search(conn, offset=23, basedn=basedn)
902
903
904 def test_vlv_as_freeipa_backup_restore(freeipa):
905 """Test vlv as if freeipa restore was performed.
906
907 :id: fb0621da-e879-11ee-900e-482ae39447e5
908 :setup: Standalone instance with freeipa test config.
909 :steps:
910 1. Check that standard search returns 16 valid certificate
911 2. Check that vlv search returns 16 valid certificate
912
913 :expectedresults:
914 1. Should Success.
915 2. Should Success.
916 """
917
918 DATE_LIMIT = '20260323135138Z'
919 EXPECTED_COUNT = 12
920 inst = freeipa.standalone
921 inst.restart()
922 conn = open_new_ldapi_conn(inst.serverid)
923 basedn = 'ou=certificateRepository,ou=ca,o=ipaca'
924 count = len(conn.search_s(basedn, ldap.SCOPE_SUBTREE, f"(&(certStatus=VALID)(notAfter<={DATE_LIMIT}))"))
925 assert count == EXPECTED_COUNT
926
927 vlv_control = VLVRequestControl(criticality=True,
928 before_count=200,
929 after_count=0,
930 offset=None,
931 content_count=None,
932 greater_than_or_equal='20260323135138Z',
933 context_id=None)
934
935 sss_control = SSSRequestControl(criticality=True, ordering_rules=['notAfter'])
936 result = conn.search_ext_s(
937 base=basedn,
938 scope=ldap.SCOPE_SUBTREE,
939 filterstr='(certStatus=VALID)',
940 serverctrls=[vlv_control, sss_control]
941 )
942 assert len(result) == EXPECTED_COUNT
943
944
945 def test_vlv_scope_one_on_two_backends(vlv_setup_with_two_backend):
946 """Test one level scoped vlv on two backends.
947
948 :id: 7652a2ea-eab0-11ee-891f-482ae39447e5
949 :setup: Standalone instance with two backens and one level scoped vlv
950 :steps:
951 1. Check that standard search returns 16 valid certificate
952 2. Check that vlv search returns 16 valid certificate
953
954 :expectedresults:
955 1. Should Success.
956 2. Should Success.
957 """
958 inst = vlv_setup_with_two_backend.standalone
959 tasks = Tasks(inst)
960 conn = open_new_ldapi_conn(inst.serverid)
961 assert len(conn.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(uid=*)")) > 0
962 # Check that vlv are working as excpected
963 for tmpd in vlv_setup_with_two_backend.belist:
964 if 'vlv_index' in tmpd:
965 check_vlv_search(conn, offset=6, basedn=tmpd['suffix'])
966
967 # Export userRoot backend
968 ldif = f'{inst.get_ldif_dir()}/db.ldif'
969 assert tasks.exportLDIF(
970 suffix=DEFAULT_SUFFIX,
971 output_file=ldif,
972 args={TASK_WAIT: True}
973 ) == 0
974 # Remove the db
975 remove_database(inst)
976 conn = open_new_ldapi_conn(inst.serverid)
977 # Check that vlv are broken
978 for tmpd in vlv_setup_with_two_backend.belist:
979 if 'vlv_index' in tmpd:
980 with pytest.raises(ldap.NO_SUCH_OBJECT):
981 check_vlv_search(conn, offset=6, basedn=tmpd['suffix'])
982 # Reimport the backends
983 for tmpd in vlv_setup_with_two_backend.belist:
984 assert tasks.importLDIF(
985 suffix=tmpd['suffix'],
986 input_file=tmpd['ldif'],
987 args={TASK_WAIT: True}, ) == 0
988 # Check that vlv are working as excpected
989 for tmpd in vlv_setup_with_two_backend.belist:
990 if 'vlv_index' in tmpd:
991 check_vlv_search(conn, offset=6, basedn=tmpd['suffix'])
992
993
994 def test_vlv_by_keyword(freeipa):
995 """Test vlv search by keyword instead of by range
996
997 :id: 0e74bbf6-f5c6-11ee-b086-482ae39447e5
998 :setup: Standalone instance with freeipa test config.
999 :steps:
1000 1. Perform a vlv search returning the six entries with
1001 highest serialno that is lesser or equal than "0210"
1002 2. Check that the 6 expected entries are returned.
1003 :expectedresults:
1004 1. Should Success.
1005 2. Should Success.
1006 """
1007
1008 inst = freeipa.standalone
1009 conn = open_new_ldapi_conn(inst.serverid)
1010 basedn = 'ou=certificateRepository,ou=ca,o=ipaca'
1011
1012 vlv_control = VLVRequestControl(criticality=True,
1013 before_count=5,
1014 after_count=0,
1015 offset=None,
1016 content_count=None,
1017 greater_than_or_equal='0211',
1018 context_id=None)
1019
1020 sss_control = SSSRequestControl(criticality=True, ordering_rules=['serialno'])
1021 result = conn.search_ext_s(
1022 base=basedn,
1023 scope=ldap.SCOPE_ONELEVEL,
1024 filterstr='(certStatus=*)',
1025 serverctrls=[vlv_control, sss_control]
1026 )
1027 assert len(result) == 6
1028 dns = [ dn for dn,entry in result ]
1029 for idx in range(6,12):
1030 assert f'cn={idx},ou=certificateRepository,ou=ca,o=ipaca' in dns
1031
1032
1033 def get_timestamp_attr():
1034 current_datetime = datetime.now()
1035 return f'tsattr-{current_datetime.timestamp()}'.replace(".", "-")
1036
1037
1038 def perform_vlv_search(conn, alog, basedn, vlvcrit=True, ssscrit=True, scope=ldap.SCOPE_SUBTREE, sss='cn', filter='(uid=*)'):
1039 timestamp = get_timestamp_attr()
1040 vlv_control = VLVRequestControl(criticality=vlvcrit,
1041 before_count=1,
1042 after_count=1,
1043 offset=4,
1044 content_count=0,
1045 greater_than_or_equal=None,
1046 context_id=None)
1047
1048 sss_control = SSSRequestControl(criticality=ssscrit, ordering_rules=[sss])
1049 log.info(f'perform_vlv_search: basedn={basedn} ={vlvcrit} ssscrit={ssscrit} sss={sss} filter={filter} timestamp={timestamp}')
1050
1051 with suppress(ldap.LDAPError):
1052 result = conn.search_ext_s(
1053 base=basedn,
1054 scope=scope,
1055 filterstr=filter,
1056 attrlist=[timestamp],
1057 serverctrls=[vlv_control, sss_control]
1058 )
1059 line = alog.match(f'.*SRCH.*{timestamp}.*')
1060 log.info(f'perform_vlv_search: line={line}')
1061 match = re.match(r'.*conn=(\d+) op=(\d+).*', line[0])
1062 conn,op = match.group(1,2)
1063 log.info(f'perform_vlv_search: conn={conn} op={op} ')
1064 lines = ''.join(alog.match(f'.*conn={conn} op={op} .*', after_pattern=f'.*{timestamp}.*'))
1065 log.info(f'perform_vlv_search: lines={lines}')
1066 return lines
1067
1068
1069 def test_vlv_logs(vlv_setup_nested_backends):
1070 """Test than VLV abd SORT lines are properply written
1071
1072 :id: a1d9ad9e-7cbb-11ef-82e3-083a88554478
1073 :setup: Standalone instance with two backens and one level scoped vlv
1074 :steps:
1075 1. Check that standard search returns 16 valid certificate
1076 2. Check that vlv search returns 16 valid certificate
1077
1078 :expectedresults:
1079 1. Should Success.
1080 2. Should Success.
1081 """
1082 inst = vlv_setup_nested_backends.standalone
1083 beh = vlv_setup_nested_backends.beh
1084 tasks = Tasks(inst)
1085 conn = open_new_ldapi_conn(inst.serverid)
1086 conn_demo = open_new_ldapi_conn(inst.serverid)
1087 alog = DirsrvAccessLog(inst)
1088 dn1 = beh.data['be1']['dn']
1089 dn2 = beh.data['be2']['dn']
1090 suffix1 = beh.data['be1']['suffix']
1091 suffix2 = beh.data['be2']['suffix']
1092 conn_demo.bind_s(dn2, DEMO_PW)
1093
1094 VLV_FEATURE_DN = 'oid=2.16.840.1.113730.3.4.9,cn=features,cn=config'
1095 VLV_DEFAULT_ACI = b'(targetattr != "aci")(version 3.0; acl "VLV Request Control"; ' + \
1096 b'allow( read , search, compare, proxy ) userdn = "ldap:///all";)'
1097 VLV_DENY_ACI = b'(targetattr != "aci")(version 3.0; acl "VLV Request Control"; ' + \
1098 f'deny( read , search, compare, proxy ) userdn = "ldap:///{dn2}";)'.encode('utf8')
1099
1100 # Set VLV feature ACI
1101 mod = (ldap.MOD_REPLACE, 'aci', [ VLV_DEFAULT_ACI, VLV_DENY_ACI ])
1102 conn.modify_s(VLV_FEATURE_DN, [mod,])
1103
1104 # Invalid ACL
1105 res = perform_vlv_search(conn_demo, alog, suffix2)
1106 assert 'SORT' in res
1107 assert 'VLV' in res
1108 assert 'err=50 ' in res
1109
1110 # Sucessful VLV
1111 res = perform_vlv_search(conn, alog, suffix2)
1112 assert 'SORT' in res
1113 assert 'VLV' in res
1114 assert 'err=0 ' in res
1115
1116 # Multiple backends SSS and VLV are critical
1117 res = perform_vlv_search(conn, alog, suffix1)
1118 assert 'SORT' in res
1119 assert 'VLV' in res
1120 assert 'err=76 ' in res
1121
1122 # Multiple backends SSS is critical VLV is not critical
1123 res = perform_vlv_search(conn, alog, suffix1, vlvcrit=False)
1124 assert 'SORT' in res
1125 assert 'VLV' in res
1126 assert 'err=12 ' in res
1127
1128 # Multiple backends SSS and VLV are not critical
1129 res = perform_vlv_search(conn, alog, suffix1, vlvcrit=False, ssscrit=False)
1130 assert 'SORT' in res
1131 assert 'VLV' in res
1132 assert 'err=0 ' in res
1133
1134
1135 def test_vlv_with_mr(vlv_setup_with_uid_mr):
1136 """
1137 Testing vlv having specific matching rule
1138
1139 :id: 5e04afe2-beec-11ef-aa84-482ae39447e5
1140 :setup: Standalone with uid have a matching rule index
1141 :steps:
1142 1. Append vlvIndex entries then vlvSearch entry in the dse.ldif
1143 2. Restart the server
1144 :expectedresults:
1145 1. Should Success.
1146 2. Should Success.
1147 """
1148 inst = vlv_setup_with_uid_mr.standalone
1149 beh = vlv_setup_with_uid_mr.beh
1150 bename, besuffix = next(iter(beh.bedict.items()))
1151 vlv_searches, vlv_index = create_vlv_search_and_index(
1152 inst, basedn=besuffix, bename=bename,
1153 vlvsort="uid:2.5.13.2")
1154 # Reindex the vlv
1155 reindex_task = Tasks(inst)
1156 assert reindex_task.reindex(
1157 suffix=besuffix,
1158 attrname=vlv_index.rdn,
1159 args={TASK_WAIT: True},
1160 vlv=True
1161 ) == 0
1162
1163 inst.restart()
1164 users = UserAccounts(inst, besuffix)
1165 user_properties = {
1166 'uid': f'a new testuser',
1167 'cn': f'a new testuser',
1168 'sn': 'user',
1169 'uidNumber': '0',
1170 'gidNumber': '0',
1171 'homeDirectory': 'foo'
1172 }
1173 user = users.create(properties=user_properties)
1174 user.delete()
1175 assert inst.status()
1176
1177
1178
1179 @pytest.mark.skipif(get_default_db_lib() == "bdb", reason="Hangs on BDB")
1180 def test_vlv_long_attribute_value(topology_st, request):
1181 """
1182 Test VLV with an entry containing a very long attribute value (2K).
1183
1184 :id: 99126fa4-003e-11f1-b7d6-c85309d5c3e3
1185 :setup: Standalone instance.
1186 :steps:
1187 1. Cleanup leftover from previous tests
1188 2. Create VLV search and index on cn attribute
1189 3. Reindex VLV
1190 4. Add an entry with a cn attribute having 2K character value
1191 5. Verify the entry was added successfully
1192 6. Perform a VLV search to ensure it still works
1193 7. Add another entry with a cn attribute having 2K character value
1194 8. Verify the entry was added successfully
1195 9. Perform a VLV search to ensure it still works
1196 :expectedresults:
1197 1. Should Success.
1198 2. Should Success.
1199 3. Should Success.
1200 4. Should Success.
1201 5. Should Success.
1202 6. Should Success.
1203 7. Should Success.
1204 8. Should Success.
1205 9. Should Success.
1206 """
1207 inst = topology_st.standalone
1208 reindex_task = Tasks(inst)
1209
1210 users_to_delete = []
1211
1212 def fin():
1213 cleanup(inst)
1214 # Clean the added users
1215 for user in users_to_delete:
1216 user.delete()
1217
1218 if not DEBUGGING:
1219 request.addfinalizer(fin)
1220
1221 # Clean previous tests leftover
1222 fin()
1223
1224 # Create VLV search and index
1225 vlv_search, vlv_index = create_vlv_search_and_index(inst)
1226 assert reindex_task.reindex(
1227 suffix=DEFAULT_SUFFIX,
1228 attrname=vlv_index.rdn,
1229 args={TASK_WAIT: True},
1230 vlv=True
1231 ) == 0
1232
1233 # Add a few regular users first
1234 add_users(inst, 10)
1235
1236 # Create a very long cn value (2K characters)
1237 long_cn_value = 'a' * 2048 + '1'
1238
1239 # Add an entry with the long cn attribute
1240 users = UserAccounts(inst, DEFAULT_SUFFIX)
1241 user_properties = {
1242 'uid': 'longcnuser1',
1243 'cn': long_cn_value,
1244 'sn': 'user1',
1245 'uidNumber': '99999',
1246 'gidNumber': '99999',
1247 'homeDirectory': '/home/longcnuser1'
1248 }
1249 user = users.create(properties=user_properties)
1250 users_to_delete.append(user);
1251
1252 # Verify the entry was created and has the long cn value
1253 entry = user.get_attr_vals_utf8('cn')
1254 assert entry[0] == long_cn_value
1255 log.info(f'Successfully created user with cn length: {len(entry[0])}')
1256
1257 # Perform VLV search to ensure VLV still works with long attribute values
1258 conn = open_new_ldapi_conn(inst.serverid)
1259 count = len(conn.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(uid=*)"))
1260 assert count > 0
1261 log.info(f'VLV search successful with {count} entries including entry with 2K cn value')
1262
1263 # Add another entry with the long cn attribute
1264 long_cn_value = 'a' * 2048 + '2'
1265
1266 user_properties = {
1267 'uid': 'longcnuser2',
1268 'cn': long_cn_value,
1269 'sn': 'user2',
1270 'uidNumber': '99998',
1271 'gidNumber': '99998',
1272 'homeDirectory': '/home/longcnuser2'
1273 }
1274 user = users.create(properties=user_properties)
1275 users_to_delete.append(user);
1276
1277 # Verify the entry was created and has the long cn value
1278 entry = user.get_attr_vals_utf8('cn')
1279 assert entry[0] == long_cn_value
1280 log.info(f'Successfully created user with cn length: {len(entry[0])}')
1281
1282 # Perform VLV search to ensure VLV still works with long attribute values
1283 conn = open_new_ldapi_conn(inst.serverid)
1284 count = len(conn.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "(uid=*)"))
1285 assert count > 1
1286 log.info(f'VLV search successful with {count} entries including entry with 2K cn value')
1287
1288
1289
1290 if __name__ == "__main__":
1291 # Run isolated
1292 # -s for DEBUG mode
1293 CURRENT_FILE = os.path.realpath(__file__)
1294 pytest.main("-s %s" % CURRENT_FILE)