~ubuntu-branches/ubuntu/lucid/mysql-dfsg-5.1/lucid-security

« back to all changes in this revision

Viewing changes to mysql-test/suite/engines/funcs/t/rpl_sp.test

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 22:33:55 UTC
  • mto: (1.2.1) (37.1.1 lucid-security)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: package-import@ubuntu.com-20120222223355-ku1tb4r70osci6v2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# row-based and statement have expected binlog difference in result files
 
2
 
 
3
# Test of replication of stored procedures (WL#2146 for MySQL 5.0)
 
4
# Modified by WL#2971.
 
5
 
 
6
# Note that in the .opt files we still use the old variable name
 
7
# log-bin-trust-routine-creators so that this test checks that it's
 
8
# still accepted (this test also checks that the new name is
 
9
# accepted). The old name could be removed in 5.1 or 6.0.
 
10
 
 
11
source include/have_binlog_format_mixed.inc;
 
12
source include/master-slave.inc;
 
13
 
 
14
# we need a db != test, where we don't have automatic grants
 
15
--disable_warnings
 
16
drop database if exists mysqltest1;
 
17
--enable_warnings
 
18
create database mysqltest1;
 
19
use mysqltest1;
 
20
create table t1 (a varchar(100));
 
21
sync_slave_with_master;
 
22
use mysqltest1;
 
23
 
 
24
# ********************** PART 1 : STORED PROCEDURES ***************
 
25
 
 
26
# Does the same proc as on master get inserted into mysql.proc ?
 
27
# (same definer, same properties...)
 
28
 
 
29
connection master;
 
30
 
 
31
delimiter |;
 
32
 
 
33
# Stored procedures don't have the limitations that functions have
 
34
# regarding binlogging: it's ok to create a procedure as not
 
35
# deterministic and updating data, while it's not ok to create such a
 
36
# function. We test this.
 
37
 
 
38
create procedure foo()
 
39
begin
 
40
  declare b int;
 
41
  set b = 8;
 
42
  insert into t1 values (b);
 
43
  insert into t1 values (unix_timestamp());
 
44
end|
 
45
delimiter ;|
 
46
 
 
47
# we replace columns having times
 
48
# (even with fixed timestamp displayed time may changed based on TZ)
 
49
--replace_result localhost.localdomain localhost 127.0.0.1 localhost
 
50
--replace_column 13 # 14 #
 
51
select * from mysql.proc where name='foo' and db='mysqltest1';
 
52
sync_slave_with_master;
 
53
# You will notice in the result that the definer does not match what
 
54
# it is on master, it is a known bug on which Alik is working
 
55
--replace_result localhost.localdomain localhost 127.0.0.1 localhost
 
56
--replace_column 13 # 14 #
 
57
select * from mysql.proc where name='foo' and db='mysqltest1';
 
58
 
 
59
connection master;
 
60
# see if timestamp used in SP on slave is same as on master
 
61
set timestamp=1000000000;
 
62
call foo();
 
63
select * from t1;
 
64
sync_slave_with_master;
 
65
select * from t1;
 
66
 
 
67
# Now a SP which is not updating tables
 
68
 
 
69
connection master;
 
70
delete from t1;
 
71
create procedure foo2()
 
72
  select * from mysqltest1.t1;
 
73
call foo2();
 
74
 
 
75
# check that this is allowed (it's not for functions):
 
76
alter procedure foo2 contains sql;
 
77
 
 
78
# SP with definer's right
 
79
 
 
80
drop table t1;
 
81
create table t1 (a int);
 
82
create table t2 like t1;
 
83
 
 
84
create procedure foo3()
 
85
  deterministic
 
86
  insert into t1 values (15);
 
87
 
 
88
# let's create a non-privileged user
 
89
grant CREATE ROUTINE, EXECUTE on mysqltest1.* to "zedjzlcsjhd"@127.0.0.1;
 
90
grant SELECT on mysqltest1.t1 to "zedjzlcsjhd"@127.0.0.1;
 
91
grant SELECT, INSERT on mysqltest1.t2 to "zedjzlcsjhd"@127.0.0.1;
 
92
 
 
93
# ToDo: BUG#14931: There is a race between the last grant binlogging, and
 
94
# the binlogging in the new connection made below, causing sporadic test
 
95
# failures due to switched statement order in binlog. To fix this we do
 
96
# SELECT 1 in the first connection before starting the second, ensuring
 
97
# that binlogging is done in the expected order.
 
98
# Please remove this SELECT 1 when BUG#14931 is fixed.
 
99
SELECT 1;
 
100
 
 
101
connect (con1,127.0.0.1,zedjzlcsjhd,,mysqltest1,$MASTER_MYPORT,);
 
102
connection con1;
 
103
 
 
104
# this routine will fail in the second INSERT because of privileges
 
105
delimiter |;
 
106
create procedure foo4()
 
107
  deterministic
 
108
  begin
 
109
  insert into t2 values(3);
 
110
  insert into t1 values (5);
 
111
  end|
 
112
 
 
113
delimiter ;|
 
114
 
 
115
# I add ,0 so that it does not print the error in the test output,
 
116
# because this error is hostname-dependent
 
117
--error 1142,0
 
118
call foo4(); # invoker has no INSERT grant on table t1 => failure
 
119
 
 
120
connection master;
 
121
call foo3(); # success (definer == root)
 
122
show warnings;
 
123
 
 
124
--error 1142,0
 
125
call foo4(); # definer's rights => failure
 
126
 
 
127
# we test replication of ALTER PROCEDURE
 
128
alter procedure foo4 sql security invoker;
 
129
call foo4(); # invoker's rights => success
 
130
show warnings;
 
131
 
 
132
# Note that half-failed procedure calls are ok with binlogging;
 
133
# if we compare t2 on master and slave we see they are identical:
 
134
 
 
135
select * from t1;
 
136
select * from t2;
 
137
sync_slave_with_master;
 
138
select * from t1;
 
139
select * from t2;
 
140
 
 
141
# Test of DROP PROCEDURE
 
142
 
 
143
--replace_result localhost.localdomain localhost 127.0.0.1 localhost
 
144
--replace_column 13 # 14 #
 
145
select * from mysql.proc where name="foo4" and db='mysqltest1';
 
146
connection master;
 
147
drop procedure foo4;
 
148
select * from mysql.proc where name="foo4" and db='mysqltest1';
 
149
sync_slave_with_master;
 
150
select * from mysql.proc where name="foo4" and db='mysqltest1';
 
151
 
 
152
# ********************** PART 2 : FUNCTIONS ***************
 
153
 
 
154
connection master;
 
155
drop procedure foo;
 
156
drop procedure foo2;
 
157
drop procedure foo3;
 
158
 
 
159
delimiter |;
 
160
# check that needs "deterministic"
 
161
--error 1418
 
162
create function fn1(x int)
 
163
       returns int
 
164
begin
 
165
       insert into t1 values (x);
 
166
       return x+2;
 
167
end|
 
168
create function fn1(x int)
 
169
       returns int
 
170
       deterministic
 
171
begin
 
172
       insert into t1 values (x);
 
173
       return x+2;
 
174
end|
 
175
 
 
176
delimiter ;|
 
177
delete t1,t2 from t1,t2;
 
178
select fn1(20);
 
179
insert into t2 values(fn1(21));
 
180
--sorted_result
 
181
select * from t1;
 
182
select * from t2;
 
183
sync_slave_with_master;
 
184
--sorted_result
 
185
select * from t1;
 
186
select * from t2;
 
187
 
 
188
connection master;
 
189
delimiter |;
 
190
 
 
191
drop function fn1;
 
192
 
 
193
create function fn1()
 
194
       returns int
 
195
       no sql
 
196
begin
 
197
       return unix_timestamp();
 
198
end|
 
199
 
 
200
delimiter ;|
 
201
# check that needs "deterministic"
 
202
--error 1418
 
203
alter function fn1 contains sql;
 
204
 
 
205
delete from t1;
 
206
set timestamp=1000000000;
 
207
insert into t1 values(fn1()); 
 
208
 
 
209
connection con1;
 
210
 
 
211
delimiter |;
 
212
--error 1419 # only full-global-privs user can create a function
 
213
create function fn2()
 
214
       returns int
 
215
       no sql
 
216
begin
 
217
       return unix_timestamp();
 
218
end|
 
219
delimiter ;|
 
220
connection master;
 
221
# test old variable name:
 
222
set global log_bin_trust_routine_creators=1;
 
223
# now use new name:
 
224
set global log_bin_trust_function_creators=0;
 
225
set global log_bin_trust_function_creators=1;
 
226
# slave needs it too otherwise will not execute what master allowed:
 
227
connection slave;
 
228
set global log_bin_trust_function_creators=1;
 
229
 
 
230
connection con1;
 
231
 
 
232
delimiter |;
 
233
create function fn2()
 
234
       returns int
 
235
       no sql
 
236
begin
 
237
       return unix_timestamp();
 
238
end|
 
239
delimiter ;|
 
240
 
 
241
connection master;
 
242
 
 
243
# Now a function which is supposed to not update tables
 
244
# as it's "reads sql data", so should not give error even if
 
245
# non-deterministic.
 
246
 
 
247
delimiter |;
 
248
create function fn3()
 
249
       returns int
 
250
       not deterministic
 
251
       reads sql data
 
252
begin
 
253
  return 0;
 
254
end|
 
255
delimiter ;|
 
256
 
 
257
select fn3();
 
258
--replace_result localhost.localdomain localhost 127.0.0.1 localhost
 
259
--replace_column 13 # 14 #
 
260
select * from mysql.proc where db='mysqltest1';
 
261
select * from t1;
 
262
 
 
263
sync_slave_with_master;
 
264
use mysqltest1;
 
265
select * from t1;
 
266
--replace_result localhost.localdomain localhost 127.0.0.1 localhost
 
267
--replace_column 13 # 14 #
 
268
select * from mysql.proc where db='mysqltest1';
 
269
 
 
270
# ********************** PART 3 : TRIGGERS ***************
 
271
 
 
272
connection con1;
 
273
# now fails due to missing trigger grant (err 1142 i/o 1227) due to new
 
274
# check in sql_trigger.cc (v1.44) by anozdrin on 2006/02/01  --azundris
 
275
--error ER_TABLEACCESS_DENIED_ERROR
 
276
create trigger trg before insert on t1 for each row set new.a= 10;
 
277
 
 
278
connection master;
 
279
delete from t1;
 
280
# TODO: when triggers can contain an update, test that this update
 
281
# does not go into binlog.
 
282
# I'm not setting user vars in the trigger, because replication of user vars
 
283
# would take care of propagating the user var's value to slave, so even if
 
284
# the trigger was not executed on slave it would not be discovered.
 
285
create trigger trg before insert on t1 for each row set new.a= 10;
 
286
insert into t1 values (1);
 
287
select * from t1;
 
288
sync_slave_with_master;
 
289
select * from t1;
 
290
 
 
291
connection master;
 
292
delete from t1;
 
293
drop trigger trg;
 
294
insert into t1 values (1);
 
295
select * from t1;
 
296
--replace_column 2 # 5 #
 
297
--replace_regex /table_id: [0-9]+/table_id: #/
 
298
#show binlog events in 'master-bin.000001' from 106;
 
299
sync_slave_with_master;
 
300
select * from t1;
 
301
 
 
302
 
 
303
#
 
304
# Test for bug #13969 "Routines which are replicated from master can't be
 
305
# executed on slave".
 
306
 
307
connection master;
 
308
create procedure foo()
 
309
  not deterministic
 
310
  reads sql data
 
311
  select * from t1;
 
312
sync_slave_with_master;
 
313
# This should not fail
 
314
call foo();
 
315
connection master;
 
316
drop procedure foo;
 
317
sync_slave_with_master;
 
318
 
 
319
 
 
320
# Clean up
 
321
connection master;
 
322
drop function fn1;
 
323
drop database mysqltest1;
 
324
drop user "zedjzlcsjhd"@127.0.0.1;
 
325
use test;
 
326
sync_slave_with_master;
 
327
use test;
 
328
 
 
329
#
 
330
# Bug#14077 "Failure to replicate a stored function with a cursor":
 
331
# verify that stored routines with cursors work on slave. 
 
332
#
 
333
connection master;
 
334
--disable_warnings
 
335
drop function if exists f1;
 
336
--enable_warnings
 
337
delimiter |;
 
338
create function f1() returns int reads sql data
 
339
begin
 
340
  declare var integer;
 
341
  declare c cursor for select a from v1;
 
342
  open c;
 
343
  fetch c into var;
 
344
  close c;
 
345
  return var;
 
346
end|
 
347
delimiter ;|
 
348
create view v1 as select 1 as a;
 
349
create table t1 (a int);
 
350
insert into t1 (a) values (f1());
 
351
select * from t1;
 
352
drop view v1;
 
353
drop function f1;
 
354
sync_slave_with_master;
 
355
connection slave;
 
356
select * from t1;
 
357
 
 
358
#
 
359
# Bug#16621 "INSERTs in Stored Procedures causes data corruption in the Binary
 
360
# Log for 5.0.18"
 
361
#
 
362
 
 
363
# Prepare environment.
 
364
 
 
365
connection master;
 
366
 
 
367
--disable_warnings
 
368
DROP PROCEDURE IF EXISTS p1;
 
369
DROP TABLE IF EXISTS t1;
 
370
--enable_warnings
 
371
 
 
372
# Test case.
 
373
 
 
374
CREATE TABLE t1(col VARCHAR(10));
 
375
 
 
376
CREATE PROCEDURE p1(arg VARCHAR(10))
 
377
  INSERT INTO t1 VALUES(arg);
 
378
 
 
379
CALL p1('test');
 
380
 
 
381
SELECT * FROM t1;
 
382
 
 
383
sync_slave_with_master;
 
384
SELECT * FROM t1;
 
385
 
 
386
# Cleanup
 
387
connection master;
 
388
DROP PROCEDURE p1;
 
389
 
 
390
 
 
391
#
 
392
# BUG#20438: CREATE statements for views, stored routines and triggers can be
 
393
# not replicable.
 
394
#
 
395
 
 
396
--echo
 
397
--echo ---> Test for BUG#20438
 
398
 
 
399
# Prepare environment.
 
400
 
 
401
--echo
 
402
--echo ---> Preparing environment...
 
403
--echo ---> connection: master
 
404
--connection master
 
405
 
 
406
--disable_warnings
 
407
DROP PROCEDURE IF EXISTS p1;
 
408
DROP FUNCTION IF EXISTS f1;
 
409
--enable_warnings
 
410
 
 
411
--echo
 
412
--echo ---> Synchronizing slave with master...
 
413
 
 
414
--save_master_pos
 
415
--connection slave
 
416
--sync_with_master
 
417
 
 
418
--echo
 
419
--echo ---> connection: master
 
420
--connection master
 
421
 
 
422
# Test.
 
423
 
 
424
--echo
 
425
--echo ---> Creating procedure...
 
426
 
 
427
/*!50003 CREATE PROCEDURE p1() SET @a = 1 */;
 
428
 
 
429
/*!50003 CREATE FUNCTION f1() RETURNS INT RETURN 0 */;
 
430
 
 
431
--echo
 
432
--echo ---> Checking on master...
 
433
 
 
434
SHOW CREATE PROCEDURE p1;
 
435
SHOW CREATE FUNCTION f1;
 
436
 
 
437
--echo
 
438
--echo ---> Synchronizing slave with master...
 
439
 
 
440
--save_master_pos
 
441
--connection slave
 
442
--sync_with_master
 
443
 
 
444
--echo ---> connection: master
 
445
 
 
446
--echo
 
447
--echo ---> Checking on slave...
 
448
 
 
449
SHOW CREATE PROCEDURE p1;
 
450
SHOW CREATE FUNCTION f1;
 
451
 
 
452
# Cleanup.
 
453
 
 
454
--echo
 
455
--echo ---> connection: master
 
456
--connection master
 
457
 
 
458
--echo
 
459
--echo ---> Cleaning up...
 
460
 
 
461
DROP PROCEDURE p1;
 
462
DROP FUNCTION f1;
 
463
 
 
464
--save_master_pos
 
465
--connection slave
 
466
--sync_with_master
 
467
--connection master
 
468
 
 
469
 
 
470
# cleanup
 
471
connection master;
 
472
drop table t1;
 
473
sync_slave_with_master;
 
474
 
 
475
# Restore log_bin_trust_function_creators to original value
 
476
set global log_bin_trust_function_creators=0;
 
477
connection master;
 
478
set global log_bin_trust_function_creators=0;
 
479
--echo End of 5.0 tests
 
480
 
 
481
#
 
482
# Bug22043: MySQL don't add "USE <DATABASE>" before "DROP PROCEDURE IF EXISTS"
 
483
#
 
484
connection master;
 
485
reset master;
 
486
--disable_warnings
 
487
drop database if exists mysqltest;
 
488
drop database if exists mysqltest2;
 
489
--enable_warnings
 
490
create database mysqltest;
 
491
create database mysqltest2;
 
492
use mysqltest2;
 
493
create table t ( t integer );
 
494
create procedure mysqltest.test() begin end;
 
495
insert into t values ( 1 );
 
496
#show binlog events in 'master-bin.000001' from 106;
 
497
--error ER_BAD_DB_ERROR
 
498
create procedure `\\`.test() begin end;
 
499
# Clean up
 
500
drop database mysqltest;
 
501
drop database mysqltest2;
 
502
 
 
503
--echo End of 5.1 tests
 
504