1
0

ticket48233_test.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. from lib389.utils import *
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. installation1_prefix = None
  16. class TopologyStandalone(object):
  17. def __init__(self, standalone):
  18. standalone.open()
  19. self.standalone = standalone
  20. @pytest.fixture(scope="module")
  21. def topology(request):
  22. global installation1_prefix
  23. if installation1_prefix:
  24. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  25. # Creating standalone instance ...
  26. standalone = DirSrv(verbose=False)
  27. args_instance[SER_HOST] = HOST_STANDALONE
  28. args_instance[SER_PORT] = PORT_STANDALONE
  29. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  30. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  31. args_standalone = args_instance.copy()
  32. standalone.allocate(args_standalone)
  33. instance_standalone = standalone.exists()
  34. if instance_standalone:
  35. standalone.delete()
  36. standalone.create()
  37. standalone.open()
  38. # Delete each instance in the end
  39. def fin():
  40. standalone.delete()
  41. request.addfinalizer(fin)
  42. # Clear out the tmp dir
  43. standalone.clearTmpDir(__file__)
  44. return TopologyStandalone(standalone)
  45. def test_ticket48233(topology):
  46. """Test that ACI's that use IP restrictions do not crash the server at
  47. shutdown
  48. """
  49. # Add aci to restrict access my ip
  50. aci_text = ('(targetattr != "userPassword")(version 3.0;acl ' +
  51. '"Enable anonymous access - IP"; allow (read,compare,search)' +
  52. '(userdn = "ldap:///anyone") and (ip="127.0.0.1");)')
  53. try:
  54. topology.standalone.modify_s(DEFAULT_SUFFIX, [(ldap.MOD_ADD, 'aci', aci_text)])
  55. except ldap.LDAPError as e:
  56. log.error('Failed to add aci: (%s) error %s' % (aci_text, e.message['desc']))
  57. assert False
  58. time.sleep(1)
  59. # Anonymous search to engage the aci
  60. try:
  61. topology.standalone.simple_bind_s("", "")
  62. except ldap.LDAPError as e:
  63. log.error('Failed to anonymously bind -error %s' % (e.message['desc']))
  64. assert False
  65. try:
  66. entries = topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'objectclass=*')
  67. if not entries:
  68. log.fatal('Failed return an entries from search')
  69. assert False
  70. except ldap.LDAPError as e:
  71. log.fatal('Search failed: ' + e.message['desc'])
  72. assert False
  73. # Restart the server
  74. topology.standalone.restart(timeout=10)
  75. # Check for crash
  76. if topology.standalone.detectDisorderlyShutdown():
  77. log.fatal('Server crashed!')
  78. assert False
  79. log.info('Test complete')
  80. if __name__ == '__main__':
  81. # Run isolated
  82. # -s for DEBUG mode
  83. CURRENT_FILE = os.path.realpath(__file__)
  84. pytest.main("-s %s" % CURRENT_FILE)