ticket49072_test.py 4.4 KB

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