From 36e88d78e6eb471acaf43bd2229891670a0d44a1 Mon Sep 17 00:00:00 2001 From: ULF WENDEL Date: Thu, 10 Jan 2013 14:51:14 +0100 Subject: MySQL 5.6 EXPIRE PASSWORD flag tests --- ext/mysqli/tests/mysqli_constants.phpt | 4 + ext/mysqli/tests/mysqli_expire_password.phpt | 145 +++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 ext/mysqli/tests/mysqli_expire_password.phpt diff --git a/ext/mysqli/tests/mysqli_constants.phpt b/ext/mysqli/tests/mysqli_constants.phpt index 613dddfc85..8bdc849f78 100644 --- a/ext/mysqli/tests/mysqli_constants.phpt +++ b/ext/mysqli/tests/mysqli_constants.phpt @@ -176,6 +176,10 @@ require_once('skipifconnectfailure.inc'); } } + if (($IS_MYSQLND && version_compare(PHP_VERSION, ' 5.4.12-dev', '>=')) || (!$IS_MYSQLND && ($version > 50610))) { + /* could be that MySQL/libmysql 5.6.9 had the flag already but it was no stable release */ + $expected_constants["MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS"] = true; + } $unexpected_constants = array(); diff --git a/ext/mysqli/tests/mysqli_expire_password.phpt b/ext/mysqli/tests/mysqli_expire_password.phpt new file mode 100644 index 0000000000..ce89a21670 --- /dev/null +++ b/ext/mysqli/tests/mysqli_expire_password.phpt @@ -0,0 +1,145 @@ +--TEST-- +MySQL 5.6 EXPIRE PASSWORD protocol change +--SKIPIF-- +=")) { + die("SKIP Available in mysqlnd as of PHP 5.4.12-dev"); +} + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + die(sprintf("SKIP Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket)); +} + +if ($link->server_version < 50610) + die(sprintf("SKIP Needs MySQL 5.6.10 or newer, found MySQL %s\n", $link->server_info)); + +if (!$IS_MYSQLND && (mysqli_get_client_version() < 50610)) { + die(sprintf("SKIP Needs libmysql 5.6.10 or newer, found %s\n", mysqli_get_client_version())); +} + +mysqli_query($link, 'DROP USER expiretest'); +mysqli_query($link, 'DROP USER expiretest@localhost'); + +if (!mysqli_query($link, 'CREATE USER expiretest@"%"') || + !mysqli_query($link, 'CREATE USER expiretest@"localhost"')) { + printf("skip Cannot create second DB user [%d] %s", mysqli_errno($link), mysqli_error($link)); + mysqli_close($link); + die("skip CREATE USER failed"); +} + +if (!mysqli_query($link, 'ALTER USER expiretest@"%" PASSWORD EXPIRE') || + !mysqli_query($link, 'ALTER USER expiretest@"localhost" PASSWORD EXPIRE')) { + printf("skip Cannot modify second DB user [%d] %s", mysqli_errno($link), mysqli_error($link)); + mysqli_close($link); + die("skip ALTER USER failed"); +} + +if (!$link->query("DROP TABLE IF EXISTS test") || + !$link->query("CREATE TABLE test (id INT)") || !$link->query("INSERT INTO test(id) VALUES (1)")) + die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error)); + + + +if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'%%'", $db)) || + !mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'localhost'", $db))) { + printf("skip Cannot grant SELECT to user [%d] %s", mysqli_errno($link), mysqli_error($link)); + mysqli_close($link); + die("skip GRANT failed"); +} +?> +--FILE-- +query("SELECT id FROM test WHERE id = 1"); + printf("[002] Connect should fail, [%d] %s\n", $link->errno, $link->error); + } + + /* explicitly requesting default */ + $link = mysqli_init(); + $link->options(MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 0); + if (!my_mysqli_real_connect($link, $host, 'expiretest', "", $db, $port, $socket)) { + printf("[003] Cannot connect [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + } else { + $link->query("SELECT id FROM test WHERE id = 1"); + printf("[004] Connect should fail, [%d] %s\n", $link->errno, $link->error); + } + + /* allow connect */ + $link = mysqli_init(); + $link->options(MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 1); + if (!my_mysqli_real_connect($link, $host, 'expiretest', "", $db, $port, $socket)) { + printf("[005] Cannot connect [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + } else { + $link->query("SELECT id FROM test WHERE id = 1"); + printf("[006] Connect allowed, query fail, [%d] %s\n", $link->errno, $link->error); + $link->close(); + } + + /* allow connect, fix pw */ + $link = mysqli_init(); + $link->options(MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 1); + if (!my_mysqli_real_connect($link, $host, 'expiretest', "", $db, $port, $socket)) { + printf("[007] Cannot connect [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + } else { + $link->query("SET PASSWORD=PASSWORD('expiretest')"); + printf("[008] Connect allowed, pw set, [%d] %s\n", $link->errno, $link->error); + if ($res = $link->query("SELECT id FROM test WHERE id = 1")) + var_dump($res->fetch_assoc()); + $link->close(); + } + + + /* check login */ + if (!$link = my_mysqli_connect($host, 'expiretest', "expiretest", $db, $port, $socket)) { + printf("[001] Cannot connect [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + } else { + $link->query("SELECT id FROM test WHERE id = 1"); + if ($res = $link->query("SELECT id FROM test WHERE id = 1")) + var_dump($res->fetch_assoc()); + $link->close(); + } + + + + print "done!"; +?> +--CLEAN-- + +--EXPECTF-- + +Warning: mysqli_real_connect(): (HY000/1820): %s in %s on line %d +[001] Cannot connect [1820] %s + +Warning: mysqli_real_connect(): (HY000/1820): %s in %s on line %d +[003] Cannot connect [1820] %s +[006] Connect allowed, query fail, [1820] %s +[008] Connect allowed, pw set, [0%A +array(1) { + ["id"]=> + string(1) "1" +} +array(1) { + ["id"]=> + string(1) "1" +} +done! -- cgit v1.2.1