1 #======================================================================
4 # test cases for TRIGGER privilege on db, table and column level
5 #======================================================================
7 --disable_abort_on_error
9 #########################################################
10 ################ Section 3.5.3 ##########################
11 # Check for mix of db and table level of Triggers #
12 #########################################################
14 # General setup to be used in all testcases
15 let $message= ####### Testcase
for mix of db and
table level: #######;
16 --source include/show_msg.inc
19 drop database
if exists priv1_db;
20 drop database
if exists priv2_db;
22 create database priv1_db;
23 create database priv2_db;
25 eval create
table t1 (f1
char(20)) engine= $engine_type;
26 eval create
table t2 (f1
char(20)) engine= $engine_type;
28 eval create
table t1 (f1
char(20)) engine= $engine_type;
30 create User test_yesprivs@localhost;
31 set password for test_yesprivs@localhost = password('PWD');
32 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
33 grant ALL on priv1_db.*
to test_yesprivs@localhost;
34 grant SELECT,UPDATE on priv2_db.*
to test_yesprivs@localhost;
35 show grants for test_yesprivs@localhost;
37 create User test_noprivs@localhost;
38 set password for test_noprivs@localhost = password('PWD');
39 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
40 grant SELECT,INSERT,UPDATE on priv1_db.*
to test_noprivs@localhost;
41 grant SELECT,INSERT on priv2_db.*
to test_noprivs@localhost;
42 show grants for test_noprivs@localhost;
44 connect (yes_privs,localhost,test_yesprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
46 connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
49 # trigger priv on db level->create trigger for all tables successful
51 let $message= trigger privilege on one db1 db
level, not on db2;
52 --source include/show_msg.inc
56 create trigger trg1_1 before INSERT on t1
for each row
57 set new.f1 =
'trig 1_1-yes';
58 create trigger trg2_1 before INSERT on t2
for each row
59 set new.f1 =
'trig 2_1-yes';
61 --error ER_TABLEACCESS_DENIED_ERROR
62 create trigger trg1_1 before INSERT on t1
for each row
63 set new.f1 =
'trig1_1-yes';
67 insert into t1 (f1) values ('insert1_no');
68 select f1 from t1 order by f1;
69 insert into t2 (f1) values ('insert1_no');
70 select f1 from t2 order by f1;
71 insert into priv2_db.t1 (f1) values ('insert21-yes');
72 select f1 from priv2_db.t1 order by f1;
75 insert into t1 (f1) values ('insert1_yes');
76 select f1 from t1 order by f1;
77 insert into priv1_db.t1 (f1) values ('insert11-no');
78 select f1 from priv1_db.t1 order by f1;
79 insert into priv1_db.t2 (f1) values ('insert22-no');
80 select f1 from priv1_db.t2 order by f1;
82 # revoke trigger priv on table level, that doesn't exists->fail
84 let $message= revoke trigger privilege on
table level (not existing);
85 --source include/show_msg.inc
89 --error ER_NONEXISTING_TABLE_GRANT
90 revoke TRIGGER on priv1_db.t1 from test_yesprivs@localhost;
91 show grants
for test_yesprivs@localhost;
101 # revoke the db level->create/drop/use trigger fail
106 revoke TRIGGER on priv1_db.* from test_yesprivs@localhost;
108 ################ Section 3.5.3 ############
109 # Check for the table level of Triggers #
110 ###########################################
111 let $message= no trigger privilege on
table level
for create:;
112 --source include/show_msg.inc
114 connection yes_privs;
117 --error ER_TABLEACCESS_DENIED_ERROR
118 create trigger trg1_1 before INSERT on t1
for each row
119 set new.f1 =
'trig 1_1-no';
124 grant TRIGGER on priv1_db.t1
to test_yesprivs@localhost;
125 show grants
for test_yesprivs@localhost;
127 let $message= trigger privilege on
table level
for create:;
128 --source include/show_msg.inc
129 connection yes_privs;
132 create trigger trg1_2 before INSERT on t1
for each row
133 set new.f1 =
'trig 1_2-yes';
134 --error ER_TABLEACCESS_DENIED_ERROR
135 create trigger trg2_1 before INSERT on t2
for each row
136 set new.f1 =
'trig 2_1-no';
140 # need 'use db' to get the newest privileges
142 insert into t1 (f1) values ('insert2-no');
143 select f1 from t1 order by f1;
144 insert into t2 (f1) values ('insert2-yes');
145 select f1 from t2 order by f1;
146 insert into priv2_db.t1 (f1) values ('insert22-yes');
147 select f1 from priv2_db.t1 order by f1;
151 grant TRIGGER on priv1_db.*
to test_yesprivs@localhost;
152 show grants for test_yesprivs@localhost;
154 # though granted on db level->create trigger fails (no use db)
156 connection yes_privs;
158 --error ER_TABLEACCESS_DENIED_ERROR
159 create trigger trg2_1 before INSERT on t2
for each row
160 set new.f1 =
'trig 2_1-yes';
162 # grant trigger takes effect
165 create trigger trg2_1 before INSERT on t2
for each row
166 set new.f1 =
'trig 2_1-yes';
171 insert into t1 (f1) values ('insert3-no');
172 select f1 from t1 order by f1;
173 insert into t2 (f1) values ('insert3-no');
174 select f1 from t2 order by f1;
176 insert into priv1_db.t1 (f1) values ('insert12-no');
177 select f1 from priv1_db.t1 order by f1;
178 insert into priv1_db.t2 (f1) values ('insert23-no');
179 select f1 from priv1_db.t2 order by f1;
183 connection yes_privs;
189 # Cleanup table level
191 disconnect yes_privs;
198 drop database
if exists priv1_db;
199 drop database
if exists priv2_db;
200 drop user test_yesprivs@localhost;
201 drop user test_noprivs@localhost;