|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 4 | +. "$CURDIR"/../../../shell_env.sh |
| 5 | + |
| 6 | +export TEST_USER_NAME="owner" |
| 7 | +export TEST_USER_PASSWORD="password" |
| 8 | +export TEST_USER_CONNECT="bendsql --user=owner --password=password --host=${QUERY_MYSQL_HANDLER_HOST} --port ${QUERY_HTTP_HANDLER_PORT}" |
| 9 | + |
| 10 | +stmt "drop user if exists 'owner'" |
| 11 | +stmt "drop role if exists role1" |
| 12 | +stmt "create user 'owner' IDENTIFIED BY '$TEST_USER_PASSWORD' with DEFAULT_ROLE='role1'" |
| 13 | +stmt 'create role role1' |
| 14 | + |
| 15 | +stmt 'grant role role1 to owner' |
| 16 | +stmt 'grant create on default.* to role role1' |
| 17 | +stmt 'drop table if exists t' |
| 18 | +stmt 'drop view if exists v_t' |
| 19 | +stmt 'drop table if exists t_owner' |
| 20 | +stmt 'drop view if exists v_t_owner' |
| 21 | +stmt 'drop view if exists v_t_union' |
| 22 | +stmt 'drop view if exists v_t1' |
| 23 | +stmt 'create table t(id int)' |
| 24 | +stmt 'insert into t values(1)' |
| 25 | +echo 'create table t_owner(c1 int)' | $TEST_USER_CONNECT |
| 26 | +echo 'insert into t_owner values(2)' | $TEST_USER_CONNECT |
| 27 | +stmt 'revoke create on default.* from role role1' |
| 28 | + |
| 29 | +echo 'need failed: with 1063' |
| 30 | +echo 'create view v_t as select * from t' | $TEST_USER_CONNECT |
| 31 | +echo 'need failed: with 1063' |
| 32 | +echo 'create view v_t_union as select * from t union all select * from t_owner' | $TEST_USER_CONNECT |
| 33 | +echo 'create view v_t_owner as select * from t_owner' | $TEST_USER_CONNECT |
| 34 | +stmt 'grant ownership on default.v_t_owner to role role1' |
| 35 | + |
| 36 | +stmt 'create view v_t as select * from t' |
| 37 | +stmt 'create view v_t_union as select * from t union all select * from t_owner' |
| 38 | + |
| 39 | +echo "'select * from v_t order by id' failed." |
| 40 | +echo "select * from v_t order by id" | $TEST_USER_CONNECT |
| 41 | +stmt 'grant select on default.v_t to owner' |
| 42 | +stmt 'grant select on default.v_t_union to owner' |
| 43 | +echo "select * from v_t order by id" | $TEST_USER_CONNECT |
| 44 | +echo "select * from v_t_owner order by c1" | $TEST_USER_CONNECT |
| 45 | +echo "select * from v_t_union order by id" | $TEST_USER_CONNECT |
| 46 | + |
| 47 | +query "select * from v_t order by id" |
| 48 | +query "select * from v_t_owner order by c1" |
| 49 | +query "select * from v_t_union order by id" |
| 50 | + |
| 51 | +echo "=== create view as select view ===" |
| 52 | + |
| 53 | +stmt 'revoke select on default.v_t from owner' |
| 54 | +stmt 'grant select on default.t to owner' |
| 55 | +echo 'create view v_t1 as select * from t union select * from v_t' | $TEST_USER_CONNECT |
| 56 | +stmt 'grant select on default.v_t to owner' |
| 57 | +stmt 'grant select on default.t to owner' |
| 58 | +echo 'create view v_t1 as select * from t union select * from v_t' | $TEST_USER_CONNECT |
| 59 | +stmt 'grant select on default.v_t1 to owner' |
| 60 | +echo "select * from v_t1 order by id" | $TEST_USER_CONNECT |
| 61 | + |
| 62 | +stmt 'drop table if exists t' |
| 63 | +stmt 'drop view if exists v_t' |
| 64 | +stmt 'drop table if exists t_owner' |
| 65 | +stmt 'drop view if exists v_t_owner' |
| 66 | +stmt 'drop view if exists v_t_union' |
| 67 | +stmt 'drop view if exists v_t1' |
| 68 | +stmt 'drop user if exists owner' |
| 69 | +stmt 'drop role if exists role1' |
0 commit comments