add test to access rights

This commit is contained in:
Anton Popov 2021-09-15 01:42:28 +03:00
parent fc17936c12
commit dafc6d32ef
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,3 @@
Not enough privileges
1 a
2 b

View File

@ -0,0 +1,38 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
url="${CLICKHOUSE_URL}&async_insert_mode=1&wait_for_async_insert=1"
${CLICKHOUSE_CLIENT} -q "DROP USER IF EXISTS u_02015_allowed"
${CLICKHOUSE_CLIENT} -q "DROP USER IF EXISTS u_02015_denied"
${CLICKHOUSE_CLIENT} -q "DROP ROLE IF EXISTS role_02015"
${CLICKHOUSE_CLIENT} -q "CREATE ROLE role_02015"
${CLICKHOUSE_CLIENT} -q "CREATE USER u_02015_allowed";
${CLICKHOUSE_CLIENT} -q "CREATE USER u_02015_denied";
${CLICKHOUSE_CLIENT} -q "REVOKE ALL ON *.* FROM u_02015_allowed"
${CLICKHOUSE_CLIENT} -q "REVOKE ALL ON *.* FROM u_02015_denied"
${CLICKHOUSE_CLIENT} -q "DROP TABLE IF EXISTS async_inserts"
${CLICKHOUSE_CLIENT} -q "CREATE TABLE async_inserts (id UInt32, s String) ENGINE = MergeTree ORDER BY id"
${CLICKHOUSE_CLIENT} -q "GRANT INSERT ON async_inserts TO role_02015"
${CLICKHOUSE_CLIENT} -q "GRANT role_02015 to u_02015_allowed"
${CLICKHOUSE_CURL} -sS "$url&user=u_02015_denied" \
-d 'INSERT INTO async_inserts FORMAT JSONEachRow {"id": 1, "s": "a"} {"id": 2, "s": "b"}' \
| grep -o "Not enough privileges"
${CLICKHOUSE_CURL} -sS "$url&user=u_02015_allowed" \
-d 'INSERT INTO async_inserts FORMAT JSONEachRow {"id": 1, "s": "a"} {"id": 2, "s": "b"}'
${CLICKHOUSE_CLIENT} -q "SELECT * FROM async_inserts ORDER BY id"
${CLICKHOUSE_CLIENT} -q "DROP TABLE async_inserts"
${CLICKHOUSE_CLIENT} -q "DROP USER u_02015_allowed"
${CLICKHOUSE_CLIENT} -q "DROP USER u_02015_denied"
${CLICKHOUSE_CLIENT} -q "DROP ROLE role_02015"