rpl_do_grant.test 10.1 KB
Newer Older
1 2
# Works in statement-based and row-based binlogging.
# Test that GRANT and other user management commands are replicated to the slave
3

4
-- source include/master-slave.inc
5 6 7

# do not be influenced by other tests.
connection master;
8 9
delete from mysql.user where user=_binary'rpl_do_grant';
delete from mysql.db where user=_binary'rpl_do_grant';
10 11 12 13 14 15
flush privileges;
save_master_pos;
connection slave;
sync_with_master;
# if these DELETE did nothing on the master, we need to do them manually on the
# slave.
16 17
delete from mysql.user where user=_binary'rpl_ignore_grant';
delete from mysql.db where user=_binary'rpl_ignore_grant';
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
flush privileges;

# test replication of GRANT
connection master;
grant select on *.* to rpl_do_grant@localhost;
grant drop on test.* to rpl_do_grant@localhost;
save_master_pos;
connection slave;
sync_with_master;
show grants for rpl_do_grant@localhost;

# test replication of SET PASSWORD
connection master;
set password for rpl_do_grant@localhost=password("does it work?");
save_master_pos;
connection slave;
sync_with_master;
35
select password<>_binary'' from mysql.user where user=_binary'rpl_do_grant';
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#
# Bug#24158 SET PASSWORD in binary log fails under ANSI_QUOTES
#
connection master;
update mysql.user set password='' where user='rpl_do_grant';
flush privileges;
select password<>'' from mysql.user where user='rpl_do_grant';
set sql_mode='ANSI_QUOTES';
set password for rpl_do_grant@localhost=password('does it work?');
set sql_mode='';
save_master_pos;
connection slave;
sync_with_master;
select password<>'' from mysql.user where user='rpl_do_grant';


53 54
# clear what we have done, to not influence other tests.
connection master;
55 56
delete from mysql.user where user=_binary'rpl_do_grant';
delete from mysql.db where user=_binary'rpl_do_grant';
57
flush privileges;
58 59 60 61 62
sync_slave_with_master;
# The mysql database is not replicated, so we have to do the deletes
# manually on the slave as well. 
delete from mysql.user where user=_binary'rpl_do_grant';
delete from mysql.db where user=_binary'rpl_do_grant';
63
flush privileges;
64 65

# End of 4.1 tests
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

connection master;
--error 1141
show grants for rpl_do_grant@localhost;
connection slave;
--error 1141
show grants for rpl_do_grant@localhost;

connection master;
create user rpl_do_grant@localhost;
show grants for rpl_do_grant@localhost;
--error 1141
show grants for rpl_do_grant2@localhost;
sync_slave_with_master;
show grants for rpl_do_grant@localhost;
--error 1141
show grants for rpl_do_grant2@localhost;

connection master;
rename user rpl_do_grant@localhost to rpl_do_grant2@localhost;
show grants for rpl_do_grant2@localhost;
sync_slave_with_master;
show grants for rpl_do_grant2@localhost;

connection master;
grant DELETE,INSERT on mysqltest1.* to rpl_do_grant2@localhost;
show grants for rpl_do_grant2@localhost;
sync_slave_with_master;
show grants for rpl_do_grant2@localhost;

connection master;
revoke DELETE on mysqltest1.* from rpl_do_grant2@localhost;
show grants for rpl_do_grant2@localhost;
sync_slave_with_master;
show grants for rpl_do_grant2@localhost;

connection master;
revoke all privileges, grant option from rpl_do_grant2@localhost;
show grants for rpl_do_grant2@localhost;
sync_slave_with_master;
show grants for rpl_do_grant2@localhost;

connection master;
drop user rpl_do_grant2@localhost;
--error 1141
show grants for rpl_do_grant2@localhost;
sync_slave_with_master;
--error 1141
show grants for rpl_do_grant2@localhost;
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

#####################################################
# Purpose
# Test whether mysql.procs_priv get replicated 
# Related bugs:
# BUG42217  mysql.procs_priv does not get replicated
#####################################################
connection master; 

--disable_warnings
DROP DATABASE IF EXISTS bug42217_db;
--enable_warnings
CREATE DATABASE  bug42217_db;

GRANT CREATE ROUTINE ON bug42217_db.* TO 'create_rout_db'@'localhost'
        IDENTIFIED BY 'create_rout_db' WITH GRANT OPTION;

132 133 134
-- sync_slave_with_master
-- connection master

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
connect (create_rout_db_master, localhost, create_rout_db, create_rout_db, bug42217_db,$MASTER_MYPORT,);
connect (create_rout_db_slave, localhost, create_rout_db, create_rout_db, bug42217_db, $SLAVE_MYPORT,);

connection create_rout_db_master;


USE bug42217_db;

DELIMITER //;
CREATE FUNCTION upgrade_del_func() RETURNS CHAR(30)
BEGIN
   RETURN "INSIDE upgrade_del_func()";
END//

DELIMITER ;//

connection master;

USE bug42217_db;
--replace_column 8 #
SELECT * FROM mysql.procs_priv;
SELECT upgrade_del_func();

sync_slave_with_master;
--replace_column 8 #
SELECT * FROM mysql.procs_priv;
SHOW GRANTS FOR 'create_rout_db'@'localhost';

USE bug42217_db;
SHOW CREATE FUNCTION upgrade_del_func;
SELECT upgrade_del_func();

--echo "Check whether the definer user will be able to execute the replicated routine on slave"
connection create_rout_db_slave;
USE bug42217_db;
SHOW CREATE FUNCTION upgrade_del_func;
SELECT upgrade_del_func();

connection slave;
DELETE FROM mysql.procs_priv;
FLUSH PRIVILEGES;
USE bug42217_db;
--echo "Can't execute the replicated routine on slave like before after procs privilege is deleted "
--error 1370
SELECT upgrade_del_func();

--echo "Test the user who creates a function on master doesn't exist on slave."
--echo "Hence SQL thread ACL_GLOBAL privilege jumps in and no mysql.procs_priv is inserted"
DROP USER 'create_rout_db'@'localhost';

connection create_rout_db_master;
DELIMITER //;
CREATE FUNCTION upgrade_alter_func() RETURNS CHAR(30)
BEGIN
   RETURN "INSIDE upgrade_alter_func()";
END//
DELIMITER ;//

connection master;
SELECT upgrade_alter_func();

sync_slave_with_master;
SHOW CREATE FUNCTION upgrade_alter_func;
--echo "Should no privilege record for upgrade_alter_func in mysql.procs_priv"
--replace_column 8 #
SELECT * FROM mysql.procs_priv;
--error 1449
SELECT upgrade_alter_func();

###### CLEAN UP SECTION ##############
disconnect create_rout_db_master;
disconnect create_rout_db_slave;
connection master;
USE bug42217_db;
DROP FUNCTION upgrade_del_func;
DROP FUNCTION upgrade_alter_func;
DROP DATABASE bug42217_db;
DROP USER 'create_rout_db'@'localhost';
Bjorn Munch's avatar
Bjorn Munch committed
213 214 215 216 217 218

call mtr.add_suppression("Slave: Operation DROP USER failed for 'create_rout_db'@'localhost' Error_code: 1396");
connection slave;
USE mtr;
call mtr.add_suppression("Slave: Operation DROP USER failed for 'create_rout_db'@'localhost' Error_code: 1396");

219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
# BUG#49119: Master crashes when executing 'REVOKE ... ON
# {PROCEDURE|FUNCTION} FROM ...'
# 
# The tests are divided into two test cases:
#
#  i) a test case that mimics the one in the bug report.
#
#     - We show that, despite the fact, that a revoke command fails
#       when binlogging is active, the master will not hit an
#       assertion.
#
# ii) a test case that partially succeeds on the master will also
#      partially succeed on the slave.
#
#     - The revoke statement that partially succeeds tries to revoke
#       an EXECUTE grant for two users, and only one of the user has
#       the specific grant. This will cause mysql to drop one of the
#       grants and report error for the statement. The slave should
#       also drop the grants that the master succeed and the SQL
#       thread should not stop on statement failure.

-- echo ######## BUG#49119 #######
-- echo ### i) test case from the 'how to repeat section'
-- source include/master-slave-reset.inc
-- connection master

CREATE TABLE t1(c1 INT);
DELIMITER |;
CREATE PROCEDURE p1() SELECT * FROM t1 |
DELIMITER ;|
-- error ER_NONEXISTING_PROC_GRANT
REVOKE EXECUTE ON PROCEDURE p1 FROM 'root'@'localhost';

-- sync_slave_with_master

-- connection master
DROP TABLE t1;
DROP PROCEDURE p1;

-- sync_slave_with_master

-- echo ### ii) Test case in which REVOKE partially succeeds

-- connection master
-- source include/master-slave-reset.inc
-- connection master

CREATE TABLE t1(c1 INT);
DELIMITER |;
CREATE PROCEDURE p1() SELECT * FROM t1 |
DELIMITER ;|

CREATE USER 'user49119'@'localhost';
GRANT EXECUTE ON PROCEDURE p1 TO 'user49119'@'localhost';

-- echo ##############################################################
-- echo ### Showing grants for both users: root and user49119 (master)
SHOW GRANTS FOR 'user49119'@'localhost';
SHOW GRANTS FOR CURRENT_USER;
-- echo ##############################################################

-- sync_slave_with_master

-- echo ##############################################################
-- echo ### Showing grants for both users: root and user49119 (master)
SHOW GRANTS FOR 'user49119'@'localhost';
SHOW GRANTS FOR CURRENT_USER;
-- echo ##############################################################

-- connection master

-- echo ## This statement will make the revoke fail because root has no
-- echo ## execute grant. However, it will still revoke the grant for
-- echo ## user49119.
-- error ER_NONEXISTING_PROC_GRANT
REVOKE EXECUTE ON PROCEDURE p1 FROM 'user49119'@'localhost', 'root'@'localhost';

-- echo ##############################################################
-- echo ### Showing grants for both users: root and user49119 (master)
-- echo ### after revoke statement failure
SHOW GRANTS FOR 'user49119'@'localhost';
SHOW GRANTS FOR CURRENT_USER;
-- echo ##############################################################

-- sync_slave_with_master

-- echo #############################################################
-- echo ### Showing grants for both users: root and user49119 (slave)
-- echo ### after revoke statement failure (should match 
SHOW GRANTS FOR 'user49119'@'localhost';
SHOW GRANTS FOR CURRENT_USER;
-- echo ##############################################################

-- connection master
DROP TABLE t1;
DROP PROCEDURE p1;
DROP USER 'user49119'@'localhost';

-- sync_slave_with_master

319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
#
# Bug #51987  	revoke privileges logs wrong error code
#

-- connection master
-- source include/master-slave-reset.inc
-- connection master

grant all on *.* to foo@"1.2.3.4";
-- error ER_REVOKE_GRANTS
revoke all privileges, grant option from "foo";

## assertion: revoke is logged
-- source include/show_binlog_events.inc

-- sync_slave_with_master

## assertion: slave replicates revoke and does not fail because master
##            logged revoke with correct expected error code
-- let $err= query_get_value(SHOW SLAVE STATUS, Last_SQL_Errno, 1)
  if ($err)
{
    -- die UNEXPECTED ERROR AT SLAVE: $err
}

-- connection master
DROP USER foo@"1.2.3.4";
-- sync_slave_with_master

348
--echo "End of test"