ticket48265_test.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2015 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 os
  10. import sys
  11. import time
  12. import ldap
  13. import logging
  14. import pytest
  15. import threading
  16. from lib389 import DirSrv, Entry, tools, tasks
  17. from lib389.tools import DirSrvTools
  18. from lib389._constants import *
  19. from lib389.properties import *
  20. from lib389.tasks import *
  21. from lib389.utils import *
  22. logging.getLogger(__name__).setLevel(logging.DEBUG)
  23. log = logging.getLogger(__name__)
  24. installation1_prefix = None
  25. USER_NUM = 20
  26. TEST_USER = 'test_user'
  27. class TopologyStandalone(object):
  28. def __init__(self, standalone):
  29. standalone.open()
  30. self.standalone = standalone
  31. @pytest.fixture(scope="module")
  32. def topology(request):
  33. global installation1_prefix
  34. if installation1_prefix:
  35. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  36. # Creating standalone instance ...
  37. standalone = DirSrv(verbose=False)
  38. args_instance[SER_HOST] = HOST_STANDALONE
  39. args_instance[SER_PORT] = PORT_STANDALONE
  40. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  41. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  42. args_standalone = args_instance.copy()
  43. standalone.allocate(args_standalone)
  44. instance_standalone = standalone.exists()
  45. if instance_standalone:
  46. standalone.delete()
  47. standalone.create()
  48. standalone.open()
  49. return TopologyStandalone(standalone)
  50. def test_ticket48265_test(topology):
  51. """
  52. Complex filter issues
  53. Ticket 47521 type complex filter:
  54. (&(|(uid=tuser*)(cn=Test user*))(&(givenname=test*3))([email protected])(&(description=*)))
  55. Ticket 48264 type complex filter:
  56. (&(&(|(l=EU)(l=AP)(l=NA))(|(c=SE)(c=DE)))(|(uid=*test*)(cn=*test*))(l=eu))
  57. """
  58. log.info("Adding %d test entries..." % USER_NUM)
  59. for id in range(USER_NUM):
  60. name = "%s%d" % (TEST_USER, id)
  61. mail = "%[email protected]" % name
  62. secretary = "cn=%s,ou=secretary,%s" % (name, SUFFIX)
  63. topology.standalone.add_s(Entry(("cn=%s,%s" % (name, SUFFIX), {
  64. 'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  65. 'sn': name,
  66. 'cn': name,
  67. 'uid': name,
  68. 'givenname': 'test',
  69. 'mail': mail,
  70. 'description': 'description',
  71. 'secretary': secretary,
  72. 'l': 'MV',
  73. 'title': 'Engineer'})))
  74. log.info("Search with Ticket 47521 type complex filter")
  75. for id in range(USER_NUM):
  76. name = "%s%d" % (TEST_USER, id)
  77. mail = "%[email protected]" % name
  78. filter47521 = '(&(|(uid=%s*)(cn=%s*))(&(givenname=test))(mail=%s)(&(description=*)))' % (TEST_USER, TEST_USER, mail)
  79. entry = topology.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, filter47521)
  80. assert len(entry) == 1
  81. log.info("Search with Ticket 48265 type complex filter")
  82. for id in range(USER_NUM):
  83. name = "%s%d" % (TEST_USER, id)
  84. mail = "%[email protected]" % name
  85. filter48265 = '(&(&(|(l=AA)(l=BB)(l=MV))(|(title=admin)(title=engineer)))(|(uid=%s)(mail=%s))(description=description))' % (name, mail)
  86. entry = topology.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, filter48265)
  87. assert len(entry) == 1
  88. log.info('Test 48265 complete\n')
  89. def test_ticket48265_final(topology):
  90. topology.standalone.delete()
  91. log.info('Testcase PASSED')
  92. def run_isolated():
  93. '''
  94. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  95. To run isolated without py.test, you need to
  96. - edit this file and comment '@pytest.fixture' line before 'topology' function.
  97. - set the installation prefix
  98. - run this program
  99. '''
  100. global installation1_prefix
  101. installation1_prefix = None
  102. topo = topology(True)
  103. log.info('Testing Ticket 48265 - Complex filter in a search request does not work as expected')
  104. test_ticket48265_test(topo)
  105. test_ticket48265_final(topo)
  106. if __name__ == '__main__':
  107. run_isolated()