2024-09-08 08:09:01 +00:00
#!/usr/bin/env bash
# Tags: no-parallel
2024-09-08 09:19:36 +00:00
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
# shellcheck source=../shell_config.sh
. " $CURDIR " /../shell_config.sh
2024-10-01 07:38:19 +00:00
db = ${ CLICKHOUSE_DATABASE }
2024-09-08 08:09:01 +00:00
2024-10-01 07:38:19 +00:00
${ CLICKHOUSE_CLIENT } --query " DROP USER IF EXISTS user_03234; DROP TABLE IF EXISTS ${ db } .tb;CREATE USER user_03234; GRANT SELECT ON ${ db } .tb TO user_03234; "
2024-09-08 08:09:01 +00:00
2024-10-01 07:38:19 +00:00
# Has been granted but not table not exists
# expected to 1
${ CLICKHOUSE_CURL } -sS " ${ CLICKHOUSE_URL } &user=user_03234 " --data-binary " CHECK GRANT SELECT ON ${ db } .tb "
2024-09-08 08:09:01 +00:00
2024-10-01 07:38:19 +00:00
${ CLICKHOUSE_CLIENT } --query " CREATE TABLE ${ db } .tb (\`content\` UInt64) ENGINE = MergeTree ORDER BY content; INSERT INTO ${ db } .tb VALUES (1); "
2024-09-08 08:09:01 +00:00
# Has been granted and table exists
2024-10-01 07:38:19 +00:00
# expected to 1
${ CLICKHOUSE_CURL } -sS " ${ CLICKHOUSE_URL } &user=user_03234 " --data-binary " CHECK GRANT SELECT ON ${ db } .tb "
2024-09-08 08:09:01 +00:00
2024-10-01 07:38:19 +00:00
${ CLICKHOUSE_CLIENT } --query " REVOKE SELECT ON ${ db } .tb FROM user_03234; "
2024-09-08 08:09:01 +00:00
# Has not been granted but table exists
2024-10-01 07:38:19 +00:00
# expected to 0
${ CLICKHOUSE_CURL } -sS " ${ CLICKHOUSE_URL } &user=user_03234 " --data-binary " CHECK GRANT SELECT ON ${ db } .tb "
2024-09-08 08:09:01 +00:00
# Role
2024-10-01 07:38:19 +00:00
# expected to 1
${ CLICKHOUSE_CLIENT } --query " DROP ROLE IF EXISTS role_03234;CREATE ROLE role_03234;GRANT SELECT ON ${ db } .tb TO role_03234;GRANT role_03234 TO user_03234 "
2024-09-08 08:09:01 +00:00
${ CLICKHOUSE_CURL } -sS " ${ CLICKHOUSE_URL } &user=user_03234 " --data-binary "SET ROLE role_03234"
2024-10-01 07:38:19 +00:00
${ CLICKHOUSE_CURL } -sS " ${ CLICKHOUSE_URL } &user=user_03234 " --data-binary " CHECK GRANT SELECT ON ${ db } .tb "
# wildcard
# expected to 1
${ CLICKHOUSE_CLIENT } --query " GRANT SELECT ON ${ db } .tbb* TO user_03234; "
${ CLICKHOUSE_CURL } -sS " ${ CLICKHOUSE_URL } &user=user_03234 " --data-binary " CHECK GRANT SELECT ON ${ db } .tbb1 "