ticket47953_test.py 3.3 KB

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