MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
triggers_03e_prepare.inc
1 #======================================================================
2 #
3 # Trigger Tests
4 # test cases for TRIGGER privilege on db, table and column level
5 # These tests ensure that at activation time (execute statement)
6 # the user must have trigger privilege.
7 #======================================================================
8 
9 --disable_abort_on_error
10 
11 ###########################################################
12 ################ Section 3.5.3 ############################
13 # Check for the trigger privilege in case of prepare/exec #
14 ###########################################################
15 
16 # General setup to be used in all testcases
17 let $message= #### Testcase for trigger privilege on execution time ########;
18 --source include/show_msg.inc
19 
20  --disable_warnings
21  drop database if exists priv_db;
22  --enable_warnings
23  create database priv_db;
24  use priv_db;
25  eval create table t1 (f1 char(20)) engine= $engine_type;
26 
27  create User test_yesprivs@localhost;
28  set password for test_yesprivs@localhost = password('PWD');
29  create User test_useprivs@localhost;
30  set password for test_useprivs@localhost = password('PWD');
31 
32  revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
33  revoke ALL PRIVILEGES, GRANT OPTION FROM test_useprivs@localhost;
34 
35  connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
36 
37  connection default;
38  select current_user;
39  show triggers;
40  grant select, insert, update ,trigger
41  on priv_db.t1 to test_yesprivs@localhost
42  with grant option;
43  grant select
44  on priv_db.t1 to test_useprivs@localhost;
45  show grants for test_yesprivs@localhost;
46 
47  connection yes_privs;
48  select current_user;
49  use priv_db;
50  create trigger trg1_1 before INSERT on t1 for each row
51  set new.f1 = 'trig 1_1-yes';
52  grant insert on t1 to test_useprivs@localhost;
53  prepare ins1 from 'insert into t1 (f1) values (''insert1-no'')';
54  execute ins1;
55  select f1 from t1 order by f1;
56  prepare ins1 from 'insert into t1 (f1) values (''insert2-no'')';
57 
58  connect (use_privs,localhost,test_useprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
59  select current_user;
60  use priv_db;
61  prepare ins1 from 'insert into t1 (f1) values (''insert3-no'')';
62  execute ins1;
63  select f1 from t1 order by f1;
64 
65  connection default;
66  select current_user;
67  revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
68  show grants for test_yesprivs@localhost;
69 
70  connection yes_privs;
71  select current_user;
72  --error ER_TABLEACCESS_DENIED_ERROR
73  execute ins1;
74  select f1 from t1 order by f1;
75  prepare ins1 from 'insert into t1 (f1) values (''insert4-no'')';
76 
77  connection use_privs;
78  select current_user;
79  prepare ins1 from 'insert into t1 (f1) values (''insert5-no'')';
80  --error ER_TABLEACCESS_DENIED_ERROR
81  execute ins1;
82  select f1 from t1 order by f1;
83 
84  connection default;
85  select current_user;
86  grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
87  show grants for test_yesprivs@localhost;
88 
89  connection yes_privs;
90  select current_user;
91  execute ins1;
92  select f1 from t1 order by f1;
93  prepare ins1 from 'insert into t1 (f1) values (''insert6-no'')';
94 
95  connection use_privs;
96  select current_user;
97  execute ins1;
98  select f1 from t1 order by f1;
99  prepare ins1 from 'insert into t1 (f1) values (''insert7-no'')';
100 
101  connection default;
102  select current_user;
103  revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
104  show grants for test_yesprivs@localhost;
105 
106  connection yes_privs;
107  select current_user;
108  --error ER_TABLEACCESS_DENIED_ERROR
109  execute ins1;
110  select f1 from t1 order by f1;
111 
112  connection use_privs;
113  select current_user;
114  --error ER_TABLEACCESS_DENIED_ERROR
115  execute ins1;
116  select f1 from t1 order by f1;
117 
118  connection default;
119  select current_user;
120  grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
121  show grants for test_yesprivs@localhost;
122 
123  connection yes_privs;
124  select current_user;
125  execute ins1;
126  select f1 from t1 order by f1;
127 
128  connection use_privs;
129  select current_user;
130  execute ins1;
131  select f1 from t1 order by f1;
132 
133  connection default;
134  select current_user;
135  revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
136  show grants for test_yesprivs@localhost;
137 
138  connection yes_privs;
139  select current_user;
140  execute ins1;
141  select f1 from t1 order by f1;
142  deallocate prepare ins1;
143 
144  connection use_privs;
145  select current_user;
146  execute ins1;
147  select f1 from t1 order by f1;
148  deallocate prepare ins1;
149 
150  connection default;
151  select current_user;
152  grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
153  show grants for test_yesprivs@localhost;
154 
155  connection yes_privs;
156  select current_user;
157  drop trigger trg1_1;
158 
159  connection default;
160  select current_user;
161 
162 # Cleanup prepare
163  --disable_warnings
164  disconnect yes_privs;
165 
166  connection default;
167  select current_user;
168  --enable_warnings
169 
170 
171 # general Cleanup
172  --disable_warnings
173  drop database if exists priv_db;
174  drop user test_yesprivs@localhost;
175  drop user test_useprivs@localhost;
176  --enable_warnings
177