1 #### suite/funcs_1/storedproc/storedproc_06.inc
3 # This test cannot be used for the embedded server because we check here
5 --source include/not_embedded.inc
7 --source suite/funcs_1/storedproc/load_sp_tb.inc
9 # ==============================================================================
10 # (numbering from requirement document TP v1.0, Last updated: 25 Jan 2005 01:00)
12 # 3.1.6 Privilege checks:
14 # 1. Ensure that no user may create a stored procedure without the
15 # GRANT CREATE ROUTINE privilege.
16 # 2. Ensure that root always has the GRANT CREATE ROUTINE privilege.
17 # 3. Ensure that a user with the GRANT CREATE ROUTINE privilege can always
18 # create both a procedure and a function, on any appropriate database.
19 # 4. Ensure that the default security provision of a stored procedure is
20 # SQL SECURITY DEFINER.
21 # 5. Ensure that a stored procedure defined with SQL SECURITY DEFINER can be
22 # called/executed by any user, using only the privileges (including
23 # database access privileges) associated with the user who created
24 # the stored procedure.
25 # 6. Ensure that a stored procedure defined with SQL SECURITY INVOKER can be
26 # called/executed by any user, using only the privileges (including
27 # database access privileges) associated with the user executing
28 # the stored procedure.
30 # ==============================================================================
31 let $message= Section 3.1.6 - Privilege Checks:;
32 --source include/show_msg80.inc
37 --source suite/funcs_1/include/show_connection.inc
39 # ------------------------------------------------------------------------------
40 let $message= Testcase 3.1.6.1:
42 Ensure that no user may create a stored procedure without the GRANT CREATE
44 --source include/show_msg80.inc
46 create user
'user_1'@
'localhost';
48 grant all on db_storedproc_1.*
to 'user_1'@
'localhost';
49 revoke create routine on db_storedproc_1.* from
'user_1'@
'localhost';
53 DROP PROCEDURE IF EXISTS sp1;
56 connect (user1a, localhost, user_1, , db_storedproc_1);
57 --source suite/funcs_1/include/show_connection.inc
62 --error ER_DBACCESS_DENIED_ERROR
63 CREATE PROCEDURE sp1(v1
char(20))
65 SELECT * from db_storedproc_1.t6 where t6.f2= 'xyz';
71 # add privilege again and check
74 --source suite/funcs_1/include/show_connection.inc
76 GRANT CREATE ROUTINE ON db_storedproc_1.* TO
'user_1'@
'localhost';
77 connect (user1b, localhost, user_1, , db_storedproc_1);
78 --source suite/funcs_1/include/show_connection.inc
83 CREATE PROCEDURE sp1(v1
char(20))
85 SELECT * from db_storedproc_1.t6 where t6.f2= 'xyz';
93 --source suite/funcs_1/include/show_connection.inc
95 DROP USER
'user_1'@
'localhost';
99 # ------------------------------------------------------------------------------
100 let $message= Testcase 3.1.6.2:
102 Ensure that root always has the GRANT CREATE ROUTINE privilege.
103 (checked by other testscases);
104 --source include/show_msg80.inc
107 # ------------------------------------------------------------------------------
108 let $message= Testcase 3.1.6.3:
110 Ensure that a user with the GRANT CREATE ROUTINE privilege can always create
111 both a procedure and a
function, on any appropriate database.
112 --source include/show_msg80.inc
115 create user
'user_1'@
'localhost';
117 grant create routine on db_storedproc_1.*
to 'user_1'@
'localhost';
121 DROP PROCEDURE IF EXISTS db_storedproc_1.sp3;
122 DROP FUNCTION IF EXISTS db_storedproc_1.fn1;
125 # disconnect default;
126 connect (user2, localhost, user_1, , db_storedproc_1);
127 --source suite/funcs_1/include/show_connection.inc
130 CREATE PROCEDURE sp3(v1
char(20))
132 SELECT * from db_storedproc_1.t6 where t6.f2= 'xyz';
137 CREATE FUNCTION fn1(v1
int) returns
int
148 --source suite/funcs_1/include/show_connection.inc
150 drop user
'user_1'@
'localhost';
155 # ------------------------------------------------------------------------------
156 let $message= Testcase 3.1.6.4:
158 Ensure that the
default security provision of a stored procedure is SQL SECURITY
160 --source include/show_msg80.inc
162 CREATE USER
'user_1'@
'localhost';
164 grant update on db_storedproc_1.t6
to 'user_1'@
'localhost';
165 grant execute on db_storedproc_1.*
to 'user_1'@
'localhost';
171 DROP PROCEDURE IF EXISTS sp4;
175 CREATE PROCEDURE sp4(v1
char(20))
177 SELECT * from db_storedproc_1.t6 where t6.f2= 'xyz';
183 connect (user3, localhost, user_1, , db_storedproc_1);
184 --source suite/funcs_1/include/show_connection.inc
190 SELECT SPECIFIC_NAME, ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE,
191 ROUTINE_BODY, ROUTINE_DEFINITION, IS_DETERMINISTIC,
192 SQL_DATA_ACCESS, SECURITY_TYPE, SQL_MODE, ROUTINE_COMMENT
193 FROM information_schema.routines
194 WHERE routine_schema LIKE
'db_sto%';
201 --source suite/funcs_1/include/show_connection.inc
203 DROP USER
'user_1'@
'localhost';
206 # ------------------------------------------------------------------------------
207 let $message= Testcase 3.1.6.5:
209 Ensure that a stored procedure defined with SQL SECURITY DEFINER can be
210 called/executed by any user,
using only the privileges (including database
211 access privileges) associated with the user who created the stored procedure.;
212 --source include/show_msg80.inc
215 CREATE
TABLE t3165 ( c1
char(20), c2
char(20), c3 date);
216 INSERT INTO t3165 VALUES (
'inserted',
'outside of SP', NULL);
219 create user
'user_1'@
'localhost';
222 create user
'user_2'@
'localhost';
224 grant create routine on db_storedproc_1.*
to 'user_1'@
'localhost';
225 grant SELECT on db_storedproc_1.*
to 'user_2'@
'localhost';
226 grant execute on db_storedproc_1.*
to 'user_2'@
'localhost';
229 connect (user5_1, localhost, user_1, , db_storedproc_1);
230 --source suite/funcs_1/include/show_connection.inc
233 CREATE PROCEDURE sp5_s_i () sql security definer
235 SELECT * from db_storedproc_1.t3165;
236 insert into db_storedproc_1.t3165 values ('inserted', 'from sp5_s_i', 1000);
239 CREATE PROCEDURE sp5_sel () sql security definer
241 SELECT * from db_storedproc_1.t3165;
244 CREATE PROCEDURE sp5_ins () sql security definer
246 insert into db_storedproc_1.t3165 values ('inserted', 'from sp5_ins', 1000);
252 connect (user5_2, localhost, user_2, , db_storedproc_1);
253 --source suite/funcs_1/include/show_connection.inc
255 --error ER_TABLEACCESS_DENIED_ERROR
257 --error ER_TABLEACCESS_DENIED_ERROR
259 --error ER_TABLEACCESS_DENIED_ERROR
262 # now 'add' INSERT to DEFINER
264 --source suite/funcs_1/include/show_connection.inc
265 --error ER_TABLEACCESS_DENIED_ERROR
267 grant insert on db_storedproc_1.*
to 'user_1'@
'localhost';
271 --source suite/funcs_1/include/show_connection.inc
272 --error ER_TABLEACCESS_DENIED_ERROR
275 --error ER_TABLEACCESS_DENIED_ERROR
278 # now 'add' SELECT to DEFINER
280 --source suite/funcs_1/include/show_connection.inc
281 --error ER_TABLEACCESS_DENIED_ERROR
283 grant SELECT on db_storedproc_1.*
to 'user_1'@
'localhost';
284 #grant execute on db_storedproc_1.* to 'user_2'@'localhost';
288 --source suite/funcs_1/include/show_connection.inc
293 # now revoke INSERT FROM DEFINER
295 --source suite/funcs_1/include/show_connection.inc
296 REVOKE INSERT on db_storedproc_1.* from
'user_1'@
'localhost';
300 --source suite/funcs_1/include/show_connection.inc
301 --error ER_TABLEACCESS_DENIED_ERROR
303 --error ER_TABLEACCESS_DENIED_ERROR
307 # now revoke SELECT FROM DEFINER
309 --source suite/funcs_1/include/show_connection.inc
310 REVOKE SELECT on db_storedproc_1.* from
'user_1'@
'localhost';
314 --source suite/funcs_1/include/show_connection.inc
315 --error ER_TABLEACCESS_DENIED_ERROR
317 --error ER_TABLEACCESS_DENIED_ERROR
319 --error ER_TABLEACCESS_DENIED_ERROR
325 --source suite/funcs_1/include/show_connection.inc
327 DROP PROCEDURE sp5_s_i;
328 DROP PROCEDURE sp5_sel;
329 DROP PROCEDURE sp5_ins;
331 DROP USER
'user_1'@
'localhost';
332 DROP USER
'user_2'@
'localhost';
335 # ------------------------------------------------------------------------------
336 let $message= Testcase 3.1.6.6:
338 Ensure that a stored procedure defined with SQL SECURITY INVOKER can be
339 called/executed by any user,
using only the privileges (including database
340 access privileges) associated with the user executing the stored procedure.;
341 --source include/show_msg80.inc
344 CREATE
TABLE t3166 ( c1
char(30) );
345 INSERT INTO db_storedproc_1.t3166 VALUES (
'inserted outside SP');
348 create user
'user_1'@
'localhost';
351 create user
'user_2'@
'localhost';
353 GRANT CREATE ROUTINE ON db_storedproc_1.* TO
'user_1'@
'localhost';
354 GRANT SELECT ON db_storedproc_1.* TO
'user_2'@
'localhost';
355 GRANT EXECUTE ON db_storedproc_1.* TO
'user_2'@
'localhost';
358 connect (user6_1, localhost, user_1, , db_storedproc_1);
359 --source suite/funcs_1/include/show_connection.inc
362 CREATE PROCEDURE sp3166_s_i () SQL SECURITY INVOKER
364 SELECT * from db_storedproc_1.t3166;
365 insert into db_storedproc_1.t3166 values ('inserted from sp3166_s_i');
368 CREATE PROCEDURE sp3166_sel () SQL SECURITY INVOKER
370 SELECT * from db_storedproc_1.t3166;
373 CREATE PROCEDURE sp3166_ins () SQL SECURITY INVOKER
375 insert into db_storedproc_1.t3166 values ('inserted from sp3166_ins');
381 connect (user6_2, localhost, user_2, , db_storedproc_1);
382 --source suite/funcs_1/include/show_connection.inc
384 --error ER_TABLEACCESS_DENIED_ERROR
386 --error ER_TABLEACCESS_DENIED_ERROR
390 # now 'add' INSERT to INVOKER
392 --source suite/funcs_1/include/show_connection.inc
394 GRANT INSERT ON db_storedproc_1.* TO
'user_2'@
'localhost';
398 connect (user6_3, localhost, user_2, , db_storedproc_1);
399 --source suite/funcs_1/include/show_connection.inc
405 # now 'remove' SELECT from INVOKER
407 --source suite/funcs_1/include/show_connection.inc
409 REVOKE SELECT ON db_storedproc_1.* FROM
'user_2'@
'localhost';
412 connect (user6_4, localhost, user_2, , db_storedproc_1);
413 --source suite/funcs_1/include/show_connection.inc
414 --error ER_TABLEACCESS_DENIED_ERROR
417 --error ER_TABLEACCESS_DENIED_ERROR
421 # now 'remove' EXECUTE FROM INVOKER
424 --source suite/funcs_1/include/show_connection.inc
425 REVOKE EXECUTE on db_storedproc_1.* FROM
'user_2'@
'localhost';
428 connect (user6_5, localhost, user_2, , db_storedproc_1);
429 --source suite/funcs_1/include/show_connection.inc
430 --error ER_PROCACCESS_DENIED_ERROR
432 --error ER_PROCACCESS_DENIED_ERROR
434 --error ER_PROCACCESS_DENIED_ERROR
440 --source suite/funcs_1/include/show_connection.inc
442 DROP PROCEDURE sp3166_s_i;
443 DROP PROCEDURE sp3166_sel;
444 DROP PROCEDURE sp3166_ins;
446 DROP USER
'user_1'@
'localhost';
447 DROP USER
'user_2'@
'localhost';
450 # ==============================================================================
451 # USE the same .inc to cleanup before and after the test
452 --source suite/funcs_1/storedproc/cleanup_sp_tb.inc
454 # ==============================================================================
456 --echo . +++ END OF SCRIPT +++
457 --echo --------------------------------------------------------------------------------
458 # ==============================================================================