ticket48265_test.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2016 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
  10. from lib389.tasks import *
  11. from lib389.utils import *
  12. from lib389.topologies import topology_st
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. USER_NUM = 20
  16. TEST_USER = 'test_user'
  17. def test_ticket48265_test(topology_st):
  18. """
  19. Complex filter issues
  20. Ticket 47521 type complex filter:
  21. (&(|(uid=tuser*)(cn=Test user*))(&(givenname=test*3))([email protected])(&(description=*)))
  22. Ticket 48264 type complex filter:
  23. (&(&(|(l=EU)(l=AP)(l=NA))(|(c=SE)(c=DE)))(|(uid=*test*)(cn=*test*))(l=eu))
  24. """
  25. log.info("Adding %d test entries..." % USER_NUM)
  26. for id in range(USER_NUM):
  27. name = "%s%d" % (TEST_USER, id)
  28. mail = "%[email protected]" % name
  29. secretary = "cn=%s,ou=secretary,%s" % (name, SUFFIX)
  30. topology_st.standalone.add_s(Entry(("cn=%s,%s" % (name, SUFFIX), {
  31. 'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  32. 'sn': name,
  33. 'cn': name,
  34. 'uid': name,
  35. 'givenname': 'test',
  36. 'mail': mail,
  37. 'description': 'description',
  38. 'secretary': secretary,
  39. 'l': 'MV',
  40. 'title': 'Engineer'})))
  41. log.info("Search with Ticket 47521 type complex filter")
  42. for id in range(USER_NUM):
  43. name = "%s%d" % (TEST_USER, id)
  44. mail = "%[email protected]" % name
  45. filter47521 = '(&(|(uid=%s*)(cn=%s*))(&(givenname=test))(mail=%s)(&(description=*)))' % (
  46. TEST_USER, TEST_USER, mail)
  47. entry = topology_st.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, filter47521)
  48. assert len(entry) == 1
  49. log.info("Search with Ticket 48265 type complex filter")
  50. for id in range(USER_NUM):
  51. name = "%s%d" % (TEST_USER, id)
  52. mail = "%[email protected]" % name
  53. filter48265 = '(&(&(|(l=AA)(l=BB)(l=MV))(|(title=admin)(title=engineer)))(|(uid=%s)(mail=%s))(description=description))' % (
  54. name, mail)
  55. entry = topology_st.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, filter48265)
  56. assert len(entry) == 1
  57. log.info('Test 48265 complete\n')
  58. if __name__ == '__main__':
  59. # Run isolated
  60. # -s for DEBUG mode
  61. CURRENT_FILE = os.path.realpath(__file__)
  62. pytest.main("-s %s" % CURRENT_FILE)