2024-09-08 08:09:01 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-11-19 16:43:57 +00:00
|
|
|
|
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-11-19 16:43:57 +00:00
|
|
|
|
2024-10-01 07:38:19 +00:00
|
|
|
db=${CLICKHOUSE_DATABASE}
|
2024-11-19 16:43:57 +00:00
|
|
|
user=user_${CLICKHOUSE_TEST_UNIQUE_NAME}
|
|
|
|
role=role_${CLICKHOUSE_TEST_UNIQUE_NAME}
|
2024-09-08 08:09:01 +00:00
|
|
|
|
2024-11-19 16:43:57 +00:00
|
|
|
${CLICKHOUSE_CLIENT} --query "DROP ROLE IF EXISTS $role; DROP USER IF EXISTS $user; DROP TABLE IF EXISTS ${db}.tb;"
|
|
|
|
|
|
|
|
${CLICKHOUSE_CLIENT} --query "CREATE USER $user; GRANT SELECT ON ${db}.tb TO $user;"
|
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
|
2024-11-19 16:43:57 +00:00
|
|
|
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&user=$user" --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
|
2024-11-19 16:43:57 +00:00
|
|
|
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&user=$user" --data-binary "CHECK GRANT SELECT ON ${db}.tb"
|
2024-09-08 08:09:01 +00:00
|
|
|
|
2024-11-19 16:43:57 +00:00
|
|
|
${CLICKHOUSE_CLIENT} --query "REVOKE SELECT ON ${db}.tb FROM $user;"
|
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
|
2024-11-19 16:43:57 +00:00
|
|
|
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&user=$user" --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
|
2024-11-19 16:43:57 +00:00
|
|
|
${CLICKHOUSE_CLIENT} --query "CREATE ROLE $role; GRANT SELECT ON ${db}.tb TO $role; GRANT $role TO $user"
|
|
|
|
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&user=$user" --data-binary "SET ROLE $role"
|
|
|
|
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&user=$user" --data-binary "CHECK GRANT SELECT ON ${db}.tb"
|
2024-10-01 07:38:19 +00:00
|
|
|
|
|
|
|
# wildcard
|
2024-11-19 16:43:57 +00:00
|
|
|
${CLICKHOUSE_CLIENT} --query "GRANT SELECT ON ${db}.tbb* TO $user;"
|
2024-10-02 00:11:17 +00:00
|
|
|
# expected to 1
|
2024-11-19 16:43:57 +00:00
|
|
|
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&user=$user" --data-binary "CHECK GRANT SELECT ON ${db}.tbb1"
|
2024-10-02 00:11:17 +00:00
|
|
|
# expected to 1
|
2024-11-19 16:43:57 +00:00
|
|
|
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&user=$user" --data-binary "CHECK GRANT SELECT ON ${db}.tbb2*"
|
|
|
|
|
|
|
|
${CLICKHOUSE_CLIENT} --query "DROP ROLE $role; DROP USER $user; DROP TABLE $db.tb;"
|