ticket365_test.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2015 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 os
  10. import sys
  11. import time
  12. import ldap
  13. import logging
  14. import pytest
  15. from lib389 import DirSrv, Entry, tools, tasks
  16. from lib389.tools import DirSrvTools
  17. from lib389._constants import *
  18. from lib389.properties import *
  19. from lib389.tasks import *
  20. logging.getLogger(__name__).setLevel(logging.DEBUG)
  21. log = logging.getLogger(__name__)
  22. installation1_prefix = None
  23. class TopologyStandalone(object):
  24. def __init__(self, standalone):
  25. standalone.open()
  26. self.standalone = standalone
  27. @pytest.fixture(scope="module")
  28. def topology(request):
  29. global installation1_prefix
  30. if installation1_prefix:
  31. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  32. # Creating standalone instance ...
  33. standalone = DirSrv(verbose=False)
  34. args_instance[SER_HOST] = HOST_STANDALONE
  35. args_instance[SER_PORT] = PORT_STANDALONE
  36. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  37. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  38. args_standalone = args_instance.copy()
  39. standalone.allocate(args_standalone)
  40. instance_standalone = standalone.exists()
  41. if instance_standalone:
  42. standalone.delete()
  43. standalone.create()
  44. standalone.open()
  45. # Clear out the tmp dir
  46. standalone.clearTmpDir(__file__)
  47. return TopologyStandalone(standalone)
  48. def test_ticket365(topology):
  49. '''
  50. Write your testcase here...
  51. nsslapd-auditlog-logging-hide-unhashed-pw
  52. and test
  53. nsslapd-unhashed-pw-switch ticket 561
  54. on, off, nolog?
  55. '''
  56. USER_DN = 'uid=test_entry,' + DEFAULT_SUFFIX
  57. #
  58. # Add the test entry
  59. #
  60. try:
  61. topology.standalone.add_s(Entry((USER_DN, {
  62. 'objectclass': 'top extensibleObject'.split(),
  63. 'uid': 'test_entry',
  64. 'userpassword': 'password'
  65. })))
  66. except ldap.LDAPError as e:
  67. log.error('Failed to add test user: error ' + e.message['desc'])
  68. assert False
  69. #
  70. # Enable the audit log
  71. #
  72. try:
  73. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-auditlog-logging-enabled', 'on')])
  74. except ldap.LDAPError as e:
  75. log.fatal('Failed to enable audit log, error: ' + e.message['desc'])
  76. assert False
  77. '''
  78. try:
  79. ent = topology.standalone.getEntry(DN_CONFIG, attrlist=[
  80. 'nsslapd-instancedir',
  81. 'nsslapd-errorlog',
  82. 'nsslapd-accesslog',
  83. 'nsslapd-certdir',
  84. 'nsslapd-schemadir'])
  85. '''
  86. #
  87. # Allow the unhashed password to be written to audit log
  88. #
  89. try:
  90. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE,
  91. 'nsslapd-auditlog-logging-hide-unhashed-pw', 'off')])
  92. except ldap.LDAPError as e:
  93. log.fatal('Failed to enable writing unhashed password to audit log, error: ' + e.message['desc'])
  94. assert False
  95. #
  96. # Set new password, and check the audit log
  97. #
  98. try:
  99. topology.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', 'mypassword')])
  100. except ldap.LDAPError as e:
  101. log.fatal('Failed to enable writing unhashed password to audit log, error: ' + e.message['desc'])
  102. assert False
  103. # Check audit log
  104. if not topology.standalone.searchAuditLog('unhashed#user#password: mypassword'):
  105. log.fatal('failed to find unhashed password in auditlog')
  106. assert False
  107. #
  108. # Hide unhashed password in audit log
  109. #
  110. try:
  111. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-auditlog-logging-hide-unhashed-pw', 'on')])
  112. except ldap.LDAPError as e:
  113. log.fatal('Failed to deny writing unhashed password to audit log, error: ' + e.message['desc'])
  114. assert False
  115. log.info('Test complete')
  116. #
  117. # Modify password, and check the audit log
  118. #
  119. try:
  120. topology.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', 'hidepassword')])
  121. except ldap.LDAPError as e:
  122. log.fatal('Failed to enable writing unhashed password to audit log, error: ' + e.message['desc'])
  123. assert False
  124. # Check audit log
  125. if topology.standalone.searchAuditLog('unhashed#user#password: hidepassword'):
  126. log.fatal('Found unhashed password in auditlog')
  127. assert False
  128. def test_ticket365_final(topology):
  129. topology.standalone.delete()
  130. log.info('Testcase PASSED')
  131. def run_isolated():
  132. global installation1_prefix
  133. installation1_prefix = None
  134. topo = topology(True)
  135. test_ticket365(topo)
  136. test_ticket365_final(topo)
  137. if __name__ == '__main__':
  138. run_isolated()