pluginpath_validation_test.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. from lib389._constants import DEFAULT_SUFFIX, PLUGIN_WHOAMI
  14. pytestmark = pytest.mark.tier1
  15. logging.getLogger(__name__).setLevel(logging.DEBUG)
  16. log = logging.getLogger(__name__)
  17. @pytest.mark.ds47384
  18. def test_pluginpath_validation(topology_st):
  19. """Test pluginpath validation: relative and absolute paths
  20. With the inclusion of ticket 47601 - we do allow plugin paths
  21. outside the default location
  22. :id: 99f1fb2f-051d-4fd9-93d0-592dcd9b4c22
  23. :setup: Standalone instance
  24. :steps:
  25. 1. Copy the library to a temporary directory
  26. 2. Add valid plugin paths
  27. * using the absolute path to the current library
  28. * using new remote location
  29. 3. Set plugin path back to the default
  30. 4. Check invalid path (no library present)
  31. 5. Check invalid relative path (no library present)
  32. :expectedresults:
  33. 1. This should pass
  34. 2. This should pass
  35. 3. This should pass
  36. 4. This should fail
  37. 5. This should fail
  38. """
  39. if os.geteuid() != 0:
  40. log.warning('This script must be run as root')
  41. return
  42. os.system('setenforce 0')
  43. PLUGIN_DN = 'cn=%s,cn=plugins,cn=config' % PLUGIN_WHOAMI
  44. tmp_dir = topology_st.standalone.get_tmp_dir()
  45. plugin_dir = topology_st.standalone.get_plugin_dir()
  46. # Copy the library to our tmp directory
  47. try:
  48. shutil.copy('%s/libwhoami-plugin.so' % plugin_dir, tmp_dir)
  49. except IOError as e:
  50. log.fatal('Failed to copy %s/libwhoami-plugin.so to the tmp directory %s, error: %s' % (
  51. plugin_dir, tmp_dir, e.strerror))
  52. assert False
  53. try:
  54. shutil.copy('%s/libwhoami-plugin.la' % plugin_dir, tmp_dir)
  55. except IOError as e:
  56. log.warning('Failed to copy ' + plugin_dir +
  57. '/libwhoami-plugin.la to the tmp directory, error: '
  58. + e.strerror)
  59. #
  60. # Test adding valid plugin paths
  61. #
  62. # Try using the absolute path to the current library
  63. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  64. 'nsslapd-pluginPath', ensure_bytes('%s/libwhoami-plugin' % plugin_dir))])
  65. # Try using new remote location
  66. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  67. 'nsslapd-pluginPath', ensure_bytes('%s/libwhoami-plugin' % tmp_dir))])
  68. # Set plugin path back to the default
  69. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  70. 'nsslapd-pluginPath', b'libwhoami-plugin')])
  71. #
  72. # Test invalid path (no library present)
  73. #
  74. with pytest.raises(ldap.UNWILLING_TO_PERFORM):
  75. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  76. 'nsslapd-pluginPath', b'/bin/libwhoami-plugin')])
  77. # No exception?! This is an error
  78. log.error('Invalid plugin path was incorrectly accepted by the server!')
  79. #
  80. # Test invalid relative path (no library present)
  81. #
  82. with pytest.raises(ldap.UNWILLING_TO_PERFORM):
  83. topology_st.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  84. 'nsslapd-pluginPath', b'../libwhoami-plugin')])
  85. # No exception?! This is an error
  86. log.error('Invalid plugin path was incorrectly accepted by the server!')
  87. log.info('Test complete')
  88. if __name__ == '__main__':
  89. # Run isolated
  90. # -s for DEBUG mode
  91. CURRENT_FILE = os.path.realpath(__file__)
  92. pytest.main("-s %s" % CURRENT_FILE)