ticket47384_test.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 pytest
  10. from lib389.tasks import *
  11. from lib389.utils import *
  12. from lib389.topologies import topology_st
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. def test_ticket47384(topology_st):
  16. '''
  17. Test pluginpath validation: relative and absolute paths
  18. With the inclusion of ticket 47601 - we do allow plugin paths
  19. outside the default location
  20. '''
  21. if os.geteuid() != 0:
  22. log.warn('This script must be run as root')
  23. return
  24. os.system('setenforce 0')
  25. PLUGIN_DN = 'cn=%s,cn=plugins,cn=config' % PLUGIN_WHOAMI
  26. tmp_dir = topology_st.standalone.get_tmp_dir()
  27. plugin_dir = topology_st.standalone.get_plugin_dir()
  28. # Copy the library to our tmp directory
  29. try:
  30. shutil.copy('%s/libwhoami-plugin.so' % plugin_dir, tmp_dir)
  31. except IOError as e:
  32. log.fatal('Failed to copy %s/libwhoami-plugin.so to the tmp directory %s, error: %s' % (
  33. plugin_dir, tmp_dir, e.strerror))
  34. assert False
  35. try:
  36. shutil.copy('%s/libwhoami-plugin.la' % plugin_dir, tmp_dir)
  37. except IOError as e:
  38. log.warn('Failed to copy ' + plugin_dir +
  39. '/libwhoami-plugin.la to the tmp directory, error: '
  40. + e.strerror)
  41. #
  42. # Test adding valid plugin paths
  43. #
  44. # Try using the absolute path to the current library
  45. try:
  46. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  47. 'nsslapd-pluginPath', '%s/libwhoami-plugin' % plugin_dir)])
  48. except ldap.LDAPError as e:
  49. log.error('Failed to set valid plugin path (%s): error (%s)' %
  50. ('%s/libwhoami-plugin' % plugin_dir, e.message['desc']))
  51. assert False
  52. # Try using new remote location
  53. try:
  54. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  55. 'nsslapd-pluginPath', '%s/libwhoami-plugin' % tmp_dir)])
  56. except ldap.LDAPError as e:
  57. log.error('Failed to set valid plugin path (%s): error (%s)' %
  58. ('%s/libwhoami-plugin' % tmp_dir, e.message['desc']))
  59. assert False
  60. # Set plugin path back to the default
  61. try:
  62. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  63. 'nsslapd-pluginPath', 'libwhoami-plugin')])
  64. except ldap.LDAPError as e:
  65. log.error('Failed to set valid relative plugin path (%s): error (%s)' %
  66. ('libwhoami-plugin' % tmp_dir, e.message['desc']))
  67. assert False
  68. #
  69. # Test invalid path (no library present)
  70. #
  71. try:
  72. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  73. 'nsslapd-pluginPath', '/bin/libwhoami-plugin')])
  74. # No exception?! This is an error
  75. log.error('Invalid plugin path was incorrectly accepted by the server!')
  76. assert False
  77. except ldap.UNWILLING_TO_PERFORM:
  78. # Correct, operation should be rejected
  79. pass
  80. except ldap.LDAPError as e:
  81. log.error('Failed to set invalid plugin path (%s): error (%s)' %
  82. ('/bin/libwhoami-plugin', e.message['desc']))
  83. #
  84. # Test invalid relative path (no library present)
  85. #
  86. try:
  87. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  88. 'nsslapd-pluginPath', '../libwhoami-plugin')])
  89. # No exception?! This is an error
  90. log.error('Invalid plugin path was incorrectly accepted by the server!')
  91. assert False
  92. except ldap.UNWILLING_TO_PERFORM:
  93. # Correct, operation should be rejected
  94. pass
  95. except ldap.LDAPError as e:
  96. log.error('Failed to set invalid plugin path (%s): error (%s)' %
  97. ('../libwhoami-plugin', e.message['desc']))
  98. log.info('Test complete')
  99. if __name__ == '__main__':
  100. # Run isolated
  101. # -s for DEBUG mode
  102. CURRENT_FILE = os.path.realpath(__file__)
  103. pytest.main("-s %s" % CURRENT_FILE)