@@ -268,6 +268,132 @@ Warning 1287 'pre-4.1 password hash' is deprecated and will be removed in a futu
268268FLUSH PRIVILEGES;
269269DROP USER old_pwd@localhost, old_gpwd@localhost;
270270SET old_passwords=default;
271+ #
272+ # WL#2392: Change Password at next login
273+ #
274+ CREATE USER must_change@localhost IDENTIFIED BY 'aha';
275+ SELECT password_expired FROM mysql.user
276+ WHERE user='must_change' and host = 'localhost';
277+ password_expired
278+ N
279+ SELECT USER();
280+ USER()
281+ must_change@localhost
282+ CREATE TABLE t1 (A INT);
283+ CREATE PROCEDURE TEST_t1(new_a INT) INSERT INTO t1 VALUES (new_a);
284+ CREATE FUNCTION last_t1() RETURNS INT RETURN (SELECT MAX(A) FROM t1);
285+ # Initialize the table
286+ CALL test_t1(1);
287+ UPDATE mysql.user SET password_expired='Y'
288+ WHERE user='must_change' and host = 'localhost';
289+ # without FLUSH the field has no effect
290+ # must not throw an error
291+ SELECT USER();
292+ USER()
293+ must_change@localhost
294+ # must not throw an error
295+ SELECT last_t1();
296+ last_t1()
297+ 1
298+ # must not throw an error
299+ CALL test_t1(last_t1() + 1);
300+ FLUSH PRIVILEGES;
301+ # existing connections continue as before even after flush
302+ # must not throw an error
303+ SELECT USER();
304+ USER()
305+ must_change@localhost
306+ # must not throw an error
307+ SELECT last_t1();
308+ last_t1()
309+ 2
310+ # must not throw an error
311+ CALL test_t1(last_t1() + 1);
312+ # new connections are blocked until a password reset
313+ SELECT USER();
314+ ERROR HY000: You must SET PASSWORD before executing this statement
315+ SELECT last_t1();
316+ ERROR HY000: You must SET PASSWORD before executing this statement
317+ CALL test_t1(last_t1() + 1);
318+ ERROR HY000: You must SET PASSWORD before executing this statement
319+ # setting a password unlocks it
320+ SET PASSWORD = PASSWORD('aha2');
321+ # must not throw an error
322+ SELECT USER();
323+ USER()
324+ must_change@localhost
325+ # must not throw an error
326+ SELECT last_t1();
327+ last_t1()
328+ 3
329+ # must not throw an error
330+ CALL test_t1(last_t1() + 1);
331+ # check if SET PASSWORD resets the column
332+ SELECT password_expired FROM mysql.user
333+ WHERE user='must_change' and host = 'localhost';
334+ password_expired
335+ N
336+ UPDATE mysql.user SET password_expired='Y'
337+ WHERE user='must_change' and host = 'localhost';
338+ FLUSH PRIVILEGES;
339+ SELECT USER();
340+ ERROR HY000: You must SET PASSWORD before executing this statement
341+ SELECT last_t1();
342+ ERROR HY000: You must SET PASSWORD before executing this statement
343+ CALL test_t1(last_t1() + 1);
344+ ERROR HY000: You must SET PASSWORD before executing this statement
345+ # setting a password with a user name is no good
346+ SET PASSWORD FOR must_change@localhost = PASSWORD('aha3');
347+ ERROR HY000: You must SET PASSWORD before executing this statement
348+ SELECT USER();
349+ ERROR HY000: You must SET PASSWORD before executing this statement
350+ SELECT last_t1();
351+ ERROR HY000: You must SET PASSWORD before executing this statement
352+ CALL test_t1(last_t1() + 1);
353+ ERROR HY000: You must SET PASSWORD before executing this statement
354+ # setting a password for the current user works
355+ SET PASSWORD FOR CURRENT_USER() = PASSWORD('aha3');
356+ SELECT USER();
357+ USER()
358+ must_change@localhost
359+ SELECT last_t1();
360+ last_t1()
361+ 4
362+ CALL test_t1(last_t1() + 1);
363+ # testing the ALTER USER command
364+ # try a single user
365+ ALTER USER must_change@localhost PASSWORD EXPIRE;
366+ SELECT password_expired FROM mysql.user
367+ WHERE user='must_change' and host = 'localhost';
368+ password_expired
369+ Y
370+ SELECT USER();
371+ ERROR HY000: You must SET PASSWORD before executing this statement
372+ SET PASSWORD = PASSWORD('aha4');
373+ # try a valid+invalid user combo
374+ ALTER USER
375+ invalid_user@localhost PASSWORD EXPIRE,
376+ must_change@localhost PASSWORD EXPIRE;
377+ ERROR HY000: Operation ALTER USER failed for 'invalid_user'@'localhost'
378+ SELECT password_expired FROM mysql.user
379+ WHERE user='must_change' and host = 'localhost';
380+ password_expired
381+ Y
382+ SELECT USER();
383+ ERROR HY000: You must SET PASSWORD before executing this statement
384+ SET PASSWORD = PASSWORD('aha5');
385+ SELECT USER();
386+ USER()
387+ must_change@localhost
388+ # Password change must be persistent when reconnecting
389+ SELECT USER();
390+ USER()
391+ must_change@localhost
392+ # cleanup
393+ DROP PROCEDURE test_t1;
394+ DROP FUNCTION last_t1;
395+ DROP TABLE t1;
396+ DROP USER must_change@localhost;
271397# ------------------------------------------------------------------
272398# -- End of 5.6 tests
273399# ------------------------------------------------------------------
0 commit comments