# ==== Purpose ==== # # This test checks we can set GTID_PURGED from inside a SP even when # is executed by a user with only privileges for execution. # # ==== Implementation ==== # # 0. This test starts with 2 servers in a source->replica setup # 1. We create a table on server 1 for check purposes and extract its id # 2. On the replica create a storage procedure that uses the `root` user # security context to SET GTID_PURGED # 3. Create a user with only EXECUTE privileges. # Make a connection with this user # 4. Use the procedure to set GTID_PURGED. # Check the value was set # 5. Check replication is working as expected # 6. Cleanup # # ==== References ==== # # Bug#31571427 SET GTID_PURGED SHOULD BE EXECUTABLE FROM STORED ROUTINES # --source include/have_binlog_format_row.inc --let $rpl_gtid_utils= 1 --source include/master-slave.inc --echo # --echo # 1. We create a table on server 1 for check purposes and extract its id --source include/rpl_connection_master.inc --let $source_uuid= `SELECT @@GLOBAL.SERVER_UUID` CREATE TABLE t1 (a INT PRIMARY KEY); --source include/sync_slave_sql_with_master.inc --echo # --echo # 2. On the replica create a storage procedure that uses the `root` user --echo # security context to SET GTID_PURGED DROP PROCEDURE IF EXISTS set_gtid_purged_sp; DELIMITER |; CREATE DEFINER = 'root'@'localhost' PROCEDURE set_gtid_purged_sp (IN gtid TEXT) SQL SECURITY DEFINER DETERMINISTIC BEGIN SET GLOBAL gtid_purged = gtid; END| DELIMITER ;| --echo # --echo # 3. Create a user with only EXECUTE privileges. --echo # Make a connection with this user CREATE USER 'no_priv_user'@localhost IDENTIFIED BY ''; GRANT EXECUTE ON test.* TO 'no_priv_user'@localhost; --connect (no_priv_user_con, 127.0.0.1, no_priv_user, , test, $SLAVE_MYPORT,) --let $rpl_connection_name= no_priv_user_con --source include/rpl_connection.inc --echo # --echo # 4. Use the procedure to set GTID_PURGED. --echo # Check the value was set --replace_result $source_uuid SOURCE_UUID --eval CALL set_gtid_purged_sp("$source_uuid:2"); --let $assert_cond= GTID_IS_EQUAL(@@GLOBAL.GTID_PURGED, "$source_uuid:2") --let $assert_text= @@GLOBAL.GTID_PURGED has changed --source include/assert.inc --echo # --echo # 5. Check replication is working as expected --source include/rpl_connection_master.inc INSERT INTO t1 values (2); INSERT INTO t1 values (3); --source include/sync_slave_sql_with_master.inc --let $assert_text= Only one transaction was replicated --let $assert_cond = COUNT(*)=1 FROM t1 --source include/assert.inc --echo # --echo # 6. Cleanup --source include/rpl_connection_master.inc DROP TABLE t1; --source include/rpl_connection_slave.inc REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'no_priv_user'@localhost; DROP USER 'no_priv_user'@localhost; DROP PROCEDURE set_gtid_purged_sp; --source include/rpl_end.inc