account_test.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2017 Red Hat, Inc.
  3. # Copyright (C) 2019 William Brown <[email protected]>
  4. # All rights reserved.
  5. #
  6. # License: GPL (version 3 or any later version).
  7. # See LICENSE for details.
  8. # --- END COPYRIGHT BLOCK ---
  9. #
  10. import os
  11. import pytest
  12. import ldap
  13. from lib389.idm.user import UserAccounts, nsUserAccounts
  14. from lib389.topologies import topology_st as topology
  15. from lib389._constants import DEFAULT_SUFFIX
  16. def test_account_locking(topology):
  17. """
  18. Ensure that user and group management works as expected.
  19. """
  20. users = UserAccounts(topology.standalone, DEFAULT_SUFFIX)
  21. user_properties = {
  22. 'uid': 'testuser',
  23. 'cn' : 'testuser',
  24. 'sn' : 'user',
  25. 'uidNumber' : '1000',
  26. 'gidNumber' : '2000',
  27. 'homeDirectory' : '/home/testuser',
  28. 'userPassword' : 'password'
  29. }
  30. testuser = users.create(properties=user_properties)
  31. assert(testuser.is_locked() is False)
  32. testuser.lock()
  33. assert(testuser.is_locked() is True)
  34. # Check a bind fails
  35. with pytest.raises(ldap.UNWILLING_TO_PERFORM):
  36. conn = testuser.bind('password')
  37. conn.unbind_s()
  38. testuser.unlock()
  39. assert(testuser.is_locked() is False)
  40. # Check the bind works.
  41. conn = testuser.bind('password')
  42. conn.unbind_s()
  43. def test_account_reset_pw(topology):
  44. users = nsUserAccounts(topology.standalone, DEFAULT_SUFFIX)
  45. testuser = users.create_test_user(uid=1001)
  46. # Make sure they are unlocked.
  47. testuser.unlock()
  48. testuser.reset_password("test_password")
  49. # Assert we can bind as the new PW
  50. c = testuser.bind('test_password')
  51. c.unbind_s()
  52. def test_account_change_pw(topology):
  53. # This test requires a secure connection
  54. topology.standalone.enable_tls()
  55. users = nsUserAccounts(topology.standalone, DEFAULT_SUFFIX)
  56. testuser = users.create_test_user(uid=1002)
  57. # Make sure they are unlocked.
  58. testuser.unlock()
  59. testuser.reset_password('password')
  60. testuser.change_password('password', "test_password")
  61. # Assert we can bind as the new PW
  62. c = testuser.bind('test_password')
  63. c.unbind_s()