1
#======================================================================
4
# (test case numbering refer to requirement document TP v1.1)
5
#======================================================================
6
# WL#4084: enable disabled parts. 2007-11-15, hhunger
8
--disable_abort_on_error
10
###########################################
11
################ Section 3.5.3 ############
12
# Check for the global nature of Triggers #
13
###########################################
15
# General setup to be used in all testcases of 3.5.3
16
let $message= Testcase 3.5.3:;
17
--source include/show_msg.inc
20
drop database if exists priv_db;
22
create database priv_db;
24
eval create table t1 (f1 char(20)) engine= $engine_type;
26
create User test_noprivs@localhost;
27
set password for test_noprivs@localhost = password('PWD');
29
create User test_yesprivs@localhost;
30
set password for test_yesprivs@localhost = password('PWD');
32
#Section 3.5.3.1 / 3.5.3.2
33
# Test case: Ensure TRIGGER privilege is required to create a trigger
34
#Section 3.5.3.3 / 3.5.3.4
35
# Test case: Ensure that root always has the TRIGGER privilege.
36
# OMR - No need to test this since SUPER priv is an existing one and not related
37
# or added for triggers (TP 2005-06-06)
38
#Section 3.5.3.5 / 3.5.3.6
39
# Test case: Ensure that the TRIGGER privilege is required to drop a trigger.
40
let $message= Testcase 3.5.3.2/6:;
41
--source include/show_msg.inc
43
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
44
grant ALL on *.* to test_noprivs@localhost;
45
revoke TRIGGER on *.* from test_noprivs@localhost;
46
show grants for test_noprivs@localhost;
48
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
49
grant TRIGGER on *.* to test_yesprivs@localhost;
50
# Adding the minimal priv to be able to set to the db
51
grant SELECT on priv_db.t1 to test_yesprivs@localhost;
52
show grants for test_yesprivs@localhost;
54
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
55
connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
56
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
57
connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
60
let $message= Testcase 3.5.3.2:;
61
--source include/show_msg.inc
67
# error 1227 is better, as it says, that not the privilege
69
create trigger trg1_1 before INSERT on t1 for each row
70
set new.f1 = 'trig 3.5.3.2_1-no';
74
insert into t1 (f1) values ('insert 3.5.3.2-no');
75
select f1 from t1 order by f1;
81
create trigger trg1_2 before INSERT on t1 for each row
82
set new.f1 = 'trig 3.5.3.2_2-yes';
89
insert into t1 (f1) values ('insert 3.5.3.2-yes');
90
select f1 from t1 order by f1;
92
grant UPDATE on priv_db.t1 to test_yesprivs@localhost;
93
insert into t1 (f1) values ('insert 3.5.3.2-yes');
94
select f1 from t1 order by f1;
96
let $message= Testcase 3.5.3.6:;
97
--source include/show_msg.inc
107
insert into t1 (f1) values ('insert 3.5.3.6-yes');
108
select f1 from t1 order by f1;
110
connection yes_privs;
117
insert into t1 (f1) values ('insert 3.5.3.6-no');
118
select f1 from t1 order by f1;
126
disconnect yes_privs;
131
# Test case: Ensure that use of the construct "SET NEW. <column name> = <value>"
132
# fails at CREATE TRIGGER time, if the current user does not have the
133
# UPDATE privilege on the column specified
134
# Note: As a result of bug 8884 the triggers are actually created.
135
# Disabled because of bug 8884
137
# --- 3.5.3.7a - Privs set on a global level
138
let $message=Testcase 3.5.3.7a:;
139
--source include/show_msg.inc
141
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
142
grant ALL on *.* to test_noprivs@localhost;
143
revoke UPDATE on *.* from test_noprivs@localhost;
144
show grants for test_noprivs@localhost;
146
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
147
grant TRIGGER, UPDATE on *.* to test_yesprivs@localhost;
148
show grants for test_yesprivs@localhost;
150
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
151
connect (no_privs_424a,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
152
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
153
connect (yes_privs_424a,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
155
connection no_privs_424a;
159
select f1 from t1 order by f1;
161
create trigger trg4a_1 before INSERT on t1 for each row
162
set new.f1 = 'trig 3.5.3.7-1a';
165
--error ER_COLUMNACCESS_DENIED_ERROR
166
insert into t1 (f1) values ('insert 3.5.3.7-1a');
167
select f1 from t1 order by f1;
168
drop trigger trg4a_1;
170
connection yes_privs_424a;
174
create trigger trg4a_2 before INSERT on t1 for each row
175
set new.f1 = 'trig 3.5.3.7-2a';
179
insert into t1 (f1) values ('insert 3.5.3.7-2b');
180
select f1 from t1 order by f1;
184
drop trigger trg4a_2;
185
disconnect no_privs_424a;
186
disconnect yes_privs_424a;
189
# --- 3.5.3.7b - Privs set on a database level
190
let $message= Testcase 3.5.3.7b:;
191
--source include/show_msg.inc
193
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
194
grant TRIGGER on *.* to test_noprivs;
195
grant ALL on priv_db.* to test_noprivs@localhost;
196
revoke UPDATE on priv_db.* from test_noprivs@localhost;
197
show grants for test_noprivs;
199
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
200
grant TRIGGER on *.* to test_yesprivs@localhost;
201
grant UPDATE on priv_db.* to test_yesprivs@localhost;
202
show grants for test_yesprivs@localhost;
204
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
205
connect (no_privs_424b,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
206
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
207
connect (yes_privs_424b,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
210
connection no_privs_424b;
214
create trigger trg4b_1 before UPDATE on t1 for each row
215
set new.f1 = 'trig 3.5.3.7-1b';
218
insert into t1 (f1) values ('insert 3.5.3.7-1b');
219
select f1 from t1 order by f1;
220
update t1 set f1 = 'update 3.5.3.7-1b' where f1 = 'insert 3.5.3.7-1b';
221
select f1 from t1 order by f1;
222
drop trigger trg4b_1;
224
connection yes_privs_424b;
227
create trigger trg4b_2 before UPDATE on t1 for each row
228
set new.f1 = 'trig 3.5.3.7-2b';
232
insert into t1 (f1) values ('insert 3.5.3.7-2b');
233
select f1 from t1 order by f1;
234
update t1 set f1 = 'update 3.5.3.7-2b' where f1 = 'insert 3.5.3.7-2b';
235
select f1 from t1 order by f1;
238
drop trigger trg4b_2;
239
disconnect no_privs_424b;
240
disconnect yes_privs_424b;
243
# --- 3.5.3.7c - Privs set on a table level
244
let $message= Testcase 3.5.3.7c;
245
--source include/show_msg.inc
247
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
248
grant TRIGGER on *.* to test_noprivs@localhost;
249
grant ALL on priv_db.t1 to test_noprivs@localhost;
250
revoke UPDATE on priv_db.t1 from test_noprivs@localhost;
251
show grants for test_noprivs;
253
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
254
grant TRIGGER on *.* to test_yesprivs@localhost;
255
grant UPDATE on priv_db.t1 to test_yesprivs@localhost;
256
show grants for test_yesprivs@localhost;
258
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
259
connect (no_privs_424c,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
260
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK 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
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
312
connect (no_privs_424d,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
313
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
314
connect (yes_privs_424d,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
317
connection no_privs_424d;
320
create trigger trg4d_1 before INSERT on t1 for each row
321
set new.f1 = 'trig 3.5.3.7-1d';
324
insert into t1 (f1) values ('insert 3.5.3.7-1d');
325
select f1 from t1 order by f1;
326
drop trigger trg4d_1;
328
connection yes_privs_424d;
331
create trigger trg4d_2 before INSERT on t1 for each row
332
set new.f1 = 'trig 3.5.3.7-2d';
336
insert into t1 (f1) values ('insert 3.5.3.7-2d');
337
select f1 from t1 order by f1;
341
drop trigger trg4d_2;
342
disconnect no_privs_424d;
343
disconnect yes_privs_424d;
347
# Test case: Ensure that use of the construct "SET <target> = NEW. <Column name>" fails
348
# at CREATE TRIGGER time, if the current user does not have the SELECT privilege
349
# on the column specified.
351
# --- 3.5.3.8a - Privs set on a global level
352
let $message= Testcase 3.5.3.8a:;
353
--source include/show_msg.inc
355
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
356
grant ALL on *.* to test_noprivs@localhost;
357
revoke SELECT on *.* from test_noprivs@localhost;
358
show grants for test_noprivs@localhost;
360
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
361
grant TRIGGER, SELECT on *.* to test_yesprivs@localhost;
362
show grants for test_yesprivs@localhost;
364
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
365
connect (no_privs_425a,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
366
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
367
connect (yes_privs_425a,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
370
connection no_privs_425a;
375
create trigger trg5a_1 before INSERT on t1 for each row
376
set @test_var = new.f1;
379
set @test_var = 'before trig 3.5.3.8-1a';
381
insert into t1 (f1) values ('insert 3.5.3.8-1a');
383
drop trigger trg5a_1;
385
connection yes_privs_425a;
389
create trigger trg5a_2 before INSERT on t1 for each row
390
set @test_var= new.f1;
393
set @test_var= 'before trig 3.5.3.8-2a';
396
insert into t1 (f1) values ('insert 3.5.3.8-2a');
401
drop trigger trg5a_2;
402
disconnect no_privs_425a;
403
disconnect yes_privs_425a;
406
# --- 3.5.3.8b - Privs set on a database level
407
let $message= Testcase: 3.5.3.8b;
408
--source include/show_msg.inc
410
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
411
grant TRIGGER on *.* to test_noprivs@localhost;
412
grant ALL on priv_db.* to test_noprivs@localhost;
413
revoke SELECT on priv_db.* from test_noprivs@localhost;
414
show grants for test_noprivs@localhost;
416
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
417
grant TRIGGER on *.* to test_yesprivs@localhost;
418
grant SELECT on priv_db.* to test_yesprivs@localhost;
419
show grants for test_yesprivs@localhost;
421
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
422
connect (no_privs_425b,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
423
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
424
connect (yes_privs_425b,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
427
connection no_privs_425b;
431
create trigger trg5b_1 before UPDATE on t1 for each row
432
set @test_var= new.f1;
435
set @test_var= 'before trig 3.5.3.8-1b';
436
insert into t1 (f1) values ('insert 3.5.3.8-1b');
438
update t1 set f1= 'update 3.5.3.8-1b' where f1 = 'insert 3.5.3.8-1b';
440
drop trigger trg5b_1;
442
connection yes_privs_425b;
445
create trigger trg5b_2 before UPDATE on t1 for each row
446
set @test_var= new.f1;
449
set @test_var= 'before trig 3.5.3.8-2b';
450
insert into t1 (f1) values ('insert 3.5.3.8-2b');
453
update t1 set f1= 'update 3.5.3.8-2b' where f1 = 'insert 3.5.3.8-2b';
457
drop trigger trg5b_2;
458
disconnect no_privs_425b;
459
disconnect yes_privs_425b;
462
# --- 3.5.3.8c - Privs set on a table level
463
let $message= Testcase 3.5.3.8c:;
464
--source include/show_msg.inc
466
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
467
grant TRIGGER on *.* to test_noprivs@localhost;
468
grant ALL on priv_db.t1 to test_noprivs@localhost;
469
revoke SELECT on priv_db.t1 from test_noprivs@localhost;
470
show grants for test_noprivs@localhost;
472
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
473
grant TRIGGER on *.* to test_yesprivs@localhost;
474
grant SELECT on priv_db.t1 to test_yesprivs@localhost;
475
show grants for test_yesprivs@localhost;
477
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
478
connect (no_privs_425c,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
479
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
480
connect (yes_privs_425c,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
483
connection no_privs_425c;
487
create trigger trg5c_1 before INSERT on t1 for each row
488
set @test_var= new.f1;
491
set @test_var= 'before trig 3.5.3.8-1c';
492
insert into t1 (f1) values ('insert 3.5.3.8-1c');
494
drop trigger trg5c_1;
496
connection yes_privs_425c;
499
create trigger trg5c_2 before INSERT on t1 for each row
500
set @test_var= new.f1;
503
set @test_var='before trig 3.5.3.8-2c';
505
insert into t1 (f1) values ('insert 3.5.3.8-2c');
509
drop trigger trg5c_2;
510
disconnect no_privs_425c;
511
disconnect yes_privs_425c;
514
# --- 3.5.3.8d - Privs set on a column level
515
let $message=Testcase: 3.5.3.8d:;
516
--source include/show_msg.inc
518
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
519
grant TRIGGER on *.* to test_noprivs@localhost;
520
# There is no ALL prov on the column level
521
grant UPDATE (f1), INSERT (f1) on priv_db.t1 to test_noprivs@localhost;
522
show grants for test_noprivs@localhost;
524
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
525
grant TRIGGER on *.* to test_yesprivs@localhost;
526
grant SELECT (f1) on priv_db.t1 to test_yesprivs@localhost;
527
show grants for test_noprivs@localhost;
529
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
530
connect (no_privs_425d,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
531
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
532
connect (yes_privs_425d,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
535
connection no_privs_425d;
538
create trigger trg5d_1 before INSERT on t1 for each row
539
set @test_var= new.f1;
542
set @test_var='before trig 3.5.3.8-1d';
543
insert into t1 (f1) values ('insert 3.5.3.8-1d');
545
drop trigger trg5d_1;
547
connection yes_privs_425d;
550
create trigger trg5d_2 before INSERT on t1 for each row
551
set @test_var= new.f1;
554
set @test_var='before trig 3.5.3.8-2d';
556
insert into t1 (f1) values ('insert 3.5.3.8-2d');
561
drop trigger trg5d_2;
564
# --- 3.5.3.x to test for trigger definer privs in the case of trigger
565
# actions (insert/update/delete/select) performed on other
567
let $message=Testcase: 3.5.3.x:;
568
--source include/show_msg.inc
572
drop table if exists t1;
573
drop table if exists t2;
576
eval create table t1 (f1 int) engine= $engine_type;
577
eval create table t2 (f2 int) engine= $engine_type;
579
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
580
grant TRIGGER on *.* to test_yesprivs@localhost;
581
grant SELECT, UPDATE on priv_db.t1 to test_yesprivs@localhost;
582
grant SELECT on priv_db.t2 to test_yesprivs@localhost;
583
show grants for test_yesprivs@localhost;
585
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
586
connect (yes_353x,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
592
create trigger trg1 before insert on t1 for each row
593
insert into t2 values (new.f1);
597
insert into t1 (f1) values (4);
598
revoke SELECT on priv_db.t2 from test_yesprivs@localhost;
599
grant INSERT on priv_db.t2 to test_yesprivs@localhost;
600
insert into t1 (f1) values (4);
601
select f1 from t1 order by f1;
602
select f2 from t2 order by f2;
608
create trigger trg2 before insert on t1 for each row
609
update t2 set f2=new.f1-1;
613
insert into t1 (f1) values (2);
614
revoke INSERT on priv_db.t2 from test_yesprivs@localhost;
615
grant UPDATE on priv_db.t2 to test_yesprivs@localhost;
616
insert into t1 (f1) values (2);
617
select f1 from t1 order by f1;
618
select f2 from t2 order by f2;
624
create trigger trg3 before insert on t1 for each row
625
select f2 into @aaa from t2 where f2=new.f1;
629
insert into t1 (f1) values (1);
630
revoke UPDATE on priv_db.t2 from test_yesprivs@localhost;
631
grant SELECT on priv_db.t2 to test_yesprivs@localhost;
632
insert into t1 (f1) values (1);
633
select f1 from t1 order by f1;
634
select f2 from t2 order by f2;
641
create trigger trg4 before insert on t1 for each row
646
insert into t1 (f1) values (1);
647
revoke SELECT on priv_db.t2 from test_yesprivs@localhost;
648
grant DELETE on priv_db.t2 to test_yesprivs@localhost;
649
insert into t1 (f1) values (1);
650
select f1 from t1 order by f1;
651
select f2 from t2 order by f2;
657
drop database if exists priv_db;
658
drop user test_yesprivs@localhost;
659
drop user test_noprivs@localhost;
660
drop user test_noprivs;