mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
Add tests.
This commit is contained in:
parent
421120b997
commit
3706b9d92a
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<yandex>
|
||||
<profiles>
|
||||
<default>
|
||||
</default>
|
||||
</profiles>
|
||||
<users>
|
||||
<default>
|
||||
<password></password>
|
||||
<networks incl="networks" replace="replace">
|
||||
<ip>::/0</ip>
|
||||
</networks>
|
||||
<profile>default</profile>
|
||||
</default>
|
||||
</users>
|
||||
</yandex>
|
49
dbms/tests/integration/test_grant_and_revoke/test.py
Normal file
49
dbms/tests/integration/test_grant_and_revoke/test.py
Normal file
@ -0,0 +1,49 @@
|
||||
import pytest
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
import re
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
instance = cluster.add_instance('instance', config_dir="configs")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def started_cluster():
|
||||
try:
|
||||
cluster.start()
|
||||
|
||||
instance.query("CREATE TABLE test_table(x UInt32) ENGINE = MergeTree ORDER BY tuple()")
|
||||
instance.query("INSERT INTO test_table SELECT number FROM numbers(3)")
|
||||
instance.query("CREATE USER A PROFILE 'default'")
|
||||
instance.query("CREATE USER B PROFILE 'default'")
|
||||
|
||||
yield cluster
|
||||
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
def test_login():
|
||||
assert instance.query("SELECT 1", user='A') == "1\n"
|
||||
assert instance.query("SELECT 1", user='B') == "1\n"
|
||||
|
||||
|
||||
def test_grant_and_revoke():
|
||||
assert "Not enough privileges" in instance.query_and_get_error("SELECT * FROM test_table", user='A')
|
||||
|
||||
instance.query('GRANT SELECT ON test_table TO A')
|
||||
assert instance.query("SELECT * FROM test_table", user='A') == "0\n1\n2\n"
|
||||
|
||||
instance.query('REVOKE SELECT ON test_table FROM A')
|
||||
assert "Not enough privileges" in instance.query_and_get_error("SELECT * FROM test_table", user='A')
|
||||
|
||||
|
||||
def test_grant_option():
|
||||
instance.query('GRANT SELECT ON test_table TO A')
|
||||
assert instance.query("SELECT * FROM test_table", user='A') == "0\n1\n2\n"
|
||||
assert "Not enough privileges" in instance.query_and_get_error("GRANT SELECT ON test_table TO B", user='A')
|
||||
|
||||
instance.query('GRANT SELECT ON test_table TO A WITH GRANT OPTION')
|
||||
instance.query("GRANT SELECT ON test_table TO B", user='A')
|
||||
assert instance.query("SELECT * FROM test_table", user='B') == "0\n1\n2\n"
|
||||
|
||||
instance.query('REVOKE SELECT ON test_table FROM A, B')
|
@ -0,0 +1,11 @@
|
||||
CREATE USER test_user_01073
|
||||
A
|
||||
B
|
||||
GRANT DELETE, INSERT ON *.* TO test_user_01073
|
||||
GRANT SELECT ON db1.* TO test_user_01073
|
||||
GRANT SELECT ON db2.table TO test_user_01073
|
||||
GRANT SELECT(col1) ON db3.table TO test_user_01073
|
||||
GRANT SELECT(col1, col2) ON db4.table TO test_user_01073
|
||||
C
|
||||
GRANT DELETE ON *.* TO test_user_01073
|
||||
GRANT SELECT(col1) ON db4.table TO test_user_01073
|
28
dbms/tests/queries/0_stateless/01073_grant_and_revoke.sql
Normal file
28
dbms/tests/queries/0_stateless/01073_grant_and_revoke.sql
Normal file
@ -0,0 +1,28 @@
|
||||
DROP USER IF EXISTS test_user_01073;
|
||||
|
||||
CREATE USER test_user_01073;
|
||||
SHOW CREATE USER test_user_01073;
|
||||
|
||||
SELECT 'A';
|
||||
SHOW GRANTS FOR test_user_01073;
|
||||
|
||||
GRANT SELECT ON db1.* TO test_user_01073;
|
||||
GRANT SELECT ON db2.table TO test_user_01073;
|
||||
GRANT SELECT(col1) ON db3.table TO test_user_01073;
|
||||
GRANT SELECT(col1, col2) ON db4.table TO test_user_01073;
|
||||
GRANT INSERT ON *.* TO test_user_01073;
|
||||
GRANT DELETE ON *.* TO test_user_01073;
|
||||
|
||||
SELECT 'B';
|
||||
SHOW GRANTS FOR test_user_01073;
|
||||
|
||||
REVOKE SELECT ON db1.* FROM test_user_01073;
|
||||
REVOKE SELECT ON db2.table FROM test_user_01073;
|
||||
REVOKE SELECT ON db3.table FROM test_user_01073;
|
||||
REVOKE SELECT(col2) ON db4.table FROM test_user_01073;
|
||||
REVOKE INSERT ON *.* FROM test_user_01073;
|
||||
|
||||
SELECT 'C';
|
||||
SHOW GRANTS FOR test_user_01073;
|
||||
|
||||
DROP USER test_user_01073;
|
Loading…
Reference in New Issue
Block a user