ticket49072_test.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2017 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 as topo
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. TEST_FILTER = '(objectClass=person'
  16. TEST_BASEDN = 'dc=testdb,dc=com'
  17. FILTER = '(objectClass=person)'
  18. FIXUP_MEMOF = 'fixup-memberof.pl'
  19. def test_ticket49072_basedn(topo):
  20. """memberOf fixup task does not validate args
  21. :ID: dce9b898-119d-42b8-a236-1130e59bfe18
  22. :feature: memberOf
  23. :setup: Standalone instance, with memberOf plugin
  24. :steps: 1. Run fixup-memberOf.pl with invalid DN entry
  25. 2. Check if error log reports "Failed to get be backend"
  26. :expectedresults: Fixup-memberOf.pl task should complete, but errors logged.
  27. """
  28. log.info("Ticket 49072 memberof fixup task with invalid basedn...")
  29. topo.standalone.plugins.enable(name=PLUGIN_MEMBER_OF)
  30. topo.standalone.restart(timeout=10)
  31. if ds_is_older('1.3'):
  32. inst_dir = topo.standalone.get_inst_dir()
  33. memof_task = os.path.join(inst_dir, FIXUP_MEMOF)
  34. try:
  35. output = subprocess.check_output([memof_task, '-D', DN_DM, '-w', PASSWORD, '-b', TEST_BASEDN, '-f', FILTER])
  36. except subprocess.CalledProcessError as err:
  37. output = err.output
  38. else:
  39. sbin_dir = topo.standalone.get_sbin_dir()
  40. memof_task = os.path.join(sbin_dir, FIXUP_MEMOF)
  41. try:
  42. output = subprocess.check_output(
  43. [memof_task, '-D', DN_DM, '-w', PASSWORD, '-b', TEST_BASEDN, '-Z', SERVERID_STANDALONE, '-f', FILTER])
  44. except subprocess.CalledProcessError as err:
  45. output = err.output
  46. log.info('output: {}'.format(output))
  47. expected = "Successfully added task entry"
  48. assert expected in output
  49. log_entry = topo.standalone.ds_error_log.match('.*Failed to get be backend.*')
  50. log.info('Error log out: {}'.format(log_entry))
  51. assert topo.standalone.ds_error_log.match('.*Failed to get be backend.*')
  52. def test_ticket49072_filter(topo):
  53. """memberOf fixup task does not validate args
  54. :ID: dde9e893-119d-42c8-a236-1190e56bfe98
  55. :feature: memberOf
  56. :setup: Standalone instance, with memberOf plugin
  57. :steps: 1. Run fixup-memberOf.pl with invalid filter
  58. 2. Check if error log reports "Bad search filter"
  59. :expectedresults: Fixup-memberOf.pl task should complete, but errors logged.
  60. """
  61. log.info("Ticket 49072 memberof fixup task with invalid filter...")
  62. log.info('Wait for 10 secs and check if task is completed')
  63. time.sleep(10)
  64. task_memof = 'cn=memberOf task,cn=tasks,cn=config'
  65. if topo.standalone.search_s(task_memof, ldap.SCOPE_SUBTREE, 'cn=memberOf_fixup*', ['dn:']):
  66. log.info('memberof task is still running, wait for +10 secs')
  67. time.sleep(10)
  68. if ds_is_older('1.3'):
  69. inst_dir = topo.standalone.get_inst_dir()
  70. memof_task = os.path.join(inst_dir, FIXUP_MEMOF)
  71. try:
  72. output = subprocess.check_output([memof_task, '-D', DN_DM, '-w', PASSWORD, '-b', SUFFIX, '-f', TEST_FILTER])
  73. except subprocess.CalledProcessError as err:
  74. output = err.output
  75. else:
  76. sbin_dir = topo.standalone.get_sbin_dir()
  77. memof_task = os.path.join(sbin_dir, FIXUP_MEMOF)
  78. try:
  79. output = subprocess.check_output(
  80. [memof_task, '-D', DN_DM, '-w', PASSWORD, '-b', SUFFIX, '-Z', SERVERID_STANDALONE, '-f', TEST_FILTER])
  81. except subprocess.CalledProcessError as err:
  82. output = err.output
  83. log.info('output: {}'.format(output))
  84. expected = "Successfully added task entry"
  85. assert expected in output
  86. log_entry = topo.standalone.ds_error_log.match('.*Bad search filter.*')
  87. log.info('Error log out: {}'.format(log_entry))
  88. assert topo.standalone.ds_error_log.match('.*Bad search filter.*')
  89. log.info("Ticket 49072 complete: memberOf fixup task does not validate args")
  90. if __name__ == '__main__':
  91. # Run isolated
  92. # -s for DEBUG mode
  93. CURRENT_FILE = os.path.realpath(__file__)
  94. pytest.main("-s %s" % CURRENT_FILE)