logpipe_test.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2017 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. import subprocess
  11. from lib389.utils import *
  12. from lib389.topologies import topology_st as topo
  13. pytestmark = pytest.mark.tier1
  14. DEBUGGING = os.getenv("DEBUGGING", default=False)
  15. if DEBUGGING:
  16. logging.getLogger(__name__).setLevel(logging.DEBUG)
  17. else:
  18. logging.getLogger(__name__).setLevel(logging.INFO)
  19. log = logging.getLogger(__name__)
  20. SYS_TEST_USER = 'dirsrv_testuser'
  21. @pytest.fixture(scope="module")
  22. def sys_test_user(request):
  23. """Creates and deletes a system test user"""
  24. cmd = ['/usr/sbin/useradd', SYS_TEST_USER]
  25. log.info('Add system test user - {}'.format(SYS_TEST_USER))
  26. try:
  27. subprocess.call(cmd)
  28. except subprocess.CalledProcessError as e:
  29. log.exception('Failed to add user {} error {}'.format(SYS_TEST_USER, e.output))
  30. def fin():
  31. cmd = ['/usr/sbin/userdel', SYS_TEST_USER]
  32. log.info('Delete system test user - {}'.format(SYS_TEST_USER))
  33. try:
  34. subprocess.call(cmd)
  35. except subprocess.CalledProcessError as e:
  36. log.exception('Failed to delete user {} error {}'.format(SYS_TEST_USER, e.output))
  37. request.addfinalizer(fin)
  38. def test_user_permissions(topo, sys_test_user):
  39. """Check permissions for usual user operations in log dir
  40. :ID: 4e423cd5-300c-4df0-ab40-aec7e51c3be8
  41. :feature: ds-logpipe
  42. :setup: Standalone instance
  43. :steps: 1. Add a new user to the system
  44. 2. Try to create a logpipe in the log directory with '-u' option specifying the user
  45. 3. Delete the user
  46. :expectedresults: Permission denied error happens
  47. """
  48. ds_logpipe_path = os.path.join(topo.standalone.ds_paths.bin_dir, 'ds-logpipe.py')
  49. fakelogpipe_path = os.path.join(topo.standalone.ds_paths.log_dir, 'fakelog.pipe')
  50. # I think we need to add a function for this to lib389, when we will port the full test suite
  51. cmd = [ds_logpipe_path, fakelogpipe_path, '-u', SYS_TEST_USER]
  52. log.info('Try to create a logpipe in the log directory with "-u" option specifying the user')
  53. with pytest.raises(subprocess.CalledProcessError) as cp:
  54. result = subprocess.check_output(cmd)
  55. assert 'Permission denied' in result
  56. if __name__ == '__main__':
  57. # Run isolated
  58. # -s for DEBUG mode
  59. CURRENT_FILE = os.path.realpath(__file__)
  60. pytest.main("-s %s" % CURRENT_FILE)