ticket48233_test.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import pytest
  2. from lib389.utils import *
  3. from lib389.topologies import topology_st
  4. logging.getLogger(__name__).setLevel(logging.DEBUG)
  5. log = logging.getLogger(__name__)
  6. def test_ticket48233(topology_st):
  7. """Test that ACI's that use IP restrictions do not crash the server at
  8. shutdown
  9. """
  10. # Add aci to restrict access my ip
  11. aci_text = ('(targetattr != "userPassword")(version 3.0;acl ' +
  12. '"Enable anonymous access - IP"; allow (read,compare,search)' +
  13. '(userdn = "ldap:///anyone") and (ip="127.0.0.1");)')
  14. try:
  15. topology_st.standalone.modify_s(DEFAULT_SUFFIX, [(ldap.MOD_ADD, 'aci', aci_text)])
  16. except ldap.LDAPError as e:
  17. log.error('Failed to add aci: (%s) error %s' % (aci_text, e.message['desc']))
  18. assert False
  19. time.sleep(1)
  20. # Anonymous search to engage the aci
  21. try:
  22. topology_st.standalone.simple_bind_s("", "")
  23. except ldap.LDAPError as e:
  24. log.error('Failed to anonymously bind -error %s' % (e.message['desc']))
  25. assert False
  26. try:
  27. entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'objectclass=*')
  28. if not entries:
  29. log.fatal('Failed return an entries from search')
  30. assert False
  31. except ldap.LDAPError as e:
  32. log.fatal('Search failed: ' + e.message['desc'])
  33. assert False
  34. # Restart the server
  35. topology_st.standalone.restart(timeout=10)
  36. # Check for crash
  37. if topology_st.standalone.detectDisorderlyShutdown():
  38. log.fatal('Server crashed!')
  39. assert False
  40. log.info('Test complete')
  41. if __name__ == '__main__':
  42. # Run isolated
  43. # -s for DEBUG mode
  44. CURRENT_FILE = os.path.realpath(__file__)
  45. pytest.main("-s %s" % CURRENT_FILE)