diff --git a/mysql-test/suite/oracle_compatibility/t/ora_profile_blacklist.test b/mysql-test/suite/oracle_compatibility/t/ora_profile_blacklist.test new file mode 100644 index 0000000000000000000000000000000000000000..b60deb5e602fc1dc38995d2d72a05b6cd2ed790a --- /dev/null +++ b/mysql-test/suite/oracle_compatibility/t/ora_profile_blacklist.test @@ -0,0 +1,214 @@ +# HAVE_ZSQL_ORA_PROFILE +# blk_user black list function in ora_profile +# TODO:1. 存储过程语句中是否支持 +# 2. prepare语句是否支持 + +--echo ======================================================= +--echo PREPARE ENVIRONMENT +--echo ======================================================= +drop database if exists db_blacklist; +create database db_blacklist; +use db_blacklist; +create table t1 (a1 int, a2 char(255), a3 varchar(1000)); +create table t2 (b1 int primary key, b2 char(255), b3 varchar(1000)); +create table t3 (c1 int, c2 char(255), c3 varchar(1000), primary key(c1,c2)); +insert into t1 values (1, "a21", 'a31'); +insert into t1 values (2, "a22", 'a32'); +insert into t1 values (3, "a23", 'a33'); +insert into t1 values (4, "a24", 'a34'); +insert into t1 values (5, "a25", 'a35'); +insert into t2 values (1, "b21", 'b31'); +insert into t2 values (2, "b22", 'b32'); +insert into t2 values (3, "b23", 'b33'); +insert into t2 values (4, "b24", 'b34'); +insert into t2 values (5, "b25", 'b35'); +insert into t3 values (1, "c21", 'c31'); +insert into t3 values (2, "c22", 'c32'); +insert into t3 values (3, "c23", 'c33'); +insert into t3 values (4, "c24", 'c34'); +insert into t3 values (5, "c25", 'c35'); + +create profile prof1 limit blacklist_no_index true warning; + +create user blk_user@'%' profile prof1; +grant create,insert,delete,drop,update,select on *.* to blk_user@'%'; +flush privileges; + +--echo ======================================================= +--echo CASE 1: blacklist_no_index +--echo ======================================================= +select profile_name from mysql.user where user = 'blk_user'; + +connect (blk_conn,localhost,blk_user,,); +connection blk_conn; +show user profile; + +use db_blacklist; + +# all, warning +select * from t1; + +# all, warning +select * from t2; + +# all, warning +select * from t3; + +# primary key: index scan, no warning +select b1 from t2; + +# const, no warning +select * from t2 where b1 = 1; + +# primary key: index scan, no warning +select c1 from t3; + +# primary key: index scan, no warning +select c1,c2 from t3; + +# primary key: index scan, no warning +select c1 from t3 where c2 = 'c21'; + +# const, no warning +select c1,c2 from t3 where c2 = 'c21' and c1 = 1; + +--echo ======================================================= +--echo CASE 2: blacklist_unsafe_updates +--echo ======================================================= +connection default; + +#aborted +create profile prof2 limit blacklist_unsafe_updates true aborted; + +alter user blk_user change profile prof2; +select profile_name from mysql.user where user = 'blk_user'; + +disconnect blk_conn; +connect (blk_conn,localhost,blk_user,,); +connection blk_conn; + +show user profile; + +use db_blacklist; + +--ERROR ER_BLACKLIST_COMMAND +update t1 set a1=a1+10; +--ERROR ER_BLACKLIST_COMMAND +update t1,t2 set t2.b1=t2.b1+10 where t1.a1>10; +--ERROR ER_BLACKLIST_COMMAND +delete from t3; +--ERROR ER_BLACKLIST_COMMAND +delete from t1 t3; + +#warning +connection default; + +alter user blk_user reset profile; +alter profile prof2 limit blacklist_unsafe_updates true warning; +alter user blk_user change profile prof2; + +disconnect blk_conn; +connect (blk_conn,localhost,blk_user,,); +connection blk_conn; + +use db_blacklist; + +update t1 set a1=a1+10; +update t1,t2 set t2.b1=t2.b1+10 where t1.a1>10; +delete from t3; +delete t1,t2 from t1,t2; + +--echo ======================================================= +--echo CASE 3: blacklist_unsafe_updates +--echo ======================================================= +connection default; +alter user blk_user reset profile; +alter profile prof2 limit blacklist_cross_join true aborted; +alter user blk_user change profile prof2; + +disconnect blk_conn; +connect (blk_conn,localhost,blk_user,,); +connection blk_conn; + +use db_blacklist; + +--ERROR ER_BLACKLIST_COMMAND +select * from t1,t2; + +--ERROR ER_BLACKLIST_COMMAND +select * from t1 cross join t2; + +--ERROR ER_BLACKLIST_COMMAND +select * from t1 inner join t2; + +--ERROR ER_BLACKLIST_COMMAND +select * from t1 join t2; + +--echo ======================================================= +--echo CASE 4: SQL COMMAND IN BLACKLIST - ABORTED +--echo ======================================================= +connection default; +alter user blk_user reset profile; +alter profile prof2 limit + blacklist_truncate_table true aborted + blacklist_drop_table true aborted + blacklist_drop_database true aborted; +alter user blk_user change profile prof2; + +use db_blacklist; +create table t4(a int); + +disconnect blk_conn; +connect (blk_conn,localhost,blk_user,,); +connection blk_conn; + +use db_blacklist; + +# TRUNCATRE TABLE +--ERROR ER_BLACKLIST_COMMAND +truncate table t4; + +# DROP TABLE +--ERROR ER_BLACKLIST_COMMAND +drop table t4; + +# DROP DATABASE +--ERROR ER_BLACKLIST_COMMAND +drop database db_blacklist; + +--echo ======================================================= +--echo CASE 5: SQL COMMAND IN BLACKLIST - WARNING +--echo ======================================================= +connection default; +alter user blk_user reset profile; +alter profile prof2 limit + blacklist_truncate_table true warning + blacklist_drop_table true warning + blacklist_drop_database true warning; +alter user blk_user change profile prof2; + +disconnect blk_conn; +connect (blk_conn,localhost,blk_user,,); +connection blk_conn; + +use db_blacklist; + +# TRUNCATRE TABLE +truncate table t4; + +#DROP TABLE +drop table t4; + +#DROP DATABASE +drop database db_blacklist; + +--echo ======================================================= +--echo CLEAN UP +--echo ======================================================= +connection default; + +disconnect blk_conn; +alter user blk_user reset profile; +drop profile prof1; +drop profile prof2; +drop user blk_user;