ticket48270_test.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import os
  2. import sys
  3. import time
  4. import ldap
  5. import logging
  6. import pytest
  7. from lib389 import DirSrv, Entry, tools, tasks
  8. from lib389.tools import DirSrvTools
  9. from lib389._constants import *
  10. from lib389.properties import *
  11. from lib389.tasks import *
  12. from lib389.utils import *
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. installation1_prefix = None
  16. NEW_ACCOUNT = "new_account"
  17. MAX_ACCOUNTS = 20
  18. MIXED_VALUE="/home/mYhOmEdIrEcToRy"
  19. LOWER_VALUE="/home/myhomedirectory"
  20. HOMEDIRECTORY_INDEX = 'cn=homeDirectory,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config'
  21. HOMEDIRECTORY_CN="homedirectory"
  22. MATCHINGRULE = 'nsMatchingRule'
  23. UIDNUMBER_INDEX = 'cn=uidnumber,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config'
  24. UIDNUMBER_CN="uidnumber"
  25. class TopologyStandalone(object):
  26. def __init__(self, standalone):
  27. standalone.open()
  28. self.standalone = standalone
  29. @pytest.fixture(scope="module")
  30. def topology(request):
  31. global installation1_prefix
  32. if installation1_prefix:
  33. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  34. # Creating standalone instance ...
  35. standalone = DirSrv(verbose=False)
  36. if installation1_prefix:
  37. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  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. # Delete each instance in the end
  50. def fin():
  51. standalone.delete()
  52. #request.addfinalizer(fin)
  53. # Clear out the tmp dir
  54. standalone.clearTmpDir(__file__)
  55. return TopologyStandalone(standalone)
  56. def test_ticket48270_init(topology):
  57. log.info("Initialization: add dummy entries for the tests")
  58. for cpt in range(MAX_ACCOUNTS):
  59. name = "%s%d" % (NEW_ACCOUNT, cpt)
  60. topology.standalone.add_s(Entry(("uid=%s,%s" % (name, SUFFIX), {
  61. 'objectclass': "top posixAccount".split(),
  62. 'uid': name,
  63. 'cn': name,
  64. 'uidnumber': str(111),
  65. 'gidnumber': str(222),
  66. 'homedirectory': "/home/tbordaz_%d" % cpt})))
  67. def test_ticket48270_homeDirectory_indexed_cis(topology):
  68. log.info("\n\nindex homeDirectory in caseIgnoreIA5Match and caseExactIA5Match")
  69. try:
  70. ent = topology.standalone.getEntry(HOMEDIRECTORY_INDEX, ldap.SCOPE_BASE)
  71. except ldap.NO_SUCH_OBJECT:
  72. topology.standalone.add_s(Entry((HOMEDIRECTORY_INDEX, {
  73. 'objectclass': "top nsIndex".split(),
  74. 'cn': HOMEDIRECTORY_CN,
  75. 'nsSystemIndex': 'false',
  76. 'nsIndexType': 'eq'})))
  77. #log.info("attach debugger")
  78. #time.sleep(60)
  79. IGNORE_MR_NAME='caseIgnoreIA5Match'
  80. EXACT_MR_NAME='caseExactIA5Match'
  81. mod = [(ldap.MOD_REPLACE, MATCHINGRULE, (IGNORE_MR_NAME, EXACT_MR_NAME))]
  82. topology.standalone.modify_s(HOMEDIRECTORY_INDEX, mod)
  83. #topology.standalone.stop(timeout=10)
  84. log.info("successfully checked that filter with exact mr , a filter with lowercase eq is failing")
  85. #assert topology.standalone.db2index(bename=DEFAULT_BENAME, suffixes=None, attrs=['homeDirectory'])
  86. #topology.standalone.start(timeout=10)
  87. args = {TASK_WAIT: True}
  88. topology.standalone.tasks.reindex(suffix=SUFFIX, attrname='homeDirectory', args=args)
  89. log.info("Check indexing succeeded with a specified matching rule")
  90. file_path = os.path.join(topology.standalone.prefix, "var/log/dirsrv/slapd-%s/errors" % topology.standalone.serverid)
  91. file_obj = open(file_path, "r")
  92. # Check if the MR configuration failure occurs
  93. regex = re.compile("unknown or invalid matching rule")
  94. while True:
  95. line = file_obj.readline()
  96. found = regex.search(line)
  97. if ((line == '') or (found)):
  98. break
  99. if (found):
  100. log.info("The configuration of a specific MR fails")
  101. log.info(line)
  102. #assert not found
  103. def test_ticket48270_homeDirectory_mixed_value(topology):
  104. # Set a homedirectory value with mixed case
  105. name = "uid=%s1,%s" % (NEW_ACCOUNT, SUFFIX)
  106. mod = [(ldap.MOD_REPLACE, 'homeDirectory', MIXED_VALUE)]
  107. topology.standalone.modify_s(name, mod)
  108. def test_ticket48270_extensible_search(topology):
  109. name = "uid=%s1,%s" % (NEW_ACCOUNT, SUFFIX)
  110. # check with the exact stored value
  111. log.info("Default: can retrieve an entry filter syntax with exact stored value")
  112. ent = topology.standalone.getEntry(name, ldap.SCOPE_BASE, "(homeDirectory=%s)" % MIXED_VALUE)
  113. log.info("Default: can retrieve an entry filter caseExactIA5Match with exact stored value")
  114. ent = topology.standalone.getEntry(name, ldap.SCOPE_BASE, "(homeDirectory:caseExactIA5Match:=%s)" % MIXED_VALUE)
  115. # check with a lower case value that is different from the stored value
  116. log.info("Default: can not retrieve an entry filter syntax match with lowered stored value")
  117. try:
  118. ent = topology.standalone.getEntry(name, ldap.SCOPE_BASE, "(homeDirectory=%s)" % LOWER_VALUE)
  119. assert ent is None
  120. except ldap.NO_SUCH_OBJECT:
  121. pass
  122. log.info("Default: can not retrieve an entry filter caseExactIA5Match with lowered stored value")
  123. try:
  124. ent = topology.standalone.getEntry(name, ldap.SCOPE_BASE, "(homeDirectory:caseExactIA5Match:=%s)" % LOWER_VALUE)
  125. assert ent is None
  126. except ldap.NO_SUCH_OBJECT:
  127. pass
  128. log.info("Default: can retrieve an entry filter caseIgnoreIA5Match with lowered stored value")
  129. ent = topology.standalone.getEntry(name, ldap.SCOPE_BASE, "(homeDirectory:caseIgnoreIA5Match:=%s)" % LOWER_VALUE)
  130. def test_ticket48270(topology):
  131. """Write your testcase here...
  132. Also, if you need any testcase initialization,
  133. please, write additional fixture for that(include finalizer).
  134. """
  135. log.info('Test complete')
  136. if __name__ == '__main__':
  137. # Run isolated
  138. # -s for DEBUG mode
  139. global installation1_prefix
  140. installation1_prefix = '/home/tbordaz/install_master'
  141. topo = topology(True)
  142. test_ticket48270_init(topo)
  143. test_ticket48270_homeDirectory_indexed_cis(topo)
  144. test_ticket48270_homeDirectory_mixed_value(topo)
  145. test_ticket48270_extensible_search(topo)
  146. # CURRENT_FILE = os.path.realpath(__file__)
  147. # pytest.main("-s %s" % CURRENT_FILE)