Debian Codegraph @

dirsrvtests/tests/suites/indexes/huge_index_key_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 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 time
10 import os
11 import pytest
12 import ldap
13 import logging
14 from lib389._constants import DEFAULT_BENAME, DEFAULT_SUFFIX
15 from lib389.index import Indexes
16 from lib389.backend import Backends, DatabaseConfig
17 from lib389.idm.user import UserAccounts
18 from lib389.idm.group import Groups, Group
19 from test389.topologies import topology_st as topo
20 from lib389.utils import ds_is_older, get_default_db_lib
21 from lib389.plugins import MemberOfPlugin
22 from lib389 import DirSrv
23 pytestmark = pytest.mark.tier1
24
25 DEBUGGING = os.getenv("DEBUGGING", default=False)
26 if DEBUGGING:
27 logging.getLogger(__name__).setLevel(logging.DEBUG)
28 else:
29 logging.getLogger(__name__).setLevel(logging.INFO)
30 log = logging.getLogger(__name__)
31
32 users_list = []
33
34 @pytest.fixture(scope="function")
35 def add_users(request, topo):
36 """
37 Add users
38 """
39 users_num = 200
40 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn=None)
41 for num in range(users_num):
42 USER_NAME = "test_{:0>3d}".format( num )
43 user = users.create(properties={
44 'uid': USER_NAME,
45 'sn': USER_NAME,
46 'cn': USER_NAME,
47 'uidNumber': f'{num}',
48 'gidNumber': f'{num}',
49 'homeDirectory': f'/home/{USER_NAME}'
50 })
51 users_list.append(user)
52
53 def fin():
54 """
55 Removes users.
56 """
57 if not topo.standalone.status():
58 topo.standalone.start()
59 for user in users_list:
60 user.delete()
61
62 request.addfinalizer(fin)
63
64
65 def test_huge_index_key(topo, add_users):
66 """
67 Test very long indexed attribute values (that should be hashed on mdb)
68
69 :id: 4bbd0ee2-0108-11ec-a5ce-482ae39447e5
70 :customerscenario: False
71 :setup: Standalone instance
72 :steps:
73 1. Add users
74 2. Change nsslapd-idlistscanlimit to a smaller value to accelerate the reproducer
75 3. Replace sn with a 600 bytes value
76 4. equality search for the sn
77 5. Range search including the sn
78 6. Replace sn back with small value
79 7. equality search for the sn
80 8. Range search including the sn
81 :expectedresults:
82 1. Should succeed
83 2. Should succeed
84 3. Should succeed
85 4. Should succeed and have exactly 1 result
86 search should be indexed.
87 5. Should succeed and have exactly 3 results
88 on bdb: search should be indexed.
89 on mdb: search should be unindexed.
90 6. Should succeed
91 7. Should succeed and have exactly 1 result
92 search should be indexed.
93 8. Should succeed and have exactly 3 results
94 search should be indexed.
95 """
96 inst = topo.standalone
97 ldc = super(DirSrv, inst); # ldap connection to be able to use
98 # the SimpleLDAPObject methods
99 shortsn='test_020'
100 test_user=users_list[20]
101 log.debug(f'Check user {test_user} sn: {test_user.get_attr_val_utf8("sn")}')
102 assert(test_user)
103
104 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn=None)
105 log.debug(f'Check users {users.list()}')
106
107 sn600b = shortsn + \
108 "0001abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz" + \
109 "0002abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz" + \
110 "0003abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz" + \
111 "0004abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz" + \
112 "0005abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz" + \
113 "0006abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz" + \
114 "0007abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz" + \
115 "0008abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz" + \
116 "0009abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz" + \
117 "0010abcdefghijklmnopqrstuvwxyz0001abcdefghijklmnopqrstuvwxyz"
118
119 test_user.replace('sn', sn600b);
120 result = ldc.search_s(base=DEFAULT_SUFFIX, scope=ldap.SCOPE_SUBTREE, filterstr=f'(sn={sn600b})')
121 assert (len(result) == 1)
122 assert (not inst.searchAccessLog("notes=U"))
123 result = ldc.search_s(base=DEFAULT_SUFFIX, scope=ldap.SCOPE_SUBTREE, filterstr=f'(&(sn>=test_019)(sn<=test_021))')
124 #with pytest.raises(ldap.INVALID_SYNTAX):
125 assert (len(result) == 3)
126 if (get_default_db_lib() == "bdb"):
127 assert (not inst.searchAccessLog("notes=U"))
128 else:
129 assert (inst.searchAccessLog("notes=U"))
130 inst.deleteLog(inst.accesslog);
131 test_user.replace('sn', shortsn);
132 result = ldc.search_s(base=DEFAULT_SUFFIX, scope=ldap.SCOPE_SUBTREE, filterstr=f'(sn={shortsn})')
133 assert (len(result) == 1)
134 assert (not inst.searchAccessLog("notes=U"))
135 result = ldc.search_s(base=DEFAULT_SUFFIX, scope=ldap.SCOPE_SUBTREE, filterstr=f'(&(sn>=test_019)(sn<=test_021))')
136 assert (len(result) == 3)
137 assert (not inst.searchAccessLog("notes=U"))
138
139
140 if __name__ == "__main__":
141 # Run isolated
142 # -s for DEBUG mode
143 CURRENT_FILE = os.path.realpath(__file__)
144 pytest.main("-s %s" % CURRENT_FILE)