From acb8cf1849b677753237e7faac9c5f41b78665a8 Mon Sep 17 00:00:00 2001 From: "Sergey V. Galtsev" Date: Wed, 19 Dec 2018 23:29:52 +0300 Subject: [PATCH] Fix test. --- .../configs/config.xml | 3 +++ .../configs/users.xml | 20 +++++++++++++++ .../test.py | 25 +++++++++++-------- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/dbms/tests/integration/test_match_process_uid_against_data_owner/configs/config.xml b/dbms/tests/integration/test_match_process_uid_against_data_owner/configs/config.xml index 48aa82349d3..032b8874af2 100644 --- a/dbms/tests/integration/test_match_process_uid_against_data_owner/configs/config.xml +++ b/dbms/tests/integration/test_match_process_uid_against_data_owner/configs/config.xml @@ -7,5 +7,8 @@ /var/log/clickhouse-server/stdout.log + /var/lib/clickhouse/ + + 5368709120 users.xml diff --git a/dbms/tests/integration/test_match_process_uid_against_data_owner/configs/users.xml b/dbms/tests/integration/test_match_process_uid_against_data_owner/configs/users.xml index 9aba4ac0914..6061af8e33d 100644 --- a/dbms/tests/integration/test_match_process_uid_against_data_owner/configs/users.xml +++ b/dbms/tests/integration/test_match_process_uid_against_data_owner/configs/users.xml @@ -1,3 +1,23 @@ + + + + + + + + + + ::/0 + + default + default + + + + + + + diff --git a/dbms/tests/integration/test_match_process_uid_against_data_owner/test.py b/dbms/tests/integration/test_match_process_uid_against_data_owner/test.py index 56c40530c36..c96560230eb 100644 --- a/dbms/tests/integration/test_match_process_uid_against_data_owner/test.py +++ b/dbms/tests/integration/test_match_process_uid_against_data_owner/test.py @@ -1,3 +1,4 @@ +import docker import os import pwd import pytest @@ -6,32 +7,36 @@ import re from helpers.cluster import ClickHouseCluster -def expect_failure_with_message(config, expected_message): +def expect_failure_with_message(expected_message): cluster = ClickHouseCluster(__file__) - node = cluster.add_instance('node', main_configs=[config], with_zookeeper=False) + node = cluster.add_instance('node', with_zookeeper=False) with pytest.raises(Exception): cluster.start() + current_user_id = os.getuid() + other_user_id = pwd.getpwnam('nobody').pw_uid + + docker_api = docker.from_env().api + container = node.get_docker_handle() + container.start() + container.exec_run('chown {0} /var/lib/clickhouse'.format(other_user_id), privileged=True) + container.exec_run('clickhouse server --config-file=/etc/clickhouse-server/config.xml --log-file=/var/log/clickhouse-server/clickhouse-server.log --errorlog-file=/var/log/clickhouse-server/clickhouse-server.err.log', privileged=True) + cluster.shutdown() # cleanup - with open(os.path.join(node.path, 'logs/stderr.log')) as log: + with open(os.path.join(node.path, 'logs/clickhouse-server.err.log')) as log: last_message = log.readlines()[-1].strip() if re.search(expected_message, last_message) is None: pytest.fail('Expected the server to fail with a message "{}", but the last message is "{}"'.format(expected_message, last_message)) -def test_no_such_directory(): - expect_failure_with_message('configs/no_such_directory.xml', 'Failed to stat.*no_such_directory') - - def test_different_user(): current_user_id = os.getuid() - if current_user_id != 0: + if current_user_id == 0: current_user_name = pwd.getpwuid(current_user_id).pw_name expect_failure_with_message( - 'configs/owner_mismatch.xml', - 'Effective user of the process \(({}|{})\) does not match the owner of the data \((0|root)\)'.format(current_user_id, current_user_name), + 'Effective user of the process \(.*\) does not match the owner of the data \(.*\)', )