Skip to content

Commit 0697a64

Browse files
grooverdannikic
authored andcommitted
Fix mysqli_expire_password test for mariadb
In MariaDB-10.4.3 EXPIRE passwords where supported for MariaDB. This only behaves like MySQL when the system variable disconnect_on_expired_passwords=1. MariaDB if there was no password it could not be considered expired. So the test is adjusted to use actual passwords. (MariaDB commit a94b20a8e0d9e64eeaabdaaa7a3e03fcdb8a686e) The error codes produced my MariaDB are different however still conforming to the SQL specification. Closes GH-6480.
1 parent d6fcaf5 commit 0697a64

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

ext/mysqli/tests/mysqli_expire_password.phpt

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
MySQL 5.6 EXPIRE PASSWORD protocol change
2+
MySQL 5.6 / MariaDB 10.4.3 EXPIRE PASSWORD protocol change
33
--SKIPIF--
44
<?php
55
require_once('skipif.inc');
@@ -14,22 +14,34 @@ if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
1414
if ($link->server_version < 50610)
1515
die(sprintf("SKIP Needs MySQL 5.6.10 or newer, found MySQL %s\n", $link->server_info));
1616

17+
if ($link->server_version >= 100000) {
18+
if ($link->server_version < 100403)
19+
die(sprintf("SKIP Needs MariaDB 10.4.3 or newer, found MariaDB %s\n", $link->server_info));
20+
$result = $link->query("select @@disconnect_on_expired_password");
21+
if (!$result)
22+
die("SKIP Failed to query MariaDB @@disconnect_on_expired_password value");
23+
$row = mysqli_fetch_row($result);
24+
if ($row[0] == 0)
25+
die("SKIP Cannot run in MariaDB @@disconnect_on_expired_password=OFF state");
26+
27+
}
28+
1729
if (!$IS_MYSQLND && (mysqli_get_client_version() < 50610)) {
1830
die(sprintf("SKIP Needs libmysql 5.6.10 or newer, found %s\n", mysqli_get_client_version()));
1931
}
2032

2133
mysqli_query($link, 'DROP USER expiretest');
2234
mysqli_query($link, 'DROP USER expiretest@localhost');
2335

24-
if (!mysqli_query($link, 'CREATE USER expiretest@"%"') ||
25-
!mysqli_query($link, 'CREATE USER expiretest@"localhost"')) {
36+
if (!mysqli_query($link, 'CREATE USER expiretest IDENTIFIED BY \'expiredpassword\'') ||
37+
!mysqli_query($link, 'CREATE USER expiretest@localhost IDENTIFIED BY \'expiredpassword\'')) {
2638
printf("skip Cannot create second DB user [%d] %s", mysqli_errno($link), mysqli_error($link));
2739
mysqli_close($link);
2840
die("skip CREATE USER failed");
2941
}
3042

31-
if (!mysqli_query($link, 'ALTER USER expiretest@"%" PASSWORD EXPIRE') ||
32-
!mysqli_query($link, 'ALTER USER expiretest@"localhost" PASSWORD EXPIRE')) {
43+
if (!mysqli_query($link, 'ALTER USER expiretest PASSWORD EXPIRE') ||
44+
!mysqli_query($link, 'ALTER USER expiretest@localhost PASSWORD EXPIRE')) {
3345
printf("skip Cannot modify second DB user [%d] %s", mysqli_errno($link), mysqli_error($link));
3446
mysqli_close($link);
3547
die("skip ALTER USER failed");
@@ -54,7 +66,7 @@ if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'%
5466
require_once('table.inc');
5567

5668
/* default */
57-
if (!$link = my_mysqli_connect($host, 'expiretest', "", $db, $port, $socket)) {
69+
if (!$link = my_mysqli_connect($host, 'expiretest', 'expiredpassword', $db, $port, $socket)) {
5870
printf("[001] Cannot connect [%d] %s\n",
5971
mysqli_connect_errno(), mysqli_connect_error());
6072
} else {
@@ -65,7 +77,7 @@ if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'%
6577
/* explicitly requesting default */
6678
$link = mysqli_init();
6779
$link->options(MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 0);
68-
if (!my_mysqli_real_connect($link, $host, 'expiretest', "", $db, $port, $socket)) {
80+
if (!my_mysqli_real_connect($link, $host, 'expiretest', 'expiredpassword', $db, $port, $socket)) {
6981
printf("[003] Cannot connect [%d] %s\n",
7082
mysqli_connect_errno(), mysqli_connect_error());
7183
} else {
@@ -76,7 +88,7 @@ if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'%
7688
/* allow connect */
7789
$link = mysqli_init();
7890
$link->options(MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 1);
79-
if (!my_mysqli_real_connect($link, $host, 'expiretest', "", $db, $port, $socket)) {
91+
if (!my_mysqli_real_connect($link, $host, 'expiretest', 'expiredpassword', $db, $port, $socket)) {
8092
printf("[005] Cannot connect [%d] %s\n",
8193
mysqli_connect_errno(), mysqli_connect_error());
8294
} else {
@@ -88,7 +100,7 @@ if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'%
88100
/* allow connect, fix pw */
89101
$link = mysqli_init();
90102
$link->options(MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 1);
91-
if (!my_mysqli_real_connect($link, $host, 'expiretest', "", $db, $port, $socket)) {
103+
if (!my_mysqli_real_connect($link, $host, 'expiretest', 'expiredpassword', $db, $port, $socket)) {
92104
printf("[007] Cannot connect [%d] %s\n",
93105
mysqli_connect_errno(), mysqli_connect_error());
94106
} else {
@@ -122,11 +134,11 @@ if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'%
122134
mysqli_query($link, 'DROP USER expiretest@localhost');
123135
?>
124136
--EXPECTF--
125-
Warning: mysqli%sconnect(): (HY000/1862): %s in %s on line %d
126-
[001] Cannot connect [1862] %s
137+
Warning: mysqli%sconnect(): (HY000/%d): %s in %s on line %d
138+
[001] Cannot connect [%d] %s
127139

128-
Warning: mysqli%sconnect(): (HY000/1862): %s in %s on line %d
129-
[003] Cannot connect [1862] %s
140+
Warning: mysqli%sconnect(): (HY000/%d): %s in %s on line %d
141+
[003] Cannot connect [%d] %s
130142
[006] Connect allowed, query fail, [1820] %s
131143
[008] Connect allowed, pw set, [0%A
132144
array(1) {

0 commit comments

Comments
 (0)