ticket47384_test.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. import shutil
  16. from lib389 import DirSrv, Entry, tools, tasks
  17. from lib389.tools import DirSrvTools
  18. from lib389._constants import *
  19. from lib389.properties import *
  20. from lib389.tasks import *
  21. from lib389.utils import *
  22. logging.getLogger(__name__).setLevel(logging.DEBUG)
  23. log = logging.getLogger(__name__)
  24. installation1_prefix = None
  25. class TopologyStandalone(object):
  26. def __init__(self, standalone):
  27. standalone.open()
  28. self.standalone = standalone
  29. @pytest.fixture(scope="module")
  30. def topology(request):
  31. global installation1_prefix
  32. if installation1_prefix:
  33. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  34. # Creating standalone instance ...
  35. standalone = DirSrv(verbose=False)
  36. args_instance[SER_HOST] = HOST_STANDALONE
  37. args_instance[SER_PORT] = PORT_STANDALONE
  38. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  39. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  40. args_standalone = args_instance.copy()
  41. standalone.allocate(args_standalone)
  42. instance_standalone = standalone.exists()
  43. if instance_standalone:
  44. standalone.delete()
  45. standalone.create()
  46. standalone.open()
  47. # Clear out the tmp dir
  48. standalone.clearTmpDir(__file__)
  49. return TopologyStandalone(standalone)
  50. def test_ticket47384(topology):
  51. '''
  52. Test pluginpath validation: relative and absolute paths
  53. With the inclusion of ticket 47601 - we do allow plugin paths
  54. outside the default location
  55. '''
  56. PLUGIN_DN = 'cn=%s,cn=plugins,cn=config' % PLUGIN_WHOAMI
  57. tmp_dir = topology.standalone.getDir(__file__, TMP_DIR)
  58. plugin_dir = get_plugin_dir(topology.standalone.prefix)
  59. # Copy the library to our tmp directory
  60. try:
  61. shutil.copy('%s/libwhoami-plugin.so' % plugin_dir, tmp_dir)
  62. except IOError, e:
  63. log.fatal('Failed to copy libwhoami-plugin.so to the tmp directory, error: '
  64. + e.strerror)
  65. assert False
  66. try:
  67. shutil.copy('%s/libwhoami-plugin.la' % plugin_dir, tmp_dir)
  68. except IOError, e:
  69. log.fatal('Failed to copy libwhoami-plugin.la to the tmp directory, error: '
  70. + e.strerror)
  71. assert False
  72. #
  73. # Test adding valid plugin paths
  74. #
  75. # Try using the absolute path to the current library
  76. try:
  77. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  78. 'nsslapd-pluginPath', '%s/libwhoami-plugin' % plugin_dir)])
  79. except ldap.LDAPError, e:
  80. log.error('Failed to set valid plugin path (%s): error (%s)' %
  81. ('%s/libwhoami-plugin' % plugin_dir, e.message['desc']))
  82. assert False
  83. # Try using new remote location
  84. try:
  85. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  86. 'nsslapd-pluginPath', '%s/libwhoami-plugin' % tmp_dir)])
  87. except ldap.LDAPError, e:
  88. log.error('Failed to set valid plugin path (%s): error (%s)' %
  89. ('%s/libwhoami-plugin' % tmp_dir, e.message['desc']))
  90. assert False
  91. # Set plugin path back to the default
  92. try:
  93. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  94. 'nsslapd-pluginPath', 'libwhoami-plugin')])
  95. except ldap.LDAPError, e:
  96. log.error('Failed to set valid relative plugin path (%s): error (%s)' %
  97. ('libwhoami-plugin' % tmp_dir, e.message['desc']))
  98. assert False
  99. #
  100. # Test invalid path (no library present)
  101. #
  102. try:
  103. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  104. 'nsslapd-pluginPath', '/bin/libwhoami-plugin')])
  105. # No exception?! This is an error
  106. log.error('Invalid plugin path was incorrectly accepted by the server!')
  107. assert False
  108. except ldap.UNWILLING_TO_PERFORM:
  109. # Correct, operation should be rejected
  110. pass
  111. except ldap.LDAPError, e:
  112. log.error('Failed to set invalid plugin path (%s): error (%s)' %
  113. ('/bin/libwhoami-plugin', e.message['desc']))
  114. #
  115. # Test invalid relative path (no library present)
  116. #
  117. try:
  118. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE,
  119. 'nsslapd-pluginPath', '../libwhoami-plugin')])
  120. # No exception?! This is an error
  121. log.error('Invalid plugin path was incorrectly accepted by the server!')
  122. assert False
  123. except ldap.UNWILLING_TO_PERFORM:
  124. # Correct, operation should be rejected
  125. pass
  126. except ldap.LDAPError, e:
  127. log.error('Failed to set invalid plugin path (%s): error (%s)' %
  128. ('../libwhoami-plugin', e.message['desc']))
  129. log.info('Test complete')
  130. def test_ticket47384_final(topology):
  131. topology.standalone.delete()
  132. log.info('Testcase PASSED')
  133. def run_isolated():
  134. global installation1_prefix
  135. installation1_prefix = None
  136. topo = topology(True)
  137. test_ticket47384(topo)
  138. test_ticket47384_final(topo)
  139. if __name__ == '__main__':
  140. run_isolated()