password_test.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2016 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 logging
  10. import pytest
  11. from lib389.tasks import *
  12. from lib389.topologies import topology_st
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. def test_password_delete_specific_password(topology_st):
  16. """ Delete a specific userpassword, and make sure
  17. it is actually deleted from the entry
  18. """
  19. log.info('Running test_password_delete_specific_password...')
  20. USER_DN = 'uid=test_entry,' + DEFAULT_SUFFIX
  21. #
  22. # Add a test user with a password
  23. #
  24. try:
  25. topology_st.standalone.add_s(Entry((USER_DN, {'objectclass': "top extensibleObject".split(),
  26. 'sn': '1',
  27. 'cn': 'user 1',
  28. 'uid': 'user1',
  29. 'userpassword': PASSWORD})))
  30. except ldap.LDAPError as e:
  31. log.fatal('test_password_delete_specific_password: Failed to add test user ' +
  32. USER_DN + ': error ' + e.message['desc'])
  33. assert False
  34. #
  35. # Delete the exact password
  36. #
  37. try:
  38. topology_st.standalone.modify_s(USER_DN, [(ldap.MOD_DELETE, 'userpassword', PASSWORD)])
  39. except ldap.LDAPError as e:
  40. log.fatal('test_password_delete_specific_password: Failed to delete userpassword: error ' +
  41. e.message['desc'])
  42. assert False
  43. #
  44. # Check the password is actually deleted
  45. #
  46. try:
  47. entry = topology_st.standalone.search_s(USER_DN, ldap.SCOPE_BASE, 'objectclass=top')
  48. if entry[0].hasAttr('userpassword'):
  49. log.fatal('test_password_delete_specific_password: Entry incorrectly still have the userpassword attribute')
  50. assert False
  51. except ldap.LDAPError as e:
  52. log.fatal('test_password_delete_specific_password: Failed to search for user(%s), error: %s' %
  53. (USER_DN, e.message('desc')))
  54. assert False
  55. #
  56. # Cleanup
  57. #
  58. try:
  59. topology_st.standalone.delete_s(USER_DN)
  60. except ldap.LDAPError as e:
  61. log.fatal('test_password_delete_specific_password: Failed to delete user(%s), error: %s' %
  62. (USER_DN, e.message('desc')))
  63. assert False
  64. log.info('test_password_delete_specific_password: PASSED')
  65. if __name__ == '__main__':
  66. # Run isolated
  67. # -s for DEBUG mode
  68. CURRENT_FILE = os.path.realpath(__file__)
  69. pytest.main("-s %s" % CURRENT_FILE)