source include/not_embedded.inc;
source include/master-slave.inc;
source include/rpl_reset.inc;

# Suppress warnings that might be generated during the test
disable_query_log;
connection master;
call mtr.add_suppression("Timeout waiting for reply of binlog");
connection slave;
call mtr.add_suppression("Slave SQL.*Request to stop slave SQL Thread received while applying a group that has non-transactional changes; waiting for completion of the group");
enable_query_log;

connection master;
echo [ on master ];

# wait for dying connections (if any) to disappear
let $wait_condition= select count(*) = 0 from information_schema.processlist where command='killed';
--source include/wait_condition.inc

# 32*3-character ASCII password should work all right

set sql_log_bin=0;
grant replication slave on *.* to rpl32@127.0.0.1 identified by '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
set sql_log_bin=1;

connection slave;
echo [ on slave ];
source include/stop_slave.inc;
change master to master_user='rpl32',master_password='0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
source include/start_slave.inc;

connection master;
echo [ on master ];
drop table if exists t1;
create table t1 (i int);
insert into t1 values (1);
sync_slave_with_master;
echo [ on slave: synchronized ];

connection master;
echo [ on master ];

# 32*3+1 -character ASCII password expected to fail
set sql_log_bin=0;
grant replication slave on *.* to rpl33@127.0.0.1 identified by '0123456789abcdef0123456789abcdef!';
set sql_log_bin=1;

connection slave;
echo [ on slave ];
source include/stop_slave.inc;
--error ER_WRONG_STRING_LENGTH
change master to master_user='rpl33',master_password='0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef!';

# Check also master_user and master_host
--error ER_WRONG_STRING_LENGTH
change master to master_user='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
--error ER_WRONG_STRING_LENGTH
change master to master_host='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc';

# 48-character cyrillic password should work all right
connection master;
echo [ on master ];
set sql_log_bin=0;
grant replication slave on *.* to rpl16cyr@127.0.0.1 identified by 'воттакойужпарольвоттакойужпарольвоттакойужпароль';
set sql_log_bin=1;

connection slave;
echo [ on slave ];
SET NAMES utf8;
change master to master_user='rpl16cyr',master_password='воттакойужпарольвоттакойужпарольвоттакойужпароль';
source include/start_slave.inc;

connection master;
echo [ on master ];
drop table if exists t1;
create table t1 (i int);
insert into t1 values (1);
sync_slave_with_master;
echo [ on slave: synchronized ];

# 48+1-character cyrillic password should fail

connection master;
echo [ on master ];
set sql_log_bin=0;
grant replication slave on *.* to rpl17mix@127.0.0.1 identified by 'воттакойужпарольвоттакойужпарольвоттакойужпароль!';
set sql_log_bin=1;

connection slave;
echo [ on slave ];
source include/stop_slave.inc;
--error ER_WRONG_STRING_LENGTH
change master to master_user='rpl17mix',master_password='воттакойужпарольвоттакойужпарольвоттакойужпароль!';

# Cleanup

connection master;
echo [ on master ];
set sql_log_bin=0;
drop user rpl32@127.0.0.1, rpl33@127.0.0.1, rpl16cyr@127.0.0.1, rpl17mix@127.0.0.1;
set sql_log_bin=1;

connection slave;
change master to master_user='root',master_password='';
source include/start_slave.inc;

connection master;
drop table if exists t1;
sync_slave_with_master;

connection master;
--source include/rpl_end.inc
