2018-12-19 20:29:52 +00:00
|
|
|
import docker
|
2018-12-07 01:40:35 +00:00
|
|
|
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-07 01:40:35 +00:00
|
|
|
|
|
|
|
|
2018-12-19 21:16:44 +00:00
|
|
|
def test_different_user():
|
|
|
|
current_user_id = os.getuid()
|
|
|
|
|
|
|
|
if current_user_id != 0:
|
|
|
|
return
|
|
|
|
|
2018-12-19 22:47:42 +00:00
|
|
|
other_user_id = pwd.getpwnam('nobody').pw_uid
|
|
|
|
|
2018-12-07 01:40:35 +00:00
|
|
|
cluster = ClickHouseCluster(__file__)
|
2018-12-19 21:16:44 +00:00
|
|
|
node = cluster.add_instance('node')
|
2018-12-07 01:40:35 +00:00
|
|
|
|
2018-12-19 22:47:42 +00:00
|
|
|
cluster.start()
|
2018-12-19 20:29:52 +00:00
|
|
|
|
|
|
|
docker_api = docker.from_env().api
|
|
|
|
container = node.get_docker_handle()
|
2018-12-19 22:47:42 +00:00
|
|
|
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
|
|
|
|
2018-12-07 01:40:35 +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:
|
2018-12-19 22:47:42 +00:00
|
|
|
expected_message = "Effective user of the process \(.*\) does not match the owner of the data \(.*\)\. Run under 'sudo -u .*'\."
|
2018-12-07 01:40:35 +00:00
|
|
|
last_message = log.readlines()[-1].strip()
|
2018-12-19 21:16:44 +00:00
|
|
|
|
2018-12-07 01:40:35 +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))
|