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 the db level of Triggers #
12 ###########################################
14 # General setup to be used in all testcases
15 let $message= ######### Testcase
for table level: ########;
16 --source include/show_msg.inc
19 drop database
if exists priv_db;
21 create database priv_db;
23 eval create
table t1 (f1
char(20)) engine= $engine_type;
25 create User test_yesprivs@localhost;
26 set password for test_yesprivs@localhost = password('PWD');
27 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
29 create User test_noprivs@localhost;
30 set password for test_noprivs@localhost = password('PWD');
31 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
33 connect (yes_privs,localhost,test_yesprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
35 connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
37 ################ Section 3.5.3 ############
38 # Check for the table level of Triggers #
39 ###########################################
41 # user has no trigger privilege->create trigger fail
43 let $message= no trigger privilege on
table level for create:;
44 --source include/show_msg.inc
48 grant select, insert, update on priv_db.t1
to test_yesprivs@localhost;
49 show grants
for test_yesprivs@localhost;
50 grant select, update, insert on priv_db.t1
to test_noprivs@localhost;
51 show grants
for test_noprivs@localhost;
57 --error ER_TABLEACCESS_DENIED_ERROR
58 create trigger trg1_1 before INSERT on t1
for each row
59 set new.f1 =
'trig 1_1-no';
61 # no trigger execution, as trigger does'nt exist
66 insert into t1 (f1) values ('insert1-yes');
67 select f1 from t1 order by f1;
73 insert into t1 (f1) values ('insert2-yes');
74 select f1 from t1 order by f1;
75 grant TRIGGER on priv_db.t1
to test_yesprivs@localhost;
76 show grants for test_yesprivs@localhost;
78 # user got trigger privilege->create trigger successful
80 let $message= trigger privilege on
table level for create:;
81 --source include/show_msg.inc
85 create trigger trg1_2 before INSERT on t1
for each row
86 set new.f1 =
'trig 1_2-yes';
88 # insert now executes the trigger
92 insert into t1 (f1) values ('insert3-no');
93 select f1 from t1 order by f1;
97 insert into t1 (f1) values ('insert4-no');
98 select f1 from t1 order by f1;
99 revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
100 show grants for test_yesprivs@localhost;
102 # revoke triggerprivilege->drop trigger fail
104 let $message= no trigger privilege on
table level for drop:;
105 --source include/show_msg.inc
106 connection yes_privs;
109 --error ER_TABLEACCESS_DENIED_ERROR
112 # no trigger priv at activation time->insert fails
114 let $message= no trigger privilege at activation time:;
115 --source include/show_msg.inc
118 --error ER_TABLEACCESS_DENIED_ERROR
119 insert into t1 (f1) values ('insert5-no');
120 select f1 from t1 order by f1;
124 grant TRIGGER on priv_db.t1
to test_yesprivs@localhost;
126 # trigger privilege at activation time->insert with trigger successful
128 let $message= trigger privilege at activation time:;
129 --source include/show_msg.inc
132 insert into t1 (f1) values ('insert6-no');
133 select f1 from t1 order by f1;
135 # trigger privilege->drop trigger successful
136 let $message= trigger privilege on
table level for drop:;
137 --source include/show_msg.inc
138 connection yes_privs;
140 show grants
for test_yesprivs@localhost;
143 # inserts without trigger
147 insert into t1 (f1) values ('insert7-yes');
148 select f1 from t1 order by f1;
152 insert into t1 (f1) values ('insert8-yes');
153 select f1 from t1 order by f1;
155 # trigger privilege must be keep when mixinf tables with and without
158 let $message=
switch to table without having trigger priv
for it:;
159 --source include/show_msg.inc
160 eval create
table t2 (f1
char(20)) engine= $engine_type;
161 # Adding the minimal priv to be able to set to the db
162 grant SELECT, INSERT, UPDATE on priv_db.t2
to test_yesprivs@localhost;
163 show grants
for test_yesprivs@localhost;
165 grant SELECT, INSERT, UPDATE on priv_db.t2
to test_noprivs@localhost;
166 show grants
for test_noprivs@localhost;
168 let $message= use
table with trigger privilege and without...:;
169 --source include/show_msg.inc
170 connection yes_privs;
172 --error ER_TABLEACCESS_DENIED_ERROR
173 create trigger trg2_1 before INSERT on t2
for each row
174 set new.f1 =
'trig 2_1-no';
175 create trigger trg1_3 before INSERT on t1
for each row
176 set new.f1 =
'trig 1_3-yes';
177 --error ER_TABLEACCESS_DENIED_ERROR
178 create trigger trg2_2 before UPDATE on t2
for each row
179 set new.f1 =
'trig 2_2-no';
180 create trigger trg1_4 before UPDATE on t1
for each row
181 set new.f1 =
'trig 1_4-yes';
185 insert into t2 (f1) values ('insert9-yes');
186 select f1 from t2 order by f1;
187 insert into t1 (f1) values ('insert10-no');
188 select f1 from t1 order by f1;
191 connection yes_privs;
193 --error ER_TRG_DOES_NOT_EXIST
196 --error ER_TRG_DOES_NOT_EXIST
201 # Cleanup table level
203 disconnect yes_privs;
212 drop database
if exists priv_db;
213 drop user test_yesprivs@localhost;
214 drop user test_noprivs@localhost;