ticket47953_test.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 shutil
  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. log = logging.getLogger(__name__)
  22. installation_prefix = None
  23. class TopologyStandalone(object):
  24. def __init__(self, standalone):
  25. standalone.open()
  26. self.standalone = standalone
  27. @pytest.fixture(scope="module")
  28. def topology(request):
  29. '''
  30. This fixture is used to standalone topology for the 'module'.
  31. '''
  32. global installation_prefix
  33. if installation_prefix:
  34. args_instance[SER_DEPLOYED_DIR] = installation_prefix
  35. standalone = DirSrv(verbose=False)
  36. # Args for the standalone instance
  37. args_instance[SER_HOST] = HOST_STANDALONE
  38. args_instance[SER_PORT] = PORT_STANDALONE
  39. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  40. args_standalone = args_instance.copy()
  41. standalone.allocate(args_standalone)
  42. # Get the status of the instance and restart it if it exists
  43. instance_standalone = standalone.exists()
  44. # Remove the instance
  45. if instance_standalone:
  46. standalone.delete()
  47. # Create the instance
  48. standalone.create()
  49. # Used to retrieve configuration information (dbdir, confdir...)
  50. standalone.open()
  51. def fin():
  52. standalone.delete()
  53. #request.addfinalizer(fin)
  54. # Here we have standalone instance up and running
  55. return TopologyStandalone(standalone)
  56. def test_ticket47953(topology):
  57. """
  58. Test that we can delete an aci that has an invalid syntax.
  59. Sart by importing an ldif with a "bad" aci, then simply try
  60. to remove that value without error.
  61. """
  62. log.info('Testing Ticket 47953 - Test we can delete aci that has invalid syntax')
  63. #
  64. # Import an invalid ldif
  65. #
  66. ldif_file = (topology.standalone.getDir(__file__, DATA_DIR) +
  67. "ticket47953/ticket47953.ldif")
  68. try:
  69. ldif_dir = topology.standalone.get_ldif_dir()
  70. shutil.copy(ldif_file, ldif_dir)
  71. ldif_file = ldif_dir + '/ticket47953.ldif'
  72. except:
  73. log.fatal('Failed to copy ldif to instance ldif dir')
  74. assert False
  75. importTask = Tasks(topology.standalone)
  76. args = {TASK_WAIT: True}
  77. try:
  78. importTask.importLDIF(DEFAULT_SUFFIX, None, ldif_file, args)
  79. except ValueError:
  80. assert False
  81. time.sleep(2)
  82. #
  83. # Delete the invalid aci
  84. #
  85. acival = '(targetattr ="fffff")(version 3.0;acl "Directory Administrators Group"' + \
  86. ';allow (all) (groupdn = "ldap:///cn=Directory Administrators, dc=example,dc=com");)'
  87. log.info('Attempting to remove invalid aci...')
  88. try:
  89. topology.standalone.modify_s(DEFAULT_SUFFIX, [(ldap.MOD_DELETE, 'aci', acival)])
  90. log.info('Removed invalid aci.')
  91. except ldap.LDAPError as e:
  92. log.error('Failed to remove invalid aci: ' + e.message['desc'])
  93. assert False
  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)