php-src/ext/mysqli/tests/mysqli_expire_password.phpt
Peter Kokot d679f02295 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:33:09 +02:00

141 lines
4.6 KiB
PHP

--TEST--
MySQL 5.6 EXPIRE PASSWORD protocol change
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('connect.inc');
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--
<?php
require_once('connect.inc');
require_once('table.inc');
/* default */
if (!$link = my_mysqli_connect($host, '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");
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--
<?php
require_once("clean_table.inc");
mysqli_query($link, 'DROP USER expiretest');
mysqli_query($link, 'DROP USER expiretest@localhost');
?>
--EXPECTF--
Warning: mysqli%sconnect(): (HY000/1862): %s in %s on line %d
[001] Cannot connect [1862] %s
Warning: mysqli%sconnect(): (HY000/1862): %s in %s on line %d
[003] Cannot connect [1862] %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!