1 #### suite/funcs_1/triggers/triggers_03.inc
2 #======================================================================
5 # (test case numbering refer to requirement document TP v1.1)
6 #======================================================================
7 # WL#4084: enable disabled parts. 2007-11-15, hhunger
9 # This test cannot be used for the embedded server because we check here
11 --source include/not_embedded.inc
14 --source suite/funcs_1/include/tb3.inc
18 --disable_abort_on_error
20 ###########################################
21 ################ Section 3.5.3 ############
22 # Check for the global nature of Triggers #
23 ###########################################
25 # General setup to be used in all testcases of 3.5.3
26 let $message= Testcase 3.5.3:;
27 --source include/show_msg.inc
30 drop database
if exists priv_db;
32 create database priv_db;
34 --replace_result $engine_type <engine_to_be_used>
35 eval create
table t1 (f1
char(20)) engine= $engine_type;
37 create User test_noprivs@localhost;
38 set password for test_noprivs@localhost = password('PWD');
40 create User test_yesprivs@localhost;
41 set password for test_yesprivs@localhost = password('PWD');
43 #Section 3.5.3.1 / 3.5.3.2
44 # Test case: Ensure TRIGGER privilege is required to create a trigger
45 #Section 3.5.3.3 / 3.5.3.4
46 # Test case: Ensure that root always has the TRIGGER privilege.
47 # OMR - No need to test this since SUPER priv is an existing one and not related
48 # or added for triggers (TP 2005-06-06)
49 #Section 3.5.3.5 / 3.5.3.6
50 # Test case: Ensure that the TRIGGER privilege is required to drop a trigger.
51 let $message= Testcase 3.5.3.2/6:;
52 --source include/show_msg.inc
54 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
55 grant ALL on *.*
to test_noprivs@localhost;
56 revoke TRIGGER on *.* from test_noprivs@localhost;
57 show grants
for test_noprivs@localhost;
59 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
60 grant TRIGGER on *.*
to test_yesprivs@localhost;
61 # Adding the minimal priv to be able to set to the db
62 grant SELECT on priv_db.t1
to test_yesprivs@localhost;
63 show grants
for test_yesprivs@localhost;
65 connect (no_privs,localhost,test_noprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
66 connect (yes_privs,localhost,test_yesprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
69 let $message= Testcase 3.5.3.2:;
70 --source include/show_msg.inc
76 --error ER_TABLEACCESS_DENIED_ERROR
77 create trigger trg1_1 before INSERT on t1
for each row
78 set new.f1 =
'trig 3.5.3.2_1-no';
82 insert into t1 (f1) values ('insert 3.5.3.2-no');
83 select f1 from t1 order by f1;
89 create trigger trg1_2 before INSERT on t1 for each row
90 set new.f1 = 'trig 3.5.3.2_2-yes';
96 --error ER_COLUMNACCESS_DENIED_ERROR
97 insert into t1 (f1) values ('insert 3.5.3.2-yes');
98 select f1 from t1 order by f1;
100 grant UPDATE on priv_db.t1
to test_yesprivs@localhost;
101 insert into t1 (f1) values ('insert 3.5.3.2-yes');
102 select f1 from t1 order by f1;
104 let $message= Testcase 3.5.3.6:;
105 --source include/show_msg.inc
110 --error ER_TABLEACCESS_DENIED_ERROR
115 insert into t1 (f1) values ('insert 3.5.3.6-yes');
116 select f1 from t1 order by f1;
118 connection yes_privs;
125 insert into t1 (f1) values ('insert 3.5.3.6-no');
126 select f1 from t1 order by f1;
131 --error 0, ER_TRG_DOES_NOT_EXIST
134 disconnect yes_privs;
139 # Test case: Ensure that use of the construct "SET NEW. <column name> = <value>"
140 # fails at CREATE TRIGGER time, if the current user does not have the
141 # UPDATE privilege on the column specified
143 # --- 3.5.3.7a - Privs set on a global level
144 let $message=Testcase 3.5.3.7a:;
145 --source include/show_msg.inc
147 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
148 grant ALL on *.*
to test_noprivs@localhost;
149 revoke UPDATE on *.* from test_noprivs@localhost;
150 show grants
for test_noprivs@localhost;
152 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
153 grant TRIGGER, UPDATE on *.*
to test_yesprivs@localhost;
154 show grants
for test_yesprivs@localhost;
156 connect (no_privs_424a,localhost,test_noprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
157 connect (yes_privs_424a,localhost,test_yesprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
159 connection no_privs_424a;
163 select f1 from t1 order by f1;
165 create trigger trg4a_1 before INSERT on t1
for each row
166 set new.f1 =
'trig 3.5.3.7-1a';
169 --error ER_COLUMNACCESS_DENIED_ERROR
170 insert into t1 (f1) values ('insert 3.5.3.7-1a');
171 select f1 from t1 order by f1;
172 drop trigger trg4a_1;
174 connection yes_privs_424a;
178 create trigger trg4a_2 before INSERT on t1 for each row
179 set new.f1 = 'trig 3.5.3.7-2a';
183 insert into t1 (f1) values ('insert 3.5.3.7-2b');
184 select f1 from t1 order by f1;
188 drop trigger trg4a_2;
189 disconnect no_privs_424a;
190 disconnect yes_privs_424a;
193 # --- 3.5.3.7b - Privs set on a database level
194 let $message= Testcase 3.5.3.7b:;
195 --source include/show_msg.inc
197 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
198 grant TRIGGER on *.*
to test_noprivs;
199 grant ALL on priv_db.*
to test_noprivs@localhost;
200 revoke UPDATE on priv_db.* from test_noprivs@localhost;
201 show grants
for test_noprivs;
203 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
204 grant TRIGGER on *.*
to test_yesprivs@localhost;
205 grant UPDATE on priv_db.*
to test_yesprivs@localhost;
206 show grants
for test_yesprivs@localhost;
208 connect (no_privs_424b,localhost,test_noprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
209 connect (yes_privs_424b,localhost,test_yesprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
212 connection no_privs_424b;
216 create trigger trg4b_1 before UPDATE on t1
for each row
217 set new.f1 =
'trig 3.5.3.7-1b';
220 insert into t1 (f1) values ('insert 3.5.3.7-1b');
221 select f1 from t1 order by f1;
222 update t1 set f1 = 'update 3.5.3.7-1b' where f1 = 'insert 3.5.3.7-1b';
223 select f1 from t1 order by f1;
224 drop trigger trg4b_1;
226 connection yes_privs_424b;
229 create trigger trg4b_2 before UPDATE on t1 for each row
230 set new.f1 = 'trig 3.5.3.7-2b';
234 insert into t1 (f1) values ('insert 3.5.3.7-2b');
235 select f1 from t1 order by f1;
236 update t1 set f1 = 'update 3.5.3.7-2b' where f1 = 'insert 3.5.3.7-2b';
237 select f1 from t1 order by f1;
240 drop trigger trg4b_2;
241 disconnect no_privs_424b;
242 disconnect yes_privs_424b;
245 # --- 3.5.3.7c - Privs set on a table level
246 let $message= Testcase 3.5.3.7c;
247 --source include/show_msg.inc
249 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
250 grant TRIGGER on *.*
to test_noprivs@localhost;
251 grant ALL on priv_db.t1
to test_noprivs@localhost;
252 revoke UPDATE on priv_db.t1 from test_noprivs@localhost;
253 show grants
for test_noprivs;
255 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
256 grant TRIGGER on *.*
to test_yesprivs@localhost;
257 grant UPDATE on priv_db.t1
to test_yesprivs@localhost;
258 show grants
for test_yesprivs@localhost;
260 connect (no_privs_424c,localhost,test_noprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
261 connect (yes_privs_424c,localhost,test_yesprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
264 connection no_privs_424c;
268 create trigger trg4c_1 before INSERT on t1
for each row
269 set new.f1 =
'trig 3.5.3.7-1c';
272 insert into t1 (f1) values ('insert 3.5.3.7-1c');
273 select f1 from t1 order by f1;
274 drop trigger trg4c_1;
276 connection yes_privs_424c;
279 create trigger trg4c_2 before INSERT on t1 for each row
280 set new.f1 = 'trig 3.5.3.7-2c';
284 insert into t1 (f1) values ('insert 3.5.3.7-2c');
285 select f1 from t1 order by f1;
289 drop trigger trg4c_2;
290 disconnect no_privs_424c;
291 disconnect yes_privs_424c;
294 # --- 3.5.3.7d - Privs set on a column level
296 let $message= Testcase 3.5.3.7d:;
298 --source include/show_msg.inc
300 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
301 grant TRIGGER on *.*
to test_noprivs@localhost;
302 # There is no ALL privs on the column level
303 grant SELECT (f1), INSERT (f1) on priv_db.t1
to test_noprivs@localhost;
304 show grants for test_noprivs;
306 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
307 grant TRIGGER on *.*
to test_yesprivs@localhost;
308 grant UPDATE (f1) on priv_db.t1
to test_yesprivs@localhost;
309 show grants for test_noprivs;
311 connect (no_privs_424d,localhost,test_noprivs,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
312 connect (yes_privs_424d,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
315 connection no_privs_424d;
318 create trigger trg4d_1 before INSERT on t1 for each row
319 set new.f1 = 'trig 3.5.3.7-1d';
322 insert into t1 (f1) values ('insert 3.5.3.7-1d');
323 select f1 from t1 order by f1;
324 drop trigger trg4d_1;
326 connection yes_privs_424d;
329 create trigger trg4d_2 before INSERT on t1 for each row
330 set new.f1 = 'trig 3.5.3.7-2d';
334 insert into t1 (f1) values ('insert 3.5.3.7-2d');
335 select f1 from t1 order by f1;
339 drop trigger trg4d_2;
340 disconnect no_privs_424d;
341 disconnect yes_privs_424d;
345 # Test case: Ensure that use of the construct "SET <target> = NEW. <Column name>" fails
346 # at CREATE TRIGGER time, if the current user does not have the SELECT privilege
347 # on the column specified.
349 # --- 3.5.3.8a - Privs set on a global level
350 let $message= Testcase 3.5.3.8a:;
351 --source include/show_msg.inc
353 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
354 grant ALL on *.*
to test_noprivs@localhost;
355 revoke SELECT on *.* from test_noprivs@localhost;
356 show grants
for test_noprivs@localhost;
358 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
359 grant TRIGGER, SELECT on *.*
to test_yesprivs@localhost;
360 show grants
for test_yesprivs@localhost;
362 connect (no_privs_425a,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
363 connect (yes_privs_425a,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
366 connection no_privs_425a;
371 create trigger trg5a_1 before INSERT on t1
for each row
372 set @test_var =
new.f1;
375 set @test_var =
'before trig 3.5.3.8-1a';
377 insert into t1 (f1) values ('insert 3.5.3.8-1a');
379 drop trigger trg5a_1;
381 connection yes_privs_425a;
385 create trigger trg5a_2 before INSERT on t1 for each row
386 set @test_var= new.f1;
389 set @test_var= 'before trig 3.5.3.8-2a';
392 insert into t1 (f1) values ('insert 3.5.3.8-2a');
397 drop trigger trg5a_2;
398 disconnect no_privs_425a;
399 disconnect yes_privs_425a;
402 # --- 3.5.3.8b - Privs set on a database level
403 let $message= Testcase: 3.5.3.8b;
404 --source include/show_msg.inc
406 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
407 grant TRIGGER on *.*
to test_noprivs@localhost;
408 grant ALL on priv_db.*
to test_noprivs@localhost;
409 revoke SELECT on priv_db.* from test_noprivs@localhost;
410 show grants
for test_noprivs@localhost;
412 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
413 grant TRIGGER on *.*
to test_yesprivs@localhost;
414 grant SELECT on priv_db.*
to test_yesprivs@localhost;
415 show grants
for test_yesprivs@localhost;
417 connect (no_privs_425b,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
418 connect (yes_privs_425b,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
421 connection no_privs_425b;
425 create trigger trg5b_1 before UPDATE on t1
for each row
426 set @test_var=
new.f1;
429 set @test_var=
'before trig 3.5.3.8-1b';
430 insert into t1 (f1) values ('insert 3.5.3.8-1b');
432 update t1 set f1= 'update 3.5.3.8-1b' where f1 = 'insert 3.5.3.8-1b';
434 drop trigger trg5b_1;
436 connection yes_privs_425b;
439 create trigger trg5b_2 before UPDATE on t1 for each row
440 set @test_var= new.f1;
443 set @test_var= 'before trig 3.5.3.8-2b';
444 insert into t1 (f1) values ('insert 3.5.3.8-2b');
447 update t1 set f1= 'update 3.5.3.8-2b' where f1 = 'insert 3.5.3.8-2b';
451 drop trigger trg5b_2;
452 disconnect no_privs_425b;
453 disconnect yes_privs_425b;
456 # --- 3.5.3.8c - Privs set on a table level
457 let $message= Testcase 3.5.3.8c:;
458 --source include/show_msg.inc
460 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
461 grant TRIGGER on *.*
to test_noprivs@localhost;
462 grant ALL on priv_db.t1
to test_noprivs@localhost;
463 revoke SELECT on priv_db.t1 from test_noprivs@localhost;
464 show grants
for test_noprivs@localhost;
466 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
467 grant TRIGGER on *.*
to test_yesprivs@localhost;
468 grant SELECT on priv_db.t1
to test_yesprivs@localhost;
469 show grants
for test_yesprivs@localhost;
471 connect (no_privs_425c,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
472 connect (yes_privs_425c,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
475 connection no_privs_425c;
479 create trigger trg5c_1 before INSERT on t1
for each row
480 set @test_var=
new.f1;
483 set @test_var=
'before trig 3.5.3.8-1c';
484 insert into t1 (f1) values ('insert 3.5.3.8-1c');
486 drop trigger trg5c_1;
488 connection yes_privs_425c;
491 create trigger trg5c_2 before INSERT on t1 for each row
492 set @test_var= new.f1;
495 set @test_var='before trig 3.5.3.8-2c';
497 insert into t1 (f1) values ('insert 3.5.3.8-2c');
501 drop trigger trg5c_2;
502 disconnect no_privs_425c;
503 disconnect yes_privs_425c;
506 # --- 3.5.3.8d - Privs set on a column level
507 let $message=Testcase: 3.5.3.8d:;
508 --source include/show_msg.inc
510 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
511 grant TRIGGER on *.*
to test_noprivs@localhost;
512 # There is no ALL prov on the column level
513 grant UPDATE (f1), INSERT (f1) on priv_db.t1
to test_noprivs@localhost;
514 show grants for test_noprivs@localhost;
516 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
517 grant TRIGGER on *.*
to test_yesprivs@localhost;
518 grant SELECT (f1) on priv_db.t1
to test_yesprivs@localhost;
519 show grants for test_noprivs@localhost;
521 connect (no_privs_425d,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
522 connect (yes_privs_425d,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
525 connection no_privs_425d;
528 create trigger trg5d_1 before INSERT on t1 for each row
529 set @test_var= new.f1;
532 set @test_var='before trig 3.5.3.8-1d';
533 insert into t1 (f1) values ('insert 3.5.3.8-1d');
535 drop trigger trg5d_1;
537 connection yes_privs_425d;
540 create trigger trg5d_2 before INSERT on t1 for each row
541 set @test_var= new.f1;
544 set @test_var='before trig 3.5.3.8-2d';
546 insert into t1 (f1) values ('insert 3.5.3.8-2d');
551 drop trigger trg5d_2;
554 # --- 3.5.3.x to test for trigger definer privs in the case of trigger
555 # actions (insert/update/delete/select) performed on other
557 let $message=Testcase: 3.5.3.x:;
558 --source include/show_msg.inc
562 drop
table if exists t1;
563 drop
table if exists t2;
566 --replace_result $engine_type <engine_to_be_used>
567 eval create
table t1 (f1
int) engine= $engine_type;
568 --replace_result $engine_type <engine_to_be_used>
569 eval create
table t2 (f2
int) engine= $engine_type;
571 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
572 grant TRIGGER on *.*
to test_yesprivs@localhost;
573 grant SELECT, UPDATE on priv_db.t1
to test_yesprivs@localhost;
574 grant SELECT on priv_db.t2
to test_yesprivs@localhost;
575 show grants
for test_yesprivs@localhost;
577 connect (yes_353x,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
583 create trigger trg1 before insert on t1
for each row
584 insert into t2 values (
new.f1);
588 insert into t1 (f1) values (4);
589 revoke SELECT on priv_db.t2 from test_yesprivs@localhost;
590 grant INSERT on priv_db.t2
to test_yesprivs@localhost;
591 insert into t1 (f1) values (4);
592 select f1 from t1 order by f1;
593 select f2 from t2 order by f2;
599 create trigger trg2 before insert on t1 for each row
600 update t2 set f2=new.f1-1;
604 insert into t1 (f1) values (2);
605 revoke INSERT on priv_db.t2 from test_yesprivs@localhost;
606 grant UPDATE on priv_db.t2
to test_yesprivs@localhost;
607 insert into t1 (f1) values (2);
608 select f1 from t1 order by f1;
609 select f2 from t2 order by f2;
615 create trigger trg3 before insert on t1 for each row
616 select f2 into @aaa from t2 where f2=new.f1;
620 insert into t1 (f1) values (1);
621 revoke UPDATE on priv_db.t2 from test_yesprivs@localhost;
622 grant SELECT on priv_db.t2
to test_yesprivs@localhost;
623 insert into t1 (f1) values (1);
624 select f1 from t1 order by f1;
625 select f2 from t2 order by f2;
632 create trigger trg4 before insert on t1 for each row
637 insert into t1 (f1) values (1);
638 revoke SELECT on priv_db.t2 from test_yesprivs@localhost;
639 grant DELETE on priv_db.t2
to test_yesprivs@localhost;
640 insert into t1 (f1) values (1);
641 select f1 from t1 order by f1;
642 select f2 from t2 order by f2;
648 drop database
if exists priv_db;
649 drop user test_yesprivs@localhost;
650 drop user test_noprivs@localhost;
651 drop user test_noprivs;