diff options
Diffstat (limited to 'ext/mysqli/tests')
-rw-r--r-- | ext/mysqli/tests/bug77956.phpt | 5 | ||||
-rw-r--r-- | ext/mysqli/tests/foo/bar/bar.data | 3 | ||||
-rw-r--r-- | ext/mysqli/tests/foo/foo.data | 3 | ||||
-rw-r--r-- | ext/mysqli/tests/local_infile_tools.inc | 12 | ||||
-rw-r--r-- | ext/mysqli/tests/mysqli_allow_local_infile_overrides_local_infile_directory.phpt | 75 | ||||
-rw-r--r-- | ext/mysqli/tests/mysqli_constants.phpt | 4 | ||||
-rw-r--r-- | ext/mysqli/tests/mysqli_local_infile_default_off.phpt | 4 | ||||
-rw-r--r-- | ext/mysqli/tests/mysqli_local_infile_directory_access_allowed.phpt | 80 | ||||
-rw-r--r-- | ext/mysqli/tests/mysqli_local_infile_directory_access_denied.phpt | 65 | ||||
-rw-r--r-- | ext/mysqli/tests/mysqli_local_infile_directory_vs_open_basedir.phpt | 65 | ||||
-rw-r--r-- | ext/mysqli/tests/mysqli_phpinfo.phpt | 2 |
11 files changed, 310 insertions, 8 deletions
diff --git a/ext/mysqli/tests/bug77956.phpt b/ext/mysqli/tests/bug77956.phpt index c76e1021e1..19df063951 100644 --- a/ext/mysqli/tests/bug77956.phpt +++ b/ext/mysqli/tests/bug77956.phpt @@ -55,6 +55,5 @@ $link->close(); unlink('bug77956.data'); ?> --EXPECTF-- -Warning: mysqli::query(): LOAD DATA LOCAL INFILE forbidden in %s on line %d -[006] [2000] LOAD DATA LOCAL INFILE is forbidden, check mysqli.allow_local_infile -done +[006] [2000] LOAD DATA LOCAL INFILE is forbidden, check related settings like mysqli.allow_local_infile|mysqli.local_infile_directory or PDO::MYSQL_ATTR_LOCAL_INFILE|PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY +done
\ No newline at end of file diff --git a/ext/mysqli/tests/foo/bar/bar.data b/ext/mysqli/tests/foo/bar/bar.data new file mode 100644 index 0000000000..56e5e8cdce --- /dev/null +++ b/ext/mysqli/tests/foo/bar/bar.data @@ -0,0 +1,3 @@ +97 +98 +99 diff --git a/ext/mysqli/tests/foo/foo.data b/ext/mysqli/tests/foo/foo.data new file mode 100644 index 0000000000..01e79c32a8 --- /dev/null +++ b/ext/mysqli/tests/foo/foo.data @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/ext/mysqli/tests/local_infile_tools.inc b/ext/mysqli/tests/local_infile_tools.inc index fef400d0a9..d45d15e6ac 100644 --- a/ext/mysqli/tests/local_infile_tools.inc +++ b/ext/mysqli/tests/local_infile_tools.inc @@ -6,8 +6,7 @@ } } - function check_local_infile_support($link, $engine, $table_name = 'test') { - + function check_local_infile_allowed_by_server($link) { if (!$res = mysqli_query($link, 'SHOW VARIABLES LIKE "local_infile"')) return "Cannot check if Server variable 'local_infile' is set to 'ON'"; @@ -16,6 +15,15 @@ if ('ON' != $row['Value']) return sprintf("Server variable 'local_infile' seems not set to 'ON', found '%s'", $row['Value']); + return ""; + } + + function check_local_infile_support($link, $engine, $table_name = 'test') { + $res = check_local_infile_allowed_by_server($link); + if ($res) { + return $res; + } + if (!mysqli_query($link, sprintf('DROP TABLE IF EXISTS %s', $table_name))) { return "Failed to drop old test table"; } diff --git a/ext/mysqli/tests/mysqli_allow_local_infile_overrides_local_infile_directory.phpt b/ext/mysqli/tests/mysqli_allow_local_infile_overrides_local_infile_directory.phpt new file mode 100644 index 0000000000..187701ff8c --- /dev/null +++ b/ext/mysqli/tests/mysqli_allow_local_infile_overrides_local_infile_directory.phpt @@ -0,0 +1,75 @@ +--TEST-- +mysqli.allow_local_infile overrides mysqli.local_infile_directory +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die("skip Cannot connect to MySQL"); + +include_once("local_infile_tools.inc"); +if ($msg = check_local_infile_allowed_by_server($link)) + die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); + +mysqli_close($link); + +?> +--INI-- +open_basedir={PWD} +mysqli.allow_local_infile=1 +mysqli.local_infile_directory={PWD}/foo/bar +--FILE-- +<?php + require_once("connect.inc"); + + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + } + + if (!$link->query("DROP TABLE IF EXISTS test")) { + printf("[002] [%d] %s\n", $link->errno, $link->error); + } + + if (!$link->query("CREATE TABLE test (id INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine)) { + printf("[003] [%d] %s\n", $link->errno, $link->error); + } + + $filepath = str_replace('\\', '/', __DIR__.'/foo/foo.data'); + if (!$link->query("LOAD DATA LOCAL INFILE '".$filepath."' INTO TABLE test")) { + printf("[004] [%d] %s\n", $link->errno, $link->error); + } + + if ($res = mysqli_query($link, 'SELECT COUNT(id) AS num FROM test')) { + $row = mysqli_fetch_assoc($res); + mysqli_free_result($res); + + $row_count = $row['num']; + $expected_row_count = 3; + if ($row_count != $expected_row_count) { + printf("[005] %d != %d\n", $row_count, $expected_row_count); + } + } else { + printf("[006] [%d] %s\n", $link->errno, $link->error); + } + + $link->close(); + echo "done"; +?> +--CLEAN-- +<?php +require_once('connect.inc'); + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[clean] 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->query($link, 'DROP TABLE IF EXISTS test')) { + printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); +} + +$link->close(); +?> +--EXPECT-- +done diff --git a/ext/mysqli/tests/mysqli_constants.phpt b/ext/mysqli/tests/mysqli_constants.phpt index 6297d56b34..8538fafa4f 100644 --- a/ext/mysqli/tests/mysqli_constants.phpt +++ b/ext/mysqli/tests/mysqli_constants.phpt @@ -202,6 +202,10 @@ mysqli.allow_local_infile=1 $expected_constants["MYSQLI_TYPE_JSON"] = true; } + if ($version > 80210 || $IS_MYSQLND) { + $expected_constants['MYSQLI_OPT_LOAD_DATA_LOCAL_DIR'] = true; + } + $unexpected_constants = array(); foreach ($constants as $group => $consts) { diff --git a/ext/mysqli/tests/mysqli_local_infile_default_off.phpt b/ext/mysqli/tests/mysqli_local_infile_default_off.phpt index c2e8aa2dc8..65f4012925 100644 --- a/ext/mysqli/tests/mysqli_local_infile_default_off.phpt +++ b/ext/mysqli/tests/mysqli_local_infile_default_off.phpt @@ -16,11 +16,11 @@ echo "server: ", $row['Value'], "\n"; mysqli_free_result($res); mysqli_close($link); -echo "connector: ", ini_get("mysqli.allow_local_infile"), "\n"; +echo 'connector: ', ini_get('mysqli.allow_local_infile'), ' ', var_export(ini_get('mysqli.local_infile_directory')), "\n"; print "done!\n"; ?> --EXPECTF-- server: %s -connector: 0 +connector: 0 '' done! diff --git a/ext/mysqli/tests/mysqli_local_infile_directory_access_allowed.phpt b/ext/mysqli/tests/mysqli_local_infile_directory_access_allowed.phpt new file mode 100644 index 0000000000..a9c0c82e99 --- /dev/null +++ b/ext/mysqli/tests/mysqli_local_infile_directory_access_allowed.phpt @@ -0,0 +1,80 @@ +--TEST-- +mysqli.local_infile_directory vs access allowed +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die("skip Cannot connect to MySQL"); + +include_once("local_infile_tools.inc"); +if ($msg = check_local_infile_allowed_by_server($link)) + die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); + +mysqli_close($link); + +?> +--INI-- +open_basedir={PWD} +mysqli.allow_local_infile=0 +mysqli.local_infile_directory={PWD}/foo +--FILE-- +<?php + require_once("connect.inc"); + + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + } + + if (!$link->query("DROP TABLE IF EXISTS test")) { + printf("[002] [%d] %s\n", $link->errno, $link->error); + } + + if (!$link->query("CREATE TABLE test (id INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine)) { + printf("[003] [%d] %s\n", $link->errno, $link->error); + } + + $filepath = str_replace('\\', '/', __DIR__.'/foo/foo.data'); + if (!$link->query("LOAD DATA LOCAL INFILE '".$filepath."' INTO TABLE test")) { + printf("[004] [%d] %s\n", $link->errno, $link->error); + } + + $filepath = str_replace('\\', '/', __DIR__.'/foo/bar/bar.data'); + if (!$link->query("LOAD DATA LOCAL INFILE '".$filepath."' INTO TABLE test")) { + printf("[005] [%d] %s\n", $link->errno, $link->error); + } + + if ($res = mysqli_query($link, 'SELECT COUNT(id) AS num FROM test')) { + $row = mysqli_fetch_assoc($res); + mysqli_free_result($res); + + $row_count = $row['num']; + $expected_row_count = 6; + if ($row_count != $expected_row_count) { + printf("[006] %d != %d\n", $row_count, $expected_row_count); + } + } else { + printf("[007] [%d] %s\n", $link->errno, $link->error); + } + + $link->close(); + echo "done"; +?> +--CLEAN-- +<?php +require_once('connect.inc'); + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[clean] 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->query($link, 'DROP TABLE IF EXISTS test')) { + printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); +} + +$link->close(); +?> +--EXPECT-- +done diff --git a/ext/mysqli/tests/mysqli_local_infile_directory_access_denied.phpt b/ext/mysqli/tests/mysqli_local_infile_directory_access_denied.phpt new file mode 100644 index 0000000000..8f50e03220 --- /dev/null +++ b/ext/mysqli/tests/mysqli_local_infile_directory_access_denied.phpt @@ -0,0 +1,65 @@ +--TEST-- +mysqli.local_infile_directory access denied +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die("skip Cannot connect to MySQL"); + +include_once("local_infile_tools.inc"); +if ($msg = check_local_infile_allowed_by_server($link)) + die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); + +mysqli_close($link); + +?> +--INI-- +open_basedir={PWD} +mysqli.allow_local_infile=0 +mysqli.local_infile_directory={PWD}/foo/bar +--FILE-- +<?php + require_once("connect.inc"); + + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + } + + if (!$link->query("DROP TABLE IF EXISTS test")) { + printf("[002] [%d] %s\n", $link->errno, $link->error); + } + + if (!$link->query("CREATE TABLE test (id INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine)) { + printf("[003] [%d] %s\n", $link->errno, $link->error); + } + + $filepath = str_replace('\\', '/', __DIR__.'/foo/foo.data'); + if (!$link->query("LOAD DATA LOCAL INFILE '".$filepath."' INTO TABLE test")) { + printf("[004] [%d] %s\n", $link->errno, $link->error); + } else { + printf("[005] bug! should not happen - access denied expected\n"); + } + + $link->close(); + echo "done"; +?> +--CLEAN-- +<?php +require_once('connect.inc'); + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[clean] 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->query($link, 'DROP TABLE IF EXISTS test')) { + printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); +} + +$link->close(); +?> +--EXPECTF-- +[004] [2068] LOAD DATA LOCAL INFILE %s +done diff --git a/ext/mysqli/tests/mysqli_local_infile_directory_vs_open_basedir.phpt b/ext/mysqli/tests/mysqli_local_infile_directory_vs_open_basedir.phpt new file mode 100644 index 0000000000..a48606ad66 --- /dev/null +++ b/ext/mysqli/tests/mysqli_local_infile_directory_vs_open_basedir.phpt @@ -0,0 +1,65 @@ +--TEST-- +mysqli.local_infile_directory vs open_basedir +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die("skip Cannot connect to MySQL"); + +include_once("local_infile_tools.inc"); +if ($msg = check_local_infile_allowed_by_server($link)) + die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); + +mysqli_close($link); + +?> +--INI-- +open_basedir={PWD} +mysqli.allow_local_infile=0 +mysqli.local_infile_directory={PWD}/../ +--FILE-- +<?php + require_once("connect.inc"); + + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + } + + if (!$link->query("DROP TABLE IF EXISTS test")) { + printf("[002] [%d] %s\n", $link->errno, $link->error); + } + + if (!$link->query("CREATE TABLE test (id INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine)) { + printf("[003] [%d] %s\n", $link->errno, $link->error); + } + + $filepath = str_replace('\\', '/', __DIR__.'/foo/foo.data'); + if (!$link->query("LOAD DATA LOCAL INFILE '".$filepath."' INTO TABLE test")) { + printf("[004] [%d] %s\n", $link->errno, $link->error); + } else { + printf("[005] bug! should not happen - operation not permitted expected\n"); + } + + echo "done"; +?> +--CLEAN-- +<?php +require_once('connect.inc'); + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[clean] 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->query($link, 'DROP TABLE IF EXISTS test')) { + printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); +} + +$link->close(); +?> +--EXPECTF-- +Warning: mysqli_connect(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d +[004] [2068] LOAD DATA LOCAL INFILE %s +done diff --git a/ext/mysqli/tests/mysqli_phpinfo.phpt b/ext/mysqli/tests/mysqli_phpinfo.phpt index fd0edd4463..ea78a6bb0c 100644 --- a/ext/mysqli/tests/mysqli_phpinfo.phpt +++ b/ext/mysqli/tests/mysqli_phpinfo.phpt @@ -46,7 +46,7 @@ require_once('skipifconnectfailure.inc'); if ($IS_MYSQLND) { $expected = array( 'size', - 'mysqli.allow_local_infile', + 'mysqli.allow_local_infile', 'mysqli.local_infile_directory', 'mysqli.allow_persistent', 'mysqli.max_persistent' ); foreach ($expected as $k => $entry) |