ticket365_test.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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_ticket365(topology_st):
  16. '''
  17. Write your testcase here...
  18. nsslapd-auditlog-logging-hide-unhashed-pw
  19. and test
  20. nsslapd-unhashed-pw-switch ticket 561
  21. on, off, nolog?
  22. '''
  23. USER_DN = 'uid=test_entry,' + DEFAULT_SUFFIX
  24. #
  25. # Add the test entry
  26. #
  27. try:
  28. topology_st.standalone.add_s(Entry((USER_DN, {
  29. 'objectclass': 'top extensibleObject'.split(),
  30. 'uid': 'test_entry',
  31. 'userpassword': 'password'
  32. })))
  33. except ldap.LDAPError as e:
  34. log.error('Failed to add test user: error ' + e.message['desc'])
  35. assert False
  36. #
  37. # Enable the audit log
  38. #
  39. try:
  40. topology_st.standalone.modify_s(DN_CONFIG,
  41. [(ldap.MOD_REPLACE,
  42. 'nsslapd-auditlog-logging-enabled',
  43. 'on')])
  44. except ldap.LDAPError as e:
  45. log.fatal('Failed to enable audit log, error: ' + e.message['desc'])
  46. assert False
  47. '''
  48. try:
  49. ent = topology_st.standalone.getEntry(DN_CONFIG, attrlist=[
  50. 'nsslapd-instancedir',
  51. 'nsslapd-errorlog',
  52. 'nsslapd-accesslog',
  53. 'nsslapd-certdir',
  54. 'nsslapd-schemadir'])
  55. '''
  56. #
  57. # Allow the unhashed password to be written to audit log
  58. #
  59. try:
  60. topology_st.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE,
  61. 'nsslapd-auditlog-logging-hide-unhashed-pw', 'off')])
  62. except ldap.LDAPError as e:
  63. log.fatal('Failed to enable writing unhashed password to audit log, ' +
  64. 'error: ' + e.message['desc'])
  65. assert False
  66. #
  67. # Set new password, and check the audit log
  68. #
  69. try:
  70. topology_st.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE,
  71. 'userpassword',
  72. 'mypassword')])
  73. except ldap.LDAPError as e:
  74. log.fatal('Failed to enable writing unhashed password to audit log, ' +
  75. 'error: ' + e.message['desc'])
  76. assert False
  77. # Check audit log
  78. time.sleep(1)
  79. if not topology_st.standalone.searchAuditLog('unhashed#user#password: mypassword'):
  80. log.fatal('failed to find unhashed password in auditlog')
  81. assert False
  82. #
  83. # Hide unhashed password in audit log
  84. #
  85. try:
  86. topology_st.standalone.modify_s(DN_CONFIG,
  87. [(ldap.MOD_REPLACE,
  88. 'nsslapd-auditlog-logging-hide-unhashed-pw',
  89. 'on')])
  90. except ldap.LDAPError as e:
  91. log.fatal('Failed to deny writing unhashed password to audit log, ' +
  92. 'error: ' + e.message['desc'])
  93. assert False
  94. log.info('Test complete')
  95. #
  96. # Modify password, and check the audit log
  97. #
  98. try:
  99. topology_st.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE,
  100. 'userpassword',
  101. 'hidepassword')])
  102. except ldap.LDAPError as e:
  103. log.fatal('Failed to enable writing unhashed password to audit log, ' +
  104. 'error: ' + e.message['desc'])
  105. assert False
  106. # Check audit log
  107. time.sleep(1)
  108. if topology_st.standalone.searchAuditLog('unhashed#user#password: hidepassword'):
  109. log.fatal('Found unhashed password in auditlog')
  110. assert False
  111. log.info('Test complete')
  112. if __name__ == '__main__':
  113. # Run isolated
  114. # -s for DEBUG mode
  115. CURRENT_FILE = os.path.realpath(__file__)
  116. pytest.main("-s %s" % CURRENT_FILE)