1
0

ticket47953_test.py 3.5 KB

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