ticket47953_test.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 logging
  10. import shutil
  11. import pytest
  12. from lib389.tasks import *
  13. from lib389.topologies import topology_st
  14. log = logging.getLogger(__name__)
  15. def test_ticket47953(topology_st):
  16. """
  17. Test that we can delete an aci that has an invalid syntax.
  18. Sart by importing an ldif with a "bad" aci, then simply try
  19. to remove that value without error.
  20. """
  21. log.info('Testing Ticket 47953 - Test we can delete aci that has invalid syntax')
  22. #
  23. # Import an invalid ldif
  24. #
  25. ldif_file = (topology_st.standalone.getDir(__file__, DATA_DIR) +
  26. "ticket47953/ticket47953.ldif")
  27. try:
  28. ldif_dir = topology_st.standalone.get_ldif_dir()
  29. shutil.copy(ldif_file, ldif_dir)
  30. ldif_file = ldif_dir + '/ticket47953.ldif'
  31. except:
  32. log.fatal('Failed to copy ldif to instance ldif dir')
  33. assert False
  34. importTask = Tasks(topology_st.standalone)
  35. args = {TASK_WAIT: True}
  36. try:
  37. importTask.importLDIF(DEFAULT_SUFFIX, None, ldif_file, args)
  38. except ValueError:
  39. assert False
  40. time.sleep(2)
  41. #
  42. # Delete the invalid aci
  43. #
  44. acival = '(targetattr ="fffff")(version 3.0;acl "Directory Administrators Group"' + \
  45. ';allow (all) (groupdn = "ldap:///cn=Directory Administrators, dc=example,dc=com");)'
  46. log.info('Attempting to remove invalid aci...')
  47. try:
  48. topology_st.standalone.modify_s(DEFAULT_SUFFIX, [(ldap.MOD_DELETE, 'aci', acival)])
  49. log.info('Removed invalid aci.')
  50. except ldap.LDAPError as e:
  51. log.error('Failed to remove invalid aci: ' + e.message['desc'])
  52. assert False
  53. if __name__ == '__main__':
  54. # Run isolated
  55. # -s for DEBUG mode
  56. CURRENT_FILE = os.path.realpath(__file__)
  57. pytest.main("-s %s" % CURRENT_FILE)