2020-02-29 12:57:52 +00:00
|
|
|
import pytest
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2020-04-08 00:50:27 +00:00
|
|
|
instance = cluster.add_instance("instance")
|
2020-02-29 12:57:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
|
|
def setup_nodes():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
2020-03-18 14:12:09 +00:00
|
|
|
instance.query("CREATE USER sasha")
|
|
|
|
instance.query("CREATE USER masha IDENTIFIED BY 'qwerty'")
|
2020-02-29 12:57:52 +00:00
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_authentication_pass():
|
|
|
|
assert instance.query("SELECT currentUser()", user="sasha") == "sasha\n"
|
|
|
|
assert (
|
|
|
|
instance.query("SELECT currentUser()", user="masha", password="qwerty")
|
|
|
|
== "masha\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-02-29 12:57:52 +00:00
|
|
|
|
2020-05-20 13:08:43 +00:00
|
|
|
# 'no_password' authentication type allows to login with any password.
|
|
|
|
assert (
|
|
|
|
instance.query("SELECT currentUser()", user="sasha", password="something")
|
|
|
|
== "sasha\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-05-20 13:08:43 +00:00
|
|
|
assert (
|
|
|
|
instance.query("SELECT currentUser()", user="sasha", password="something2")
|
|
|
|
== "sasha\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-05-20 13:08:43 +00:00
|
|
|
|
2020-02-29 12:57:52 +00:00
|
|
|
|
|
|
|
def test_authentication_fail():
|
|
|
|
# User doesn't exist.
|
2020-09-16 04:26:10 +00:00
|
|
|
assert "vasya: Authentication failed" in instance.query_and_get_error(
|
|
|
|
"SELECT currentUser()", user="vasya"
|
|
|
|
)
|
|
|
|
|
2020-02-29 12:57:52 +00:00
|
|
|
# Wrong password.
|
2020-09-16 04:26:10 +00:00
|
|
|
assert "masha: Authentication failed" in instance.query_and_get_error(
|
|
|
|
"SELECT currentUser()", user="masha", password="123"
|
|
|
|
)
|