Skip to content

Commit 4023f24

Browse files
committed
ext/mysqli: Skip test that needs superuser
This test needs CREATE DATABASE and CREATE SERVER, and will fail in the cleanup step if it doesn't have it. If the test is running as a user that can't do these, then we should skip instead of borking. Alternative to phpGH-17466.
1 parent ce53dab commit 4023f24

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

ext/mysqli/tests/mysqli_get_client_stats.phpt

+27-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,33 @@ mysqli_get_client_stats()
44
mysqli
55
--SKIPIF--
66
<?PHP
7-
require_once 'skipifconnectfailure.inc';
7+
require_once __DIR__ . '/test_setup/test_helpers.inc';
8+
$link = mysqli_connect_or_skip();
9+
// We run some operations that need CREATE SERVER and CREATE DATABASE in
10+
// this test, so check if we can do that. We don't check if we can merely
11+
// create a table; if that doesn't work with the provided database, many
12+
// more tests would fail.
13+
14+
// It seems DML can be privilege checked on prepare, but DML can't be, so
15+
// we need to execute and clean up.
16+
try {
17+
$sql = "CREATE DATABASE mysqli_get_client_stats";
18+
$stmt = mysqli_query($link, $sql);
19+
$stmt->close();
20+
mysqli_query($link, "DROP DATABASE mysqli_get_client_stats");
21+
} catch (\mysqli_sql_exception) {
22+
die("skip don't have create database privilege");
23+
}
24+
try {
25+
$sql = sprintf("CREATE SERVER myself FOREIGN DATA WRAPPER mysql OPTIONS (user '%s', password '%s', database '%s')",
26+
get_default_user(), get_default_password(), get_default_database());
27+
$stmt = mysqli_query($link, $sql);
28+
$stmt->close();
29+
mysqli_query($link, "DROP SERVER myself");
30+
} catch(\mysqli_sql_exception) {
31+
die("skip don't have create server privilege");
32+
}
33+
mysqli_close($link);
834
?>
935
--INI--
1036
mysqlnd.collect_statistics=1

0 commit comments

Comments
 (0)