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 column privileges of Triggers #
12 #########################################################
14 # General setup to be used in all testcases
15 let $message= ####### Testcase
for column privileges of triggers: #######;
16 --source include/show_msg.inc
19 drop database
if exists priv_db;
20 drop database
if exists no_priv_db;
22 create database priv_db;
24 eval create
table t1 (f1
char(20)) engine= $engine_type;
25 eval create
table t2 (f1
char(20)) engine= $engine_type;
27 create User test_yesprivs@localhost;
28 set password for test_yesprivs@localhost = password('PWD');
29 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
30 grant TRIGGER on priv_db.*
to test_yesprivs@localhost;
31 show grants for test_yesprivs@localhost;
33 create User test_noprivs@localhost;
34 set password for test_noprivs@localhost = password('PWD');
35 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
36 grant SELECT,UPDATE on priv_db.*
to test_noprivs@localhost;
37 show grants for test_noprivs@localhost;
39 connect (yes_privs,localhost,test_yesprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
41 connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
43 # grant TRIGGER and UPDATE on column -> succeed
45 let $message= update only on column:;
46 --source include/show_msg.inc
50 grant SELECT(f1),INSERT,UPDATE(f1) on priv_db.t1
51 to test_yesprivs@localhost;
52 grant SELECT(f1),INSERT,UPDATE(f1) on priv_db.t2
53 to test_yesprivs@localhost;
58 insert into t1 (f1) values ('insert1-yes');
59 insert into t2 (f1) values ('insert1-yes');
60 create trigger trg1_1 before UPDATE on t1 for each row
61 set new.f1 = 'trig 1_1-yes';
62 create trigger trg2_1 before UPDATE on t2 for each row
63 set new.f1 = 'trig 2_1-yes';
68 select f1 from t1 order by f1;
69 update t1 set f1 = 'update1_no'
70 where f1 like '%insert%';
71 select f1 from t1 order by f1;
72 select f1 from t2 order by f1;
73 update t2 set f1 = 'update1_no'
74 where f1 like '%insert%';
75 select f1 from t2 order by f1;
79 revoke UPDATE on priv_db.*
80 from test_yesprivs@localhost;
81 revoke UPDATE(f1) on priv_db.t2
82 from test_yesprivs@localhost;
83 show grants for test_yesprivs@localhost;
88 insert into t1 (f1) values ('insert2-yes');
89 insert into t2 (f1) values ('insert2-yes');
94 update t1 set f1 = 'update2_no'
95 where f1 like '%insert%';
96 --error ER_COLUMNACCESS_DENIED_ERROR
97 update t2 set f1 = 'update2_no'
98 where f1 like '%insert%';
99 update t1 set f1 = 'update3_no'
100 where f1 like '%insert%';
101 --error ER_COLUMNACCESS_DENIED_ERROR
102 update t2 set f1 = 'update3_no'
103 where f1 like '%insert%';
104 select f1 from t1 order by f1;
105 select f1 from t2 order by f1;
107 # check with three columns
108 let $message= check
if access only on one of three columns;
109 --source include/show_msg.inc
113 alter
table priv_db.t1 add f2 char(20), add f3 int;
114 revoke TRIGGER on priv_db.* from test_yesprivs@localhost;
115 grant TRIGGER,SELECT on priv_db.t1
to test_yesprivs@localhost;
116 grant UPDATE on priv_db.t2
to test_yesprivs@localhost;
118 connection yes_privs;
121 insert into t1 values (
'insert2-yes',
'insert2-yes',1);
122 insert into t1 values (
'insert3-yes',
'insert3-yes',2);
123 select * from t1 order by f1;
128 update t1
set f1 =
'update4-no',
131 where f2 like
'%yes';
132 select * from t1 order by f1,f2,f3;
134 connection yes_privs;
136 create trigger trg1_2 after UPDATE on t1
for each row
137 set @f2 =
'trig 1_2-yes';
141 update t1
set f1 =
'update5-yes',
143 where f2 like
'%yes';
144 select * from t1 order by f1,f2,f3;
147 update t1
set f1 =
'update6_no'
148 where f1 like
'%insert%';
149 --error ER_TABLEACCESS_DENIED_ERROR
150 update t2
set f1 =
'update6_no'
151 where f1 like
'%insert%';
152 update t1
set f1 =
'update7_no'
153 where f1 like
'%insert%';
154 --error ER_TABLEACCESS_DENIED_ERROR
155 update t2
set f1 =
'update7_no'
156 where f1 like
'%insert%';
157 select f1 from t1 order by f1;
158 select f1 from t2 order by f1;
160 # check with three columns
163 # check if update is rejected without trigger privilege
165 let $message= check
if rejected without trigger privilege:;
166 --source include/show_msg.inc
170 revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
174 --error ER_TABLEACCESS_DENIED_ERROR
175 update t1
set f1 =
'update8-no',
177 where f2 like
'%yes';
178 select * from t1 order by f1,f2,f3;
181 # check trigger, but not update privilege on column
183 let $message= check trigger, but not update privilege on column:;
184 --source include/show_msg.inc
188 revoke UPDATE(f1) on priv_db.t1 from test_yesprivs@localhost;
189 grant TRIGGER,UPDATE(f2),UPDATE(f3) on priv_db.t1
190 to test_yesprivs@localhost;
191 show grants for test_yesprivs@localhost;
193 connection yes_privs;
197 create trigger trg1_3 before UPDATE on t1 for each row
198 set new.f1 = 'trig 1_3-yes';
203 --error ER_COLUMNACCESS_DENIED_ERROR
204 update t1 set f1 = 'update9-no',
206 where f2 like '%yes';
207 select * from t1 order by f1,f2,f3;
209 # trigger is involved (table privilege) ->fail
210 --error ER_COLUMNACCESS_DENIED_ERROR
211 update t1
set f3= f3+1;
212 select f3 from t1 order by f3;
216 revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
217 grant UPDATE(f1),UPDATE(f2),UPDATE(f3) on priv_db.t1
218 to test_yesprivs@localhost;
219 show grants for test_yesprivs@localhost;
221 # trigger is involved (table privilege) ->fail
225 --error ER_TABLEACCESS_DENIED_ERROR
226 update t1
set f3= f3+1;
227 select f3 from t1 order by f3;
229 let $message= ##### trigger privilege on column
level? #######;
230 --source include/show_msg.inc
231 --error ER_PARSE_ERROR
232 grant TRIGGER(f1) on priv_db.t1
to test_yesprivs@localhost;
234 # Cleanup table level
236 disconnect yes_privs;
244 drop database
if exists priv_db;
245 drop user test_yesprivs@localhost;
246 drop user test_noprivs@localhost;