| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2019 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 |
""" |
| 10 |
This script will test different type of Filers. |
| 11 |
""" |
| 12 |
|
| 13 |
import os |
| 14 |
import ldap |
| 15 |
import pytest |
| 16 |
|
| 17 |
from lib389._constants import DEFAULT_SUFFIX, PW_DM |
| 18 |
from test389.topologies import topology_st as topo |
| 19 |
from lib389.idm.user import UserAccounts |
| 20 |
from lib389.idm.organizationalunit import OrganizationalUnits |
| 21 |
from lib389.index import Index |
| 22 |
from lib389.idm.account import Accounts |
| 23 |
from lib389.idm.group import UniqueGroups |
| 24 |
from lib389.utils import ds_is_older |
| 25 |
|
| 26 |
pytestmark = pytest.mark.tier1 |
| 27 |
|
| 28 |
GIVEN_NAME = 'cn=givenname,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config' |
| 29 |
CN_NAME = 'cn=sn,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config' |
| 30 |
UNIQMEMBER = 'cn=uniquemember,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config' |
| 31 |
OBJECTCLASS = 'cn=objectclass,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config' |
| 32 |
MAIL = 'cn=mail,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config' |
| 33 |
ACLG_OU = f'ou=ACLGroup,{DEFAULT_SUFFIX}' |
| 34 |
NESG_OU = f'ou=nestedgroup, {DEFAULT_SUFFIX}' |
| 35 |
|
| 36 |
LIST_OF_USER_ACCOUNTING = [ |
| 37 |
"Ted Morris", |
| 38 |
"David Miller", |
| 39 |
"Gern Farmer", |
| 40 |
"Judy Wallace", |
| 41 |
"Marcus Ward", |
| 42 |
"Judy McFarland", |
| 43 |
"Gern Triplett", |
| 44 |
"Emanuel Johnson", |
| 45 |
"Brad Walker", |
| 46 |
"Tobias Pierce", |
| 47 |
"Randy Mills", |
| 48 |
"David Thorud", |
| 49 |
"Elba Kohler", |
| 50 |
"Laurel Campbell", |
| 51 |
"Torrey Schneider", |
| 52 |
"Paula Rose", |
| 53 |
"Frank Albers", |
| 54 |
"Martin Schneider", |
| 55 |
"Andrew Hel", |
| 56 |
"Pete Tyler", |
| 57 |
"Randy Ulrich", |
| 58 |
"Richard Francis", |
| 59 |
"Morgan White", |
| 60 |
"Jody Jensen", |
| 61 |
"Mike Carter", |
| 62 |
"Gern Tyler", |
| 63 |
"Bjorn Jensen", |
| 64 |
"Andy Hall", |
| 65 |
"Ted Jensen", |
| 66 |
"Wendy Lutz", |
| 67 |
"Kelly Mcinnis", |
| 68 |
"Trent Couzens", |
| 69 |
"Dan Lanoway", |
| 70 |
"Richard Jensen"] |
| 71 |
|
| 72 |
LIST_OF_USER_HUMAN = [ |
| 73 |
"Kirsten Vaughan", |
| 74 |
"Chris Schmith", |
| 75 |
"Torrey Clow", |
| 76 |
"Robert Daugherty", |
| 77 |
"Torrey Mason", |
| 78 |
"Brad Talbot", |
| 79 |
"Jeffrey Campaigne", |
| 80 |
"Stephen Triplett", |
| 81 |
"John Falena", |
| 82 |
"Peter Rigden", |
| 83 |
"Mike Lott", |
| 84 |
"Richard Bannister", |
| 85 |
"Brian Plante", |
| 86 |
"Daniel Smith", |
| 87 |
"Tim Labonte", |
| 88 |
"Scott Lee", |
| 89 |
"Bjorn Free", |
| 90 |
"Alexander Shelton", |
| 91 |
"James Burrell", |
| 92 |
"Karen Carter", |
| 93 |
"Randy Fish", |
| 94 |
"Philip Hunt", |
| 95 |
"Rachel Schneider", |
| 96 |
"Gern Jensen", |
| 97 |
"David Akers", |
| 98 |
"Tobias Ward", |
| 99 |
"Jody Rentz", |
| 100 |
"Peter Lorig", |
| 101 |
"Kelly Schmith", |
| 102 |
"Pete Worrell", |
| 103 |
"Matthew Reuter", |
| 104 |
"Tobias Schmith", |
| 105 |
"Jon Goldstein", |
| 106 |
"Janet Lutz", |
| 107 |
"Karl Cope"] |
| 108 |
|
| 109 |
LIST_OF_USER_TESTING = [ |
| 110 |
"Andy Bergin", |
| 111 |
"John Walker", |
| 112 |
"Jayne Reuter", |
| 113 |
"Lee Ulrich", |
| 114 |
"Benjamin Schneider", |
| 115 |
"Bertram Rentz", |
| 116 |
"Patricia Cruse", |
| 117 |
"Jim Lange", |
| 118 |
"Alan White", |
| 119 |
"Daniel Ward", |
| 120 |
"Lee Stockton", |
| 121 |
"Matthew Vaughan"] |
| 122 |
|
| 123 |
LIST_OF_USER_DEVELOPMENT = [ |
| 124 |
"Kelly Winters", |
| 125 |
"Torrey Rigden", |
| 126 |
"Benjamin Hall", |
| 127 |
"Lee Labonte", |
| 128 |
"Jody Campaigne", |
| 129 |
"Alexander Lutz", |
| 130 |
"Bjorn Talbot", |
| 131 |
"Marcus Langdon", |
| 132 |
"Sue Peterson", |
| 133 |
"Kurt Jensen", |
| 134 |
"Cecil Wallace", |
| 135 |
"Stephen Carter", |
| 136 |
"Janet Hunter", |
| 137 |
"Marcus Mcinnis", |
| 138 |
"Timothy Kelly", |
| 139 |
"Sue Mason", |
| 140 |
"Chris Alexander", |
| 141 |
"Martin Talbot", |
| 142 |
"Scott Farmer", |
| 143 |
"Allison Jensen", |
| 144 |
"Jeff Muffly", |
| 145 |
"Alan Worrell", |
| 146 |
"Dan Langdon", |
| 147 |
"Ashley Knutson", |
| 148 |
"Jon Bourke", |
| 149 |
"Pete Hunt"] |
| 150 |
|
| 151 |
LIST_OF_USER_PAYROLL = [ |
| 152 |
"Ashley Chassin", |
| 153 |
"Sue Kelleher", |
| 154 |
"Jim Cruse", |
| 155 |
"Judy Brown", |
| 156 |
"Patricia Shelton", |
| 157 |
"Dietrich Swain", |
| 158 |
"Allison Hunter", |
| 159 |
"Anne-Louise Barnes"] |
| 160 |
|
| 161 |
LIST_OF_USER_PEOPLE = [ |
| 162 |
'Sam Carter', |
| 163 |
'Tom Morris', |
| 164 |
'Kevin Vaughan', |
| 165 |
'Rich Daugherty', |
| 166 |
'Harry Miller', |
| 167 |
'Sam Schmith'] |
| 168 |
|
| 169 |
@pytest.mark.xfail(ds_is_older('1.4.4'), reason="https://github.com/389ds/389-ds-base/issues/3260") |
| 170 |
def test_invalid_configuration(topo): |
| 171 |
""""Error handling for invalid configuration |
| 172 |
Starting...test cases for bug1011539 |
| 173 |
Index config error handling does not exist - you can add any old thing |
| 174 |
|
| 175 |
:id: 377950f6-9f06-11e8-831b-8c16451d917b |
| 176 |
:setup: Standalone instance |
| 177 |
:steps: |
| 178 |
1. Try change nsIndexIDListScanLimit |
| 179 |
:expectedresults: |
| 180 |
1. This should pass |
| 181 |
""" |
| 182 |
for i in ['4000', |
| 183 |
'limit=0 flags=bogus', |
| 184 |
'limit=0 limit=1', |
| 185 |
'limit=0 type=eq type=eq', |
| 186 |
'limit=0 type=sub type=eq', |
| 187 |
'limit=0 flags=AND flags=AND', |
| 188 |
'limit=0 type=eq values=foo values=foo', |
| 189 |
'limit=0 type=eq values=foo,foo', |
| 190 |
'limit', |
| 191 |
'limit=0 type=pres values=bogus', |
| 192 |
'limit=0 type=eq,sub values=bogus', |
| 193 |
'limit=', |
| 194 |
'limit=1 type=', |
| 195 |
'limit=1 flags=', |
| 196 |
'limit=1 type=eq values=', |
| 197 |
'limit=-2', |
| 198 |
'type=eq', |
| 199 |
'limit=0 type=bogus']: |
| 200 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM): |
| 201 |
Index(topo.standalone, GIVEN_NAME).replace('nsIndexIDListScanLimit', i) |
| 202 |
|
| 203 |
|
| 204 |
def test_idlistscanlimit(topo): |
| 205 |
"""Test various combinations of filters and idlistscanlimit |
| 206 |
|
| 207 |
:id: 44f83e2c-9f06-11e8-bffe-8c16451d917b |
| 208 |
:setup: Standalone instance |
| 209 |
:steps: |
| 210 |
1. Create entries |
| 211 |
2. Try change nsslapd-errorlog-level |
| 212 |
3. Test nsIndexIDListScanLimit values |
| 213 |
4. Search created entries |
| 214 |
5. restart instance |
| 215 |
6. Search created entries |
| 216 |
7. indexing works after restart |
| 217 |
:expectedresults: |
| 218 |
1. This should pass |
| 219 |
2. This should pass |
| 220 |
3. This should pass |
| 221 |
4. This should pass |
| 222 |
5. This should pass |
| 223 |
6. This should pass |
| 224 |
7. This should pass |
| 225 |
""" |
| 226 |
ous = OrganizationalUnits(topo.standalone, DEFAULT_SUFFIX) |
| 227 |
for demo in ['Product Development', |
| 228 |
'Accounting', |
| 229 |
'Human Resources', |
| 230 |
'Payroll', |
| 231 |
'Product Testing']: |
| 232 |
ous.create(properties={'ou': demo}) |
| 233 |
|
| 234 |
users_accounts = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=Accounting') |
| 235 |
users_human = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=Human Resources') |
| 236 |
users_testing = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=Product Testing') |
| 237 |
users_development = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=Product Development') |
| 238 |
users_payroll = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=Payroll') |
| 239 |
users_people = UserAccounts(topo.standalone, DEFAULT_SUFFIX) |
| 240 |
|
| 241 |
for data in [(LIST_OF_USER_ACCOUNTING, users_accounts), |
| 242 |
(LIST_OF_USER_HUMAN, users_human), |
| 243 |
(LIST_OF_USER_TESTING, users_testing), |
| 244 |
(LIST_OF_USER_DEVELOPMENT, users_development), |
| 245 |
(LIST_OF_USER_PAYROLL, users_payroll), |
| 246 |
(LIST_OF_USER_PEOPLE, users_people)]: |
| 247 |
for demo1 in data[0]: |
| 248 |
fn = demo1.split()[0] |
| 249 |
sn = demo1.split()[1] |
| 250 |
uid = ''.join([fn[:1], sn]).lower() |
| 251 |
data[1].create(properties={ |
| 252 |
'uid': uid, |
| 253 |
'cn': demo1, |
| 254 |
'sn': sn, |
| 255 |
'uidNumber': str(1000), |
| 256 |
'gidNumber': '2000', |
| 257 |
'homeDirectory': f'/home/{uid}', |
| 258 |
'givenname': fn, |
| 259 |
'userpassword': PW_DM, |
| 260 |
'mail': f'{uid}@test.com' |
| 261 |
}) |
| 262 |
|
| 263 |
try: |
| 264 |
# Change log levels |
| 265 |
errorlog_value = topo.standalone.config.get_attr_val_utf8('nsslapd-errorlog-level') |
| 266 |
topo.standalone.config.set('nsslapd-errorlog-level', '524288') |
| 267 |
|
| 268 |
# Test nsIndexIDListScanLimit values |
| 269 |
for i in ['limit=1 type=eq values=Lutz,Hunter', |
| 270 |
'limit=2 type=eq flags=AND values=Jensen,Rentz', |
| 271 |
'limit=3 type=eq flags=AND', |
| 272 |
'limit=4 type=eq', 'limit=5 flags=AND', |
| 273 |
'limit=6', |
| 274 |
'limit=1 type=sub values=*utz,*ter', |
| 275 |
'limit=4 type=sub', |
| 276 |
'limit=2 type=sub flags=AND values=*sen,*ntz', |
| 277 |
'limit=3 type=sub flags=AND', |
| 278 |
'limit=5 type=sub values=*sch*']: |
| 279 |
Index(topo.standalone, CN_NAME).replace('nsIndexIDListScanLimit', i) |
| 280 |
|
| 281 |
for i in ['limit=1 type=eq values=Andy,Andrew', |
| 282 |
'limit=2 type=eq flags=AND values=Bjorn,David', |
| 283 |
'limit=3 type=eq flags=AND', |
| 284 |
'limit=4 type=eq', |
| 285 |
'limit=5 flags=AND', |
| 286 |
'limit=6']: |
| 287 |
Index(topo.standalone, GIVEN_NAME).replace('nsIndexIDListScanLimit', i) |
| 288 |
|
| 289 |
Index(topo.standalone, UNIQMEMBER).\ |
| 290 |
replace('nsIndexIDListScanLimit', |
| 291 |
'limit=0 type=eq values=uid=kvaughan\2Cou=People\2Cdc=example\2Cdc=com,' |
| 292 |
'uid=rdaugherty\2Cou=People\2Cdc=example\2Cdc=com') |
| 293 |
|
| 294 |
Index(topo.standalone, OBJECTCLASS).\ |
| 295 |
replace('nsIndexIDListScanLimit', 'limit=0 type=eq flags=AND values=inetOrgPerson') |
| 296 |
|
| 297 |
# Search with filter |
| 298 |
for i in ['(sn=Lutz)', |
| 299 |
'(sn=*ter)', |
| 300 |
'(&(sn=*sen)(objectclass=organizationalPerson))', |
| 301 |
'(&(objectclass=organizationalPerson)(sn=*ntz))', |
| 302 |
'(&(sn=Car*)(objectclass=organizationalPerson))', |
| 303 |
'(sn=sc*)', |
| 304 |
'(sn=*sch*)', |
| 305 |
'(|(givenname=Andy)(givenname=Andrew))', |
| 306 |
'(&(givenname=Bjorn)(objectclass=organizationalPerson))', |
| 307 |
'(&(objectclass=organizationalPerson)(givenname=David))', |
| 308 |
'(&(sn=*)(cn=*))', |
| 309 |
'(sn=Hunter)', |
| 310 |
'(&(givenname=Richard)(objectclass=organizationalPerson))', |
| 311 |
'(givenname=Morgan)', |
| 312 |
'(&(givenname=*)(cn=*))', |
| 313 |
'(givenname=*)']: |
| 314 |
assert Accounts(topo.standalone, DEFAULT_SUFFIX).filter(f'{i}') |
| 315 |
|
| 316 |
# Creating Groups and adding members |
| 317 |
groups = UniqueGroups(topo.standalone, DEFAULT_SUFFIX) |
| 318 |
accounting_managers = groups.ensure_state(properties={'cn': 'Accounting Managers'}) |
| 319 |
hr_managers = groups.ensure_state(properties={'cn': 'HR Managers'}) |
| 320 |
|
| 321 |
accounting_managers.add('uniquemember', |
| 322 |
['uid=scarter, ou=People, dc=example,dc=com', |
| 323 |
'uid=tmorris, ou=People, dc=example,dc=com', |
| 324 |
'uid=kvaughan, ou=People, dc=example,dc=com', |
| 325 |
'uid=rdaugherty, ou=People, dc=example,dc=com', |
| 326 |
'uid=hmiller, ou=People, dc=example,dc=com']) |
| 327 |
|
| 328 |
hr_managers.add('uniquemember', |
| 329 |
['uid=kvaughan, ou=People, dc=example,dc=com', |
| 330 |
'uid=cschmith, ou=People, dc=example,dc=com']) |
| 331 |
|
| 332 |
# Test Filters |
| 333 |
for value in ['(uniquemember=uid=kvaughan,ou=People,dc=example,dc=com)', |
| 334 |
'(uniquemember=uid=rdaugherty,ou=People,dc=example,dc=com)', |
| 335 |
'(uniquemember=uid=hmiller,ou=People,dc=example,dc=com)', |
| 336 |
'(&(objectclass=inetorgperson)(uid=scarter))', |
| 337 |
'(&(objectclass=organizationalperson)(uid=scarter))', |
| 338 |
'(objectclass=inetorgperson)', |
| 339 |
'(&(objectclass=organizationalPerson)(sn=Jensen))', |
| 340 |
'(&(mail=*)(objectclass=organizationalPerson))', |
| 341 |
'(mail=*)', |
| 342 |
'(&(sn=Rentz)(objectclass=organizationalPerson))', |
| 343 |
'(&(sn=Ward)(sn=Ward))', |
| 344 |
'(sn=Jensen)', |
| 345 |
'(sn=*)', |
| 346 |
'(sn=*utz)', |
| 347 |
'(&(sn=Hunter)(sn=Rentz))']: |
| 348 |
if value == '(&(sn=Hunter)(sn=Rentz))': |
| 349 |
assert not Accounts(topo.standalone, DEFAULT_SUFFIX).filter(value) |
| 350 |
elif value.find('uniquemember') == 1: |
| 351 |
assert UniqueGroups(topo.standalone, DEFAULT_SUFFIX).filter(value) |
| 352 |
else: |
| 353 |
assert Accounts(topo.standalone, DEFAULT_SUFFIX).filter(value) |
| 354 |
|
| 355 |
# restart instance |
| 356 |
topo.standalone.restart() |
| 357 |
|
| 358 |
# see if indexing works after restart |
| 359 |
for value in ['(uniquemember=uid=kvaughan,ou=People,dc=example,dc=com)', |
| 360 |
'(uniquemember=uid=rdaugherty,ou=People,dc=example,dc=com)', |
| 361 |
'(uniquemember=uid=hmiller,ou=People,dc=example,dc=com)', |
| 362 |
'(&(objectclass=inetorgperson)(uid=scarter))', |
| 363 |
'(&(objectclass=organizationalperson)(uid=scarter))', |
| 364 |
'(objectclass=inetorgperson)', |
| 365 |
'(&(objectclass=organizationalPerson)(sn=Jensen))', |
| 366 |
'(&(mail=*)(objectclass=organizationalPerson))', |
| 367 |
'(mail=*)', |
| 368 |
'(&(sn=Rentz)(objectclass=organizationalPerson))', |
| 369 |
'(&(sn=Ward)(sn=Ward))', |
| 370 |
'(sn=Jensen)', |
| 371 |
'(sn=*)', |
| 372 |
'(sn=*utz)']: |
| 373 |
if value == '(&(sn=Hunter)(sn=Rentz))': |
| 374 |
assert not Accounts(topo.standalone, DEFAULT_SUFFIX).filter(value) |
| 375 |
elif value.find('uniquemember') == 1: |
| 376 |
assert UniqueGroups(topo.standalone, DEFAULT_SUFFIX).filter(value) |
| 377 |
else: |
| 378 |
assert Accounts(topo.standalone, DEFAULT_SUFFIX).filter(value) |
| 379 |
|
| 380 |
assert not Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(&(sn=Hunter)(sn=Rentz))') |
| 381 |
|
| 382 |
for value in ['(sn=Lutz)', |
| 383 |
'(sn=*ter)', |
| 384 |
'(&(sn=*sen)(objectclass=organizationalPerson))', |
| 385 |
'(&(objectclass=organizationalPerson)(sn=*ntz))', |
| 386 |
'(&(sn=Car*)(objectclass=organizationalPerson))', |
| 387 |
'(sn=sc*)', |
| 388 |
'(sn=*sch*)', |
| 389 |
'(|(givenname=Andy)(givenname=Andrew))', |
| 390 |
'(&(givenname=Bjorn)(objectclass=organizationalPerson))', |
| 391 |
'(&(objectclass=organizationalPerson)(givenname=David))', |
| 392 |
'(&(sn=*)(cn=*))', |
| 393 |
'(sn=Hunter)', |
| 394 |
'(&(givenname=Richard)(objectclass=organizationalPerson))', |
| 395 |
'(givenname=Morgan)', |
| 396 |
'(&(givenname=*)(cn=*))', |
| 397 |
'(givenname=*)']: |
| 398 |
assert Accounts(topo.standalone, DEFAULT_SUFFIX).filter(value) |
| 399 |
|
| 400 |
finally: |
| 401 |
topo.standalone.config.set('nsslapd-errorlog-level', errorlog_value) |
| 402 |
|
| 403 |
|
| 404 |
if __name__ == '__main__': |
| 405 |
CURRENT_FILE = os.path.realpath(__file__) |
| 406 |
pytest.main("-s -v %s" % CURRENT_FILE) |