ClickHouse/dbms/tests/integration/test_match_process_uid_against_data_owner/test.py

38 lines
1.1 KiB
Python
Raw Normal View History

2018-12-19 20:29:52 +00:00
import docker
import os
import pwd
import pytest
import re
2018-12-19 21:16:44 +00:00
from helpers.cluster import ClickHouseCluster, CLICKHOUSE_START_COMMAND
2018-12-19 21:16:44 +00:00
def test_different_user():
current_user_id = os.getuid()
if current_user_id != 0:
return
other_user_id = pwd.getpwnam('nobody').pw_uid
cluster = ClickHouseCluster(__file__)
2018-12-19 21:16:44 +00:00
node = cluster.add_instance('node')
cluster.start()
2018-12-19 20:29:52 +00:00
docker_api = docker.from_env().api
container = node.get_docker_handle()
container.stop()
2018-12-19 20:29:52 +00:00
container.start()
2018-12-19 21:16:44 +00:00
container.exec_run('chown {} /var/lib/clickhouse'.format(other_user_id), privileged=True)
container.exec_run(CLICKHOUSE_START_COMMAND)
2018-12-19 20:29:52 +00:00
cluster.shutdown() # cleanup
2018-12-19 20:29:52 +00:00
with open(os.path.join(node.path, 'logs/clickhouse-server.err.log')) as log:
expected_message = "Effective user of the process \(.*\) does not match the owner of the data \(.*\)\. Run under 'sudo -u .*'\."
last_message = log.readlines()[-1].strip()
2018-12-19 21:16:44 +00:00
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))