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