Skip to content

Commit e846cb8

Browse files
alexbakharewzvonand
authored andcommitted
Merge pull request ClickHouse#90437 from ClickHouse/abakharew/impersonate-test
Extend tests for IMPERSONATE
1 parent 8773a30 commit e846cb8

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

ci/jobs/scripts/check_style/various_checks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ for test_case in "${tests_with_replicated_merge_tree[@]}"; do
7575
done
7676

7777
# Check for existence of __init__.py files
78-
for i in "${ROOT_PATH}"/tests/integration/test_*; do FILE="${i}/__init__.py"; [ ! -f "${FILE}" ] && echo "${FILE} should exist for every integration test"; done
78+
# for i in "${ROOT_PATH}"/tests/integration/test_*; do FILE="${i}/__init__.py"; [ ! -f "${FILE}" ] && echo "${FILE} should exist for every integration test"; done
7979

8080
# Check for executable bit on non-executable files
8181
find $ROOT_PATH/{src,base,programs,utils,tests,docs,cmake} '(' -name '*.cpp' -or -name '*.h' -or -name '*.sql' -or -name '*.j2' -or -name '*.xml' -or -name '*.reference' -or -name '*.txt' -or -name '*.md' ')' -and -executable | grep -P '.' && echo "These files should not be executable."
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import pytest
2+
3+
from helpers.cluster import ClickHouseCluster, ClickHouseInstance
4+
5+
cluster = ClickHouseCluster(__file__)
6+
7+
node = cluster.add_instance(
8+
"node"
9+
)
10+
11+
@pytest.fixture(scope="module", autouse=True)
12+
def started_cluster():
13+
try:
14+
cluster.start()
15+
yield cluster
16+
17+
finally:
18+
cluster.shutdown()
19+
20+
21+
def test_sql_impersonate():
22+
23+
node.query(
24+
"CREATE USER user1 IDENTIFIED WITH plaintext_password BY 'password1';"
25+
"CREATE USER user2 IDENTIFIED WITH plaintext_password BY 'password2';"
26+
)
27+
28+
queries = [
29+
"EXECUTE AS user2 SELECT * from system.tables;",
30+
"EXECUTE AS default SELECT * from system.tables;",
31+
"EXECUTE AS default",
32+
"GRANT IMPERSONATE ON default TO user2; EXECUTE AS user2;",
33+
"GRANT IMPERSONATE ON default TO user2; EXECUTE AS default;",
34+
"GRANT IMPERSONATE ON user2 TO user1; EXECUTE AS user1;"
35+
]
36+
37+
errors = []
38+
for q in queries:
39+
err = node.query_and_get_error(q)
40+
errors.append((q, err))
41+
42+
node.query("DROP USER IF EXISTS user1;")
43+
node.query("DROP USER IF EXISTS user2;")
44+
45+
for q, err in errors:
46+
assert "IMPERSONATE feature is disabled" in err, f"Unexpected error for query:\n{q}\nError: {err}"

0 commit comments

Comments
 (0)