1
by brian
clean slate |
1 |
#====================================================================== |
2 |
#
|
|
3 |
# Trigger Tests |
|
4 |
# test cases for TRIGGER privilege on db, table and column level |
|
5 |
#====================================================================== |
|
6 |
||
7 |
--disable_abort_on_error |
|
8 |
||
9 |
###########################################
|
|
10 |
################ Section 3.5.3 ############ |
|
11 |
# Check for the definer of Triggers # |
|
12 |
###########################################
|
|
13 |
||
14 |
# General setup to be used in all testcases |
|
15 |
let $message= ######### Testcase for definer: ########; |
|
16 |
--source include/show_msg.inc |
|
17 |
||
18 |
--disable_warnings |
|
19 |
drop database if exists priv_db; |
|
20 |
--enable_warnings |
|
21 |
create database priv_db; |
|
22 |
use priv_db; |
|
23 |
eval create table t1 (f1 char(20)) engine= $engine_type; |
|
24 |
||
25 |
create User test_yesprivs@localhost; |
|
26 |
set password for test_yesprivs@localhost = password('PWD'); |
|
27 |
||
28 |
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost; |
|
29 |
||
30 |
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK |
|
31 |
connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK); |
|
32 |
||
33 |
# create trigger with not existing definer shall deliver a warning: |
|
34 |
connection default; |
|
35 |
select current_user; |
|
36 |
# --warning 1449 |
|
37 |
create definer=not_ex_user@localhost trigger trg1_0 |
|
38 |
before INSERT on t1 for each row |
|
39 |
set new.f1 = 'trig 1_0-yes'; |
|
40 |
drop trigger trg1_0; |
|
41 |
# create trigger with definer test_yesprivs@localhost->succeed: |
|
42 |
create definer=test_yesprivs@localhost trigger trg1_0 |
|
43 |
before INSERT on t1 for each row |
|
44 |
set new.f1 = 'trig 1_0-yes'; |
|
45 |
grant select, insert, update |
|
46 |
on priv_db.t1 to test_yesprivs@localhost; |
|
47 |
||
48 |
connection yes_privs; |
|
49 |
select current_user; |
|
50 |
use priv_db; |
|
51 |
# user hasn't trigger privilege->fail: |
|
52 |
--error 1142 |
|
53 |
insert into t1 (f1) values ('insert-no'); |
|
54 |
select f1 from t1 order by f1; |
|
55 |
--error 1142 |
|
56 |
drop trigger trg1_0; |
|
57 |
||
58 |
connection default; select current_user; grant select, insert, update ,trigger |
|
59 |
on priv_db.t1 to test_yesprivs@localhost; |
|
60 |
show grants for test_yesprivs@localhost; |
|
61 |
||
62 |
connection yes_privs; |
|
63 |
select current_user; |
|
64 |
# user now has trigger privilege->succeed: |
|
65 |
insert into t1 (f1) values ('insert-no'); |
|
66 |
select f1 from t1 order by f1; |
|
67 |
drop trigger trg1_0; |
|
68 |
# user has not super privilege->fail: |
|
69 |
--error 1227 |
|
70 |
create definer=not_ex_user@localhost trigger trg1_0 |
|
71 |
before INSERT on t1 for each row |
|
72 |
set new.f1 = 'trig 1_0-yes'; |
|
73 |
# shall always succeed: |
|
74 |
create definer=current_user trigger trg1_1 |
|
75 |
before INSERT on t1 for each row |
|
76 |
set new.f1 = 'trig 1_1-yes'; |
|
77 |
insert into t1 (f1) values ('insert-no'); |
|
78 |
select f1 from t1 order by f1; |
|
79 |
# shall always succeed: |
|
80 |
create definer=test_yesprivs@localhost trigger trg1_2 |
|
81 |
before UPDATE on t1 for each row |
|
82 |
set new.f1 = 'trig 1_2-yes'; |
|
83 |
update t1 set f1 = 'update-yes' where f1 like '%trig%'; |
|
84 |
select f1 from t1 order by f1; |
|
85 |
||
86 |
connection default; |
|
87 |
select current_user; |
|
88 |
grant trigger on priv_db.* to test_yesprivs@localhost |
|
89 |
with grant option; |
|
90 |
||
91 |
# user has not super privilege->fail: |
|
92 |
connection yes_privs; |
|
93 |
select current_user; |
|
94 |
show grants; |
|
95 |
--error 1227 |
|
96 |
create definer=not_ex_user@localhost trigger trg1_3 |
|
97 |
after UPDATE on t1 for each row |
|
98 |
set @var1 = 'trig 1_3-yes'; |
|
99 |
||
100 |
connection default; |
|
101 |
select current_user; |
|
102 |
||
103 |
# Cleanup prepare |
|
104 |
--disable_warnings |
|
105 |
disconnect yes_privs; |
|
106 |
||
107 |
connection default; |
|
108 |
select current_user; |
|
109 |
--enable_warnings |
|
110 |
||
111 |
||
112 |
# general Cleanup |
|
113 |
--disable_warnings |
|
114 |
drop database if exists priv_db; |
|
115 |
drop user test_yesprivs@localhost; |
|
116 |
--enable_warnings |
|
117 |