Merge pull request #6687 from marc1706/ticket/12479

[ticket/12479] Remove deprecated functions
This commit is contained in:
Marc Alexander 2024-07-24 22:45:53 +02:00 committed by GitHub
commit 2afb6bd8cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 410 additions and 1341 deletions

View file

@ -383,14 +383,14 @@ jobs:
db: "mcr.microsoft.com/mssql/server:2019-latest"
db_alias: 'MSSQL 2019'
- php: '8.1'
db: "mcr.microsoft.com/mssql/server:2022-latest"
db: "mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04"
db_alias: 'MSSQL 2022'
name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}
services:
mssql:
image: ${{ matrix.db != 'mcr.microsoft.com/mssql/server:2017-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2019-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2022-latest' && 'mcr.microsoft.com/mssql/server:2017-latest' || matrix.db }}
image: ${{ matrix.db != 'mcr.microsoft.com/mssql/server:2017-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2019-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04' && 'mcr.microsoft.com/mssql/server:2017-latest' || matrix.db }}
env:
SA_PASSWORD: "Pssw0rd_12"
ACCEPT_EULA: "y"
@ -422,7 +422,7 @@ jobs:
env:
MATRIX_DB: ${{ matrix.db }}
run: |
if [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2017-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2019-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2022-latest' ]
if [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2017-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2019-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04' ]
then
db='mssql'
else

View file

@ -651,38 +651,4 @@ class bbcode
return $code;
}
/**
* Function to perform custom bbcode second pass by extensions
* can be used to assign bbcode pattern replacement
* Example: '#\[list=([^\[]+):$uid\]#e' => "\$this->bbcode_second_pass_by_extension('\$1')"
*
* Accepts variable number of parameters
*
* @return bool Second pass result
*
* @deprecated 3.2.10 (To be removed 4.0.0)
*/
function bbcode_second_pass_by_extension()
{
global $phpbb_dispatcher;
$return = false;
$params_array = func_get_args();
/**
* Event to perform bbcode second pass with
* the custom validating methods provided by extensions
*
* @event core.bbcode_second_pass_by_extension
* @var array params_array Array with the function parameters
* @var mixed return Second pass result to return
*
* @since 3.1.5-RC1
*/
$vars = array('params_array', 'return');
extract($phpbb_dispatcher->trigger_event('core.bbcode_second_pass_by_extension', compact($vars)));
return $return;
}
}

View file

@ -49,8 +49,6 @@ function register_compatibility_globals()
/* @var $request \phpbb\request\request_interface */
$request = $phpbb_container->get('request');
// Inject request instance, so only this instance is used with request_var
request_var('', 0, false, false, $request);
/* @var $user \phpbb\user */
$user = $phpbb_container->get('user');
@ -67,8 +65,6 @@ function register_compatibility_globals()
// Grab global variables, re-cache if necessary
/* @var $config phpbb\config\db */
$config = $phpbb_container->get('config');
set_config('', '', false, $config);
set_config_count('', 0, false, $config);
/* @var $phpbb_log \phpbb\log\log_interface */
$phpbb_log = $phpbb_container->get('log');

View file

@ -19,835 +19,6 @@ if (!defined('IN_PHPBB'))
exit;
}
/**
* Hash the password
*
* @deprecated 3.1.0-a2 (To be removed: 4.0.0)
*
* @param string $password Password to be hashed
*
* @return string|bool Password hash or false if something went wrong during hashing
*/
function phpbb_hash($password)
{
global $phpbb_container;
/* @var $passwords_manager \phpbb\passwords\manager */
$passwords_manager = $phpbb_container->get('passwords.manager');
return $passwords_manager->hash($password);
}
/**
* Check for correct password
*
* @deprecated 3.1.0-a2 (To be removed: 4.0.0)
*
* @param string $password The password in plain text
* @param string $hash The stored password hash
*
* @return bool Returns true if the password is correct, false if not.
*/
function phpbb_check_hash($password, $hash)
{
global $phpbb_container;
/* @var $passwords_manager \phpbb\passwords\manager */
$passwords_manager = $phpbb_container->get('passwords.manager');
return $passwords_manager->check($password, $hash);
}
/**
* Eliminates useless . and .. components from specified path.
*
* Deprecated, use storage helper class instead
*
* @param string $path Path to clean
* @return string Cleaned path
*
* @deprecated 3.1.0 (To be removed: 4.0.0)
*/
function phpbb_clean_path($path)
{
return \phpbb\filesystem\helper::clean_path($path);
}
/**
* Pick a timezone
*
* @param string $default A timezone to select
* @param boolean $truncate Shall we truncate the options text
*
* @return string Returns the options for timezone selector only
*
* @deprecated 3.1.0 (To be removed: 4.0.0)
*/
function tz_select($default = '', $truncate = false)
{
global $user;
return phpbb_timezone_select($user, $default, $truncate);
}
/**
* Cache moderators. Called whenever permissions are changed
* via admin_permissions. Changes of usernames and group names
* must be carried through for the moderators table.
*
* @deprecated 3.1.0 (To be removed: 4.0.0)
* @return void
*/
function cache_moderators()
{
global $db, $cache, $auth, $phpbb_container;
phpbb_cache_moderators($db, $phpbb_container->get('dbal.tools'), $cache, $auth);
}
/**
* Removes moderators and administrators from foe lists.
*
* @deprecated 3.1.0 (To be removed: 4.0.0)
* @param array|bool $group_id If an array, remove all members of this group from foe lists, or false to ignore
* @param array|bool $user_id If an array, remove this user from foe lists, or false to ignore
* @return void
*/
function update_foes($group_id = false, $user_id = false)
{
global $db, $auth;
return phpbb_update_foes($db, $auth, $group_id, $user_id);
}
/**
* Get user rank title and image
*
* @param int $user_rank the current stored users rank id
* @param int $user_posts the users number of posts
* @param string &$rank_title the rank title will be stored here after execution
* @param string &$rank_img the rank image as full img tag is stored here after execution
* @param string &$rank_img_src the rank image source is stored here after execution
*
* @deprecated 3.1.0-RC5 (To be removed: 4.0.0)
*
* Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false
*/
function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
{
global $phpbb_root_path, $phpEx;
if (!function_exists('phpbb_get_user_rank'))
{
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
}
$rank_data = phpbb_get_user_rank(array('user_rank' => $user_rank), $user_posts);
$rank_title = $rank_data['title'];
$rank_img = $rank_data['img'];
$rank_img_src = $rank_data['img_src'];
}
/**
* Retrieve contents from remotely stored file
*
* @deprecated 3.1.2 Use file_downloader instead
*/
function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port = 80, $timeout = 6)
{
global $phpbb_container;
// Get file downloader and assign $errstr and $errno
/* @var $file_downloader \phpbb\file_downloader */
$file_downloader = $phpbb_container->get('file_downloader');
$file_data = $file_downloader->get($host, $directory, $filename, $port, $timeout);
$errstr = $file_downloader->get_error_string();
$errno = $file_downloader->get_error_number();
return $file_data;
}
/**
* Add log entry
*
* string $mode The mode defines which log_type is used and from which log the entry is retrieved
* int $forum_id Mode 'mod' ONLY: forum id of the related item, NOT INCLUDED otherwise
* int $topic_id Mode 'mod' ONLY: topic id of the related item, NOT INCLUDED otherwise
* int $reportee_id Mode 'user' ONLY: user id of the reportee, NOT INCLUDED otherwise
* string $log_operation Name of the operation
* array $additional_data More arguments can be added, depending on the log_type
*
* @return int|bool Returns the log_id, if the entry was added to the database, false otherwise.
*
* @deprecated 3.1.0 (To be removed: 4.0.0)
*/
function add_log()
{
global $phpbb_log, $user;
$args = func_get_args();
$mode = array_shift($args);
// This looks kind of dirty, but add_log has some additional data before the log_operation
$additional_data = array();
switch ($mode)
{
case 'admin':
case 'critical':
break;
case 'mod':
$additional_data['forum_id'] = array_shift($args);
$additional_data['topic_id'] = array_shift($args);
break;
case 'user':
$additional_data['reportee_id'] = array_shift($args);
break;
}
$log_operation = array_shift($args);
$additional_data = array_merge($additional_data, $args);
$user_id = (empty($user->data)) ? ANONYMOUS : $user->data['user_id'];
$user_ip = (empty($user->ip)) ? '' : $user->ip;
return $phpbb_log->add($mode, $user_id, $user_ip, $log_operation, time(), $additional_data);
}
/**
* Sets a configuration option's value.
*
* Please note that this function does not update the is_dynamic value for
* an already existing config option.
*
* @param string $config_name The configuration option's name
* @param string $config_value New configuration value
* @param bool $is_dynamic Whether this variable should be cached (false) or
* if it changes too frequently (true) to be
* efficiently cached.
*
* @return void
*
* @deprecated 3.1.0 (To be removed: 4.0.0)
*/
function set_config($config_name, $config_value, $is_dynamic = false, \phpbb\config\config $set_config = null)
{
static $config = null;
if ($set_config !== null)
{
$config = $set_config;
if (empty($config_name))
{
return;
}
}
$config->set($config_name, $config_value, !$is_dynamic);
}
/**
* Increments an integer config value directly in the database.
*
* @param string $config_name The configuration option's name
* @param int $increment Amount to increment by
* @param bool $is_dynamic Whether this variable should be cached (false) or
* if it changes too frequently (true) to be
* efficiently cached.
*
* @return void
*
* @deprecated 3.1.0 (To be removed: 4.0.0)
*/
function set_config_count($config_name, $increment, $is_dynamic = false, \phpbb\config\config $set_config = null)
{
static $config = null;
if ($set_config !== null)
{
$config = $set_config;
if (empty($config_name))
{
return;
}
}
$config->increment($config_name, $increment, !$is_dynamic);
}
/**
* Wrapper function of \phpbb\request\request::variable which exists for backwards compatability.
* See {@link \phpbb\request\request_interface::variable \phpbb\request\request_interface::variable} for
* documentation of this function's use.
*
* @deprecated 3.1.0 (To be removed: 4.0.0)
* @param mixed $var_name The form variable's name from which data shall be retrieved.
* If the value is an array this may be an array of indizes which will give
* direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a")
* then specifying array("var", 1) as the name will return "a".
* If you pass an instance of {@link \phpbb\request\request_interface phpbb_request_interface}
* as this parameter it will overwrite the current request class instance. If you do
* not do so, it will create its own instance (but leave superglobals enabled).
* @param mixed $default A default value that is returned if the variable was not set.
* This function will always return a value of the same type as the default.
* @param bool $multibyte If $default is a string this paramater has to be true if the variable may contain any UTF-8 characters
* Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks
* @param bool $cookie This param is mapped to \phpbb\request\request_interface::COOKIE as the last param for
* \phpbb\request\request_interface::variable for backwards compatability reasons.
* @param \phpbb\request\request_interface|null|false $request
* If an instance of \phpbb\request\request_interface is given the instance is stored in
* a static variable and used for all further calls where this parameters is null. Until
* the function is called with an instance it automatically creates a new \phpbb\request\request
* instance on every call. By passing false this per-call instantiation can be restored
* after having passed in a \phpbb\request\request_interface instance.
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
function request_var($var_name, $default, $multibyte = false, $cookie = false, $request = null)
{
// This is all just an ugly hack to add "Dependency Injection" to a function
// the only real code is the function call which maps this function to a method.
static $static_request = null;
if ($request instanceof \phpbb\request\request_interface)
{
$static_request = $request;
if (empty($var_name))
{
return null;
}
}
else if ($request === false)
{
$static_request = null;
if (empty($var_name))
{
return null;
}
}
$tmp_request = $static_request;
// no request class set, create a temporary one ourselves to keep backwards compatibility
if ($tmp_request === null)
{
// false param: enable super globals, so the created request class does not
// make super globals inaccessible everywhere outside this function.
$tmp_request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
}
return $tmp_request->variable($var_name, $default, $multibyte, ($cookie) ? \phpbb\request\request_interface::COOKIE : \phpbb\request\request_interface::REQUEST);
}
/**
* Get tables of a database
*
* @deprecated 3.1.0 (To be removed: 4.0.0)
*/
function get_tables($db)
{
throw new BadFunctionCallException('function removed from phpBB core, use db_tools service instead.');
}
/**
* Global function for chmodding directories and files for internal use
*
* This function determines owner and group whom the file belongs to and user and group of PHP and then set safest possible file permissions.
* The function determines owner and group from common.php file and sets the same to the provided file.
* The function uses bit fields to build the permissions.
* The function sets the appropiate execute bit on directories.
*
* Supported constants representing bit fields are:
*
* CHMOD_ALL - all permissions (7)
* CHMOD_READ - read permission (4)
* CHMOD_WRITE - write permission (2)
* CHMOD_EXECUTE - execute permission (1)
*
* NOTE: The function uses POSIX extension and fileowner()/filegroup() functions. If any of them is disabled, this function tries to build proper permissions, by calling is_readable() and is_writable() functions.
*
* @param string $filename The file/directory to be chmodded
* @param int $perms Permissions to set
*
* @return bool true on success, otherwise false
*
* @deprecated 3.2.0-dev use \phpbb\filesystem\filesystem::phpbb_chmod() instead
*/
function phpbb_chmod($filename, $perms = CHMOD_READ)
{
global $phpbb_filesystem;
try
{
$phpbb_filesystem->phpbb_chmod($filename, $perms);
}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{
return false;
}
return true;
}
/**
* Test if a file/directory is writable
*
* This function calls the native is_writable() when not running under
* Windows and it is not disabled.
*
* @param string $file Path to perform write test on
* @return bool True when the path is writable, otherwise false.
*
* @deprecated 3.2.0-dev use \phpbb\filesystem\filesystem::is_writable() instead
*/
function phpbb_is_writable($file)
{
global $phpbb_filesystem;
return $phpbb_filesystem->is_writable($file);
}
/**
* Checks if a path ($path) is absolute or relative
*
* @param string $path Path to check absoluteness of
* @return boolean
*
* @deprecated 3.2.0-dev use \phpbb\filesystem\helper::is_absolute_path() instead
*/
function phpbb_is_absolute($path)
{
return \phpbb\filesystem\helper::is_absolute_path($path);
}
/**
* A wrapper for realpath
*
* @deprecated 3.2.0-dev use \phpbb\filesystem\helper::realpath() instead
*/
function phpbb_realpath($path)
{
return \phpbb\filesystem\helper::realpath($path);
}
/**
* Determine which plural form we should use.
* For some languages this is not as simple as for English.
*
* @param int $rule ID of the plural rule we want to use, see https://area51.phpbb.com/docs/dev/3.3.x/language/plurals.html
* @param int|float $number The number we want to get the plural case for. Float numbers are floored.
* @return int The plural-case we need to use for the number plural-rule combination
*
* @deprecated 3.2.0-dev (To be removed: 4.0.0)
*/
function phpbb_get_plural_form($rule, $number)
{
global $phpbb_container;
/** @var \phpbb\language\language $language */
$language = $phpbb_container->get('language');
return $language->get_plural_form($number, $rule);
}
/**
* @return bool Always true
* @deprecated 3.2.0-dev
*/
function phpbb_pcre_utf8_support()
{
return true;
}
/**
* Casts a variable to the given type.
*
* @deprecated 3.1 (To be removed 4.0.0)
*/
function set_var(&$result, $var, $type, $multibyte = false)
{
// no need for dependency injection here, if you have the object, call the method yourself!
$type_cast_helper = new \phpbb\request\type_cast_helper();
$type_cast_helper->set_var($result, $var, $type, $multibyte);
}
/**
* Delete Attachments
*
* @deprecated 3.2.0-a1 (To be removed: 4.0.0)
*
* @param string $mode can be: post|message|topic|attach|user
* @param mixed $ids can be: post_ids, message_ids, topic_ids, attach_ids, user_ids
* @param bool $resync set this to false if you are deleting posts or topics
*/
function delete_attachments($mode, $ids, $resync = true)
{
global $phpbb_container;
/** @var \phpbb\attachment\manager $attachment_manager */
$attachment_manager = $phpbb_container->get('attachment.manager');
$num_deleted = $attachment_manager->delete($mode, $ids, $resync);
unset($attachment_manager);
return $num_deleted;
}
/**
* Delete attached file
*
* @deprecated 3.2.0-a1 (To be removed: 4.0.0)
*/
function phpbb_unlink($filename, $mode = 'file', $entry_removed = false)
{
global $phpbb_container;
/** @var \phpbb\attachment\manager $attachment_manager */
$attachment_manager = $phpbb_container->get('attachment.manager');
$unlink = $attachment_manager->unlink($filename, $mode, $entry_removed);
unset($attachment_manager);
return $unlink;
}
/**
* Display reasons
*
* @deprecated 3.2.0-dev (To be removed: 4.0.0)
*/
function display_reasons($reason_id = 0)
{
global $phpbb_container;
$phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id);
}
/**
* Upload Attachment - filedata is generated here
* Uses upload class
*
* @deprecated 3.2.0-a1 (To be removed: 4.0.0)
*
* @param string $form_name The form name of the file upload input
* @param int $forum_id The id of the forum
* @param bool $local Whether the file is local or not
* @param string $local_storage The path to the local file
* @param bool $is_message Whether it is a PM or not
* @param array $local_filedata A filespec object created for the local file
*
* @return array File data array
*/
function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false)
{
global $phpbb_container;
/** @var \phpbb\attachment\manager $attachment_manager */
$attachment_manager = $phpbb_container->get('attachment.manager');
$file = $attachment_manager->upload($form_name, $forum_id, $local, $local_storage, $is_message, $local_filedata);
unset($attachment_manager);
return $file;
}
/**
* Wrapper for php's checkdnsrr function.
*
* @param string $host Fully-Qualified Domain Name
* @param string $type Resource record type to lookup
* Supported types are: MX (default), A, AAAA, NS, TXT, CNAME
* Other types may work or may not work
*
* @return bool|null true if entry found,
* false if entry not found,
* null if this function is not supported by this environment
*
* Since null can also be returned, you probably want to compare the result
* with === true or === false,
*
* @deprecated 3.3.0-b2 (To be removed: 4.0.0)
*/
function phpbb_checkdnsrr($host, $type = 'MX')
{
return checkdnsrr($host, $type);
}
/*
* Wrapper for inet_ntop()
*
* Converts a packed internet address to a human readable representation
* inet_ntop() is supported by PHP since 5.1.0, since 5.3.0 also on Windows.
*
* @param string $in_addr A 32bit IPv4, or 128bit IPv6 address.
*
* @return mixed false on failure,
* string otherwise
*
* @deprecated 3.3.0-b2 (To be removed: 4.0.0)
*/
function phpbb_inet_ntop($in_addr)
{
return inet_ntop($in_addr);
}
/**
* Wrapper for inet_pton()
*
* Converts a human readable IP address to its packed in_addr representation
* inet_pton() is supported by PHP since 5.1.0, since 5.3.0 also on Windows.
*
* @param string $address A human readable IPv4 or IPv6 address.
*
* @return false|string false if address is invalid,
* in_addr representation of the given address otherwise (string)
*
* @deprecated 3.3.0-b2 (To be removed: 4.0.0)
*/
function phpbb_inet_pton($address)
{
return inet_pton($address);
}
/**
* Hashes an email address to a big integer
*
* @param string $email Email address
*
* @return string Unsigned Big Integer
*
* @deprecated 3.3.0-b2 (To be removed: 4.0.0)
*/
function phpbb_email_hash($email)
{
return sprintf('%u', crc32(strtolower($email))) . strlen($email);
}
/**
* Load the autoloaders added by the extensions.
*
* @param string $phpbb_root_path Path to the phpbb root directory.
*/
function phpbb_load_extensions_autoloaders($phpbb_root_path)
{
$iterator = new \phpbb\finder\recursive_path_iterator(
$phpbb_root_path . 'ext/',
\RecursiveIteratorIterator::SELF_FIRST,
\FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS
);
$iterator->setMaxDepth(2);
foreach ($iterator as $file_info)
{
if ($file_info->getFilename() === 'vendor' && $iterator->getDepth() === 2)
{
$filename = $file_info->getRealPath() . '/autoload.php';
if (file_exists($filename))
{
require $filename;
}
}
}
}
/**
* Login using http authenticate.
*
* @param array $param Parameter array, see $param_defaults array.
*
* @return void
*
* @deprecated 3.2.10 (To be removed 4.0.0)
*/
function phpbb_http_login($param)
{
global $auth, $user, $request;
global $config;
$param_defaults = array(
'auth_message' => '',
'autologin' => false,
'viewonline' => true,
'admin' => false,
);
// Overwrite default values with passed values
$param = array_merge($param_defaults, $param);
// User is already logged in
// We will not overwrite his session
if (!empty($user->data['is_registered']))
{
return;
}
// $_SERVER keys to check
$username_keys = array(
'PHP_AUTH_USER',
'Authorization',
'REMOTE_USER', 'REDIRECT_REMOTE_USER',
'HTTP_AUTHORIZATION', 'REDIRECT_HTTP_AUTHORIZATION',
'REMOTE_AUTHORIZATION', 'REDIRECT_REMOTE_AUTHORIZATION',
'AUTH_USER',
);
$password_keys = array(
'PHP_AUTH_PW',
'REMOTE_PASSWORD',
'AUTH_PASSWORD',
);
$username = null;
foreach ($username_keys as $k)
{
if ($request->is_set($k, \phpbb\request\request_interface::SERVER))
{
$username = html_entity_decode($request->server($k), ENT_COMPAT);
break;
}
}
$password = null;
foreach ($password_keys as $k)
{
if ($request->is_set($k, \phpbb\request\request_interface::SERVER))
{
$password = html_entity_decode($request->server($k), ENT_COMPAT);
break;
}
}
// Decode encoded information (IIS, CGI, FastCGI etc.)
if (!is_null($username) && is_null($password) && strpos($username, 'Basic ') === 0)
{
list($username, $password) = explode(':', base64_decode(substr($username, 6)), 2);
}
if (!is_null($username) && !is_null($password))
{
set_var($username, $username, 'string', true);
set_var($password, $password, 'string', true);
$auth_result = $auth->login($username, $password, $param['autologin'], $param['viewonline'], $param['admin']);
if ($auth_result['status'] == LOGIN_SUCCESS)
{
return;
}
else if ($auth_result['status'] == LOGIN_ERROR_ATTEMPTS)
{
send_status_line(401, 'Unauthorized');
trigger_error('NOT_AUTHORISED');
}
}
// Prepend sitename to auth_message
$param['auth_message'] = ($param['auth_message'] === '') ? $config['sitename'] : $config['sitename'] . ' - ' . $param['auth_message'];
// We should probably filter out non-ASCII characters - RFC2616
$param['auth_message'] = preg_replace('/[\x80-\xFF]/', '?', $param['auth_message']);
header('WWW-Authenticate: Basic realm="' . $param['auth_message'] . '"');
send_status_line(401, 'Unauthorized');
trigger_error('NOT_AUTHORISED');
}
/**
* Converts query string (GET) parameters in request into hidden fields.
*
* Useful for forwarding GET parameters when submitting forms with GET method.
*
* It is possible to omit some of the GET parameters, which is useful if
* they are specified in the form being submitted.
*
* sid is always omitted.
*
* @param \phpbb\request\request $request Request object
* @param array $exclude A list of variable names that should not be forwarded
* @return string HTML with hidden fields
*
* @deprecated 3.2.10 (To be removed 4.0.0)
*/
function phpbb_build_hidden_fields_for_query_params($request, $exclude = null)
{
$names = $request->variable_names(\phpbb\request\request_interface::GET);
$hidden = '';
foreach ($names as $name)
{
// Sessions are dealt with elsewhere, omit sid always
if ($name == 'sid')
{
continue;
}
// Omit any additional parameters requested
if (!empty($exclude) && in_array($name, $exclude))
{
continue;
}
$escaped_name = phpbb_quoteattr($name);
// Note: we might retrieve the variable from POST or cookies
// here. To avoid exposing cookies, skip variables that are
// overwritten somewhere other than GET entirely.
$value = $request->variable($name, '', true);
$get_value = $request->variable($name, '', true, \phpbb\request\request_interface::GET);
if ($value === $get_value)
{
$escaped_value = phpbb_quoteattr($value);
$hidden .= "<input type='hidden' name=$escaped_name value=$escaped_value />";
}
}
return $hidden;
}
/**
* Delete all PM(s) for a given user and delete the ones without references
*
* @param int $user_id ID of the user whose private messages we want to delete
*
* @return boolean False if there were no pms found, true otherwise.
*
* @deprecated 3.2.10 (To be removed 4.0.0)
*/
function phpbb_delete_user_pms($user_id)
{
$user_id = (int) $user_id;
if (!$user_id)
{
return false;
}
return phpbb_delete_users_pms(array($user_id));
}
/**
* Casts a numeric string $input to an appropriate numeric type (i.e. integer or float)
*
* @param string $input A numeric string.
*
* @return int|float Integer $input if $input fits integer,
* float $input otherwise.
*
* @deprecated 3.2.10 (To be removed 4.0.0)
*/
function phpbb_to_numeric($input)
{
return ($input > PHP_INT_MAX) ? (float) $input : (int) $input;
}
/**
* Check and display the SQL report if requested.
*
* @param \phpbb\request\request_interface $request Request object
* @param \phpbb\auth\auth $auth Auth object
* @param \phpbb\db\driver\driver_interface $db Database connection
*
* @deprecated 3.3.1 (To be removed: 4.0.0-a1); use controller helper's display_sql_report()
*/
function phpbb_check_and_display_sql_report(\phpbb\request\request_interface $request, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db)
{
global $phpbb_container;
/** @var \phpbb\controller\helper $controller_helper */
$controller_helper = $phpbb_container->get('controller.helper');
$controller_helper->display_sql_report();
}
/**
* Parse cfg file
* @param string $filename
@ -909,27 +80,3 @@ function parse_cfg_file($filename, $lines = false)
return $parsed_items;
}
/**
* Wraps an url into a simple html page. Used to display attachments in IE.
* this is a workaround for now; might be moved to template system later
* direct any complaints to 1 Microsoft Way, Redmond
*
* @deprecated: 3.3.0-dev (To be removed: 4.0.0)
*/
function wrap_img_in_html($src, $title)
{
echo '<!DOCTYPE html>';
echo '<html>';
echo '<head>';
echo '<meta charset="utf-8">';
echo '<meta http-equiv="X-UA-Compatible" content="IE=edge">';
echo '<title>' . $title . '</title>';
echo '</head>';
echo '<body>';
echo '<div>';
echo '<img src="' . $src . '" alt="' . $title . '" />';
echo '</div>';
echo '</body>';
echo '</html>';
}

View file

@ -13,91 +13,116 @@
namespace phpbb;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use phpbb\exception\runtime_exception;
class file_downloader
{
const OK = 200;
const NOT_FOUND = 404;
const REQUEST_TIMEOUT = 408;
/** @var string Error string */
protected $error_string = '';
protected string $error_string = '';
/** @var int Error number */
protected $error_number = 0;
protected int $error_number = 0;
/**
* Create new guzzle client
*
* @param string $host
* @param int $port
* @param int $timeout
*
* @return Client
*/
protected function create_client(string $host, int $port = 443, int $timeout = 6): Client
{
// Only set URL scheme if not specified in URL
$url_parts = parse_url($host);
if (!isset($url_parts['scheme']))
{
$host = (($port === 443) ? 'https://' : 'http://') . $host;
}
// Initialize Guzzle client
return new Client([
'base_uri' => $host,
'timeout' => $timeout,
]);
}
/**
* Retrieve contents from remotely stored file
*
* @param string $host File host
* @param string $directory Directory file is in
* @param string $filename Filename of file to retrieve
* @param int $port Port to connect to; default: 80
* @param int $timeout Connection timeout in seconds; default: 6
* @param string $host File host
* @param string $directory Directory file is in
* @param string $filename Filename of file to retrieve
* @param int $port Port to connect to; default: 80
* @param int $timeout Connection timeout in seconds; default: 6
*
* @return false|string File data as string if file can be read and there is no
* timeout, false if there were errors or the connection timed out
* timeout, false if there were errors or the connection timed out
*
* @throws \phpbb\exception\runtime_exception If data can't be retrieved and no error
* message is returned
* @throws runtime_exception If data can't be retrieved and no error
* message is returned
*/
public function get($host, $directory, $filename, $port = 80, $timeout = 6)
public function get(string $host, string $directory, string $filename, int $port = 443, int $timeout = 6): bool|string
{
// Initialize Guzzle client
$client = $this->create_client($host, $port, $timeout);
// Set default values for error variables
$this->error_number = 0;
$this->error_string = '';
if (function_exists('fsockopen') &&
$socket = @fsockopen(($port == 443 ? 'ssl://' : '') . $host, $port, $this->error_number, $this->error_string, $timeout)
)
try
{
@fputs($socket, "GET $directory/$filename HTTP/1.0\r\n");
@fputs($socket, "HOST: $host\r\n");
@fputs($socket, "Connection: close\r\n\r\n");
$response = $client->request('GET', "$directory/$filename");
$timer_stop = time() + $timeout;
stream_set_timeout($socket, $timeout);
$file_info = '';
$get_info = false;
while (!@feof($socket))
// Check if the response status code is 200 (OK)
if ($response->getStatusCode() == self::OK)
{
if ($get_info)
{
$file_info .= @fread($socket, 1024);
}
else
{
$line = @fgets($socket, 1024);
if ($line == "\r\n")
{
$get_info = true;
}
else if (stripos($line, '404 not found') !== false)
{
throw new \phpbb\exception\runtime_exception('FILE_NOT_FOUND', array($filename));
}
}
$stream_meta_data = stream_get_meta_data($socket);
if ($stream_meta_data['timed_out'] || time() >= $timer_stop)
{
throw new \phpbb\exception\runtime_exception('FSOCK_TIMEOUT');
}
}
@fclose($socket);
}
else
{
if ($this->error_string)
{
$this->error_string = utf8_convert_message($this->error_string);
return false;
return $response->getBody()->getContents();
}
else
{
throw new \phpbb\exception\runtime_exception('FSOCK_DISABLED');
$this->error_number = $response->getStatusCode();
throw new runtime_exception('FILE_NOT_FOUND', [$filename]);
}
}
catch (RequestException $exception)
{
if ($exception->hasResponse())
{
$this->error_number = $exception->getResponse()->getStatusCode();
return $file_info;
if ($this->error_number == self::NOT_FOUND)
{
throw new runtime_exception('FILE_NOT_FOUND', [$filename]);
}
}
else
{
$this->error_number = self::REQUEST_TIMEOUT;
throw new runtime_exception('FSOCK_TIMEOUT');
}
$this->error_string = utf8_convert_message($exception->getMessage());
return false;
}
catch (runtime_exception $exception)
{
// Rethrow runtime_exceptions, only handle unknown cases below
throw $exception;
}
catch (\Throwable $exception)
{
$this->error_string = utf8_convert_message($exception->getMessage());
throw new runtime_exception('FSOCK_DISABLED');
}
}
/**
@ -105,7 +130,7 @@ class file_downloader
*
* @return string Error string
*/
public function get_error_string()
public function get_error_string(): string
{
return $this->error_string;
}
@ -115,7 +140,7 @@ class file_downloader
*
* @return int Error number
*/
public function get_error_number()
public function get_error_number(): int
{
return $this->error_number;
}

View file

@ -398,7 +398,7 @@ class filespec
* @param bool $overwrite If set to true, an already existing file will be overwritten
* @param bool $skip_image_check If set to true, the check for the file to be a valid image is skipped
* @param string|bool $chmod Permission mask for chmodding the file after a successful move.
* The mode entered here reflects the mode defined by {@link phpbb_chmod()}
* The mode entered here reflects the mode defined by {@link \phpbb\filesystem\filesystem::phpbb_chmod()}
*
* @return bool True if file was moved, false if not
* @access public

View file

@ -1,21 +0,0 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb;
/**
* @deprecated 3.2.0-dev (To be removed 4.0.0) use \phpbb\filesystem\filesystem instead
*/
class filesystem extends \phpbb\filesystem\filesystem
{
}

View file

@ -1,175 +0,0 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\php;
/**
* Wrapper class for ini_get function.
*
* Provides easier handling of the different interpretations of ini values.
* @deprecated 3.2.10 (To be removed 4.0.0)
*/
class ini
{
/**
* Simple wrapper for ini_get()
* See http://php.net/manual/en/function.ini-get.php
*
* @param string $varname The configuration option name.
* @return bool|string False if configuration option does not exist,
* the configuration option value (string) otherwise.
*/
public function get($varname)
{
return ini_get($varname);
}
/**
* Gets the configuration option value as a trimmed string.
*
* @param string $varname The configuration option name.
* @return bool|string False if configuration option does not exist,
* the configuration option value (string) otherwise.
*/
public function get_string($varname)
{
$value = $this->get($varname);
if ($value === false)
{
return false;
}
return trim($value);
}
/**
* Gets configuration option value as a boolean.
* Interprets the string value 'off' as false.
*
* @param string $varname The configuration option name.
* @return bool False if configuration option does not exist.
* False if configuration option is disabled.
* True otherwise.
*/
public function get_bool($varname)
{
$value = $this->get_string($varname);
if (empty($value) || strtolower($value) == 'off')
{
return false;
}
return true;
}
/**
* Gets configuration option value as an integer.
*
* @param string $varname The configuration option name.
* @return bool|int False if configuration option does not exist,
* false if configuration option value is not numeric,
* the configuration option value (integer) otherwise.
*/
public function get_int($varname)
{
$value = $this->get_string($varname);
if (!is_numeric($value))
{
return false;
}
return (int) $value;
}
/**
* Gets configuration option value as a float.
*
* @param string $varname The configuration option name.
* @return bool|float False if configuration option does not exist,
* false if configuration option value is not numeric,
* the configuration option value (float) otherwise.
*/
public function get_float($varname)
{
$value = $this->get_string($varname);
if (!is_numeric($value))
{
return false;
}
return (float) $value;
}
/**
* Gets configuration option value in bytes.
* Converts strings like '128M' to bytes (integer or float).
*
* @param string $varname The configuration option name.
* @return bool|int|float False if configuration option does not exist,
* false if configuration option value is not well-formed,
* the configuration option value otherwise.
*/
public function get_bytes($varname)
{
$value = $this->get_string($varname);
if ($value === false)
{
return false;
}
if (is_numeric($value))
{
// Already in bytes.
return phpbb_to_numeric($value);
}
else if (is_string($value))
{
if (strlen($value) < 2)
{
// Single character.
return false;
}
else if (strlen($value) < 3 && $value[0] === '-')
{
// Two characters but the first one is a minus.
return false;
}
}
$value_lower = strtolower($value);
$value_numeric = phpbb_to_numeric($value);
switch ($value_lower[strlen($value_lower) - 1])
{
case 'g':
$value_numeric *= 1024;
case 'm':
$value_numeric *= 1024;
case 'k':
$value_numeric *= 1024;
break;
default:
// It's not already in bytes (and thus numeric)
// and does not carry a unit.
return false;
}
return $value_numeric;
}
}

View file

@ -344,8 +344,9 @@ class plupload
}
$tmp_file = $this->temporary_filepath($upload['tmp_name']);
$filesystem = new \phpbb\filesystem\filesystem();
if (!phpbb_is_writable($this->temporary_directory) || !move_uploaded_file($upload['tmp_name'], $tmp_file))
if (!$filesystem->is_writable($this->temporary_directory) || !move_uploaded_file($upload['tmp_name'], $tmp_file))
{
$this->emit_error(103, 'PLUPLOAD_ERR_MOVE_UPLOADED');
}

View file

@ -184,7 +184,7 @@ class request implements request_interface
* @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE)
* Specifies which super global should be used
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
public function variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST)
@ -208,7 +208,7 @@ class request implements request_interface
* @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE)
* Specifies which super global should be used
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
public function untrimmed_variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST)
@ -401,7 +401,7 @@ class request implements request_interface
* Specifies which super global should be used
* @param bool $trim Indicates whether trim() should be applied to string values.
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
protected function _variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST, $trim = true)

View file

@ -59,7 +59,7 @@ interface request_interface
* @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE)
* Specifies which super global shall be changed
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
public function variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST);
@ -81,7 +81,7 @@ interface request_interface
* @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE)
* Specifies which super global shall be changed
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
public function raw_variable($var_name, $default, $super_global = request_interface::REQUEST);

View file

@ -33,7 +33,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$this->request = $this->createMock('\phpbb\request\request');
$this->user = new \phpbb\user($lang, '\phpbb\datetime');;
$this->user = new \phpbb\user($lang, '\phpbb\datetime');
$this->provider = new \phpbb\auth\provider\apache($config, $db, $lang, $this->request, $this->user, $phpbb_root_path, $phpEx);
}

View file

@ -136,7 +136,7 @@ class phpbb_config_db_test extends phpbb_database_test_case
public function test_increment_new()
{
$this->config->increment('foobar', 3);
$this->assertEquals(3, $this->config['foobar']);;
$this->assertEquals(3, $this->config['foobar']);
}
public function test_delete()

View file

@ -111,7 +111,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_database_test_
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$this->user = new \phpbb\user($lang, '\phpbb\datetime');;
$this->user = new \phpbb\user($lang, '\phpbb\datetime');
$container = new phpbb_mock_container_builder();
$container->setParameter('core.environment', PHPBB_ENVIRONMENT);

View file

@ -1,73 +0,0 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
class phpbb_build_hidden_fields_for_query_params_test extends phpbb_test_case
{
public function build_hidden_fields_for_query_params_test_data()
{
return array(
// get
// post
// exclude
// expected
array(
array('foo' => 'bar'),
array(),
array(),
"<input type='hidden' name=\"foo\" value=\"bar\" />",
),
array(
array('foo' => 'bar', 'a' => 'b'),
array(),
array(),
"<input type='hidden' name=\"foo\" value=\"bar\" /><input type='hidden' name=\"a\" value=\"b\" />",
),
array(
array('a' => 'quote"', 'b' => '<less>'),
array(),
array(),
"<input type='hidden' name=\"a\" value='quote\"' /><input type='hidden' name=\"b\" value=\"&lt;less&gt;\" />",
),
array(
array('a' => "quotes'\""),
array(),
array(),
"<input type='hidden' name=\"a\" value=\"quotes'&quot;\" />",
),
array(
array('foo' => 'bar', 'a' => 'b'),
array('a' => 'c'),
array(),
"<input type='hidden' name=\"foo\" value=\"bar\" />",
),
// strict equality check
array(
array('foo' => 'bar', 'a' => '0'),
array('a' => ''),
array(),
"<input type='hidden' name=\"foo\" value=\"bar\" />",
),
);
}
/**
* @dataProvider build_hidden_fields_for_query_params_test_data
*/
public function test_build_hidden_fields_for_query_params($get, $post, $exclude, $expected)
{
$request = new phpbb_mock_request($get, $post);
$result = phpbb_build_hidden_fields_for_query_params($request, $exclude);
$this->assertEquals($expected, $result);
}
}

View file

@ -1,80 +0,0 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
/**
* @group slow
*/
class phpbb_functions_get_remote_file extends phpbb_test_case
{
public function test_version_phpbb_com()
{
global $phpbb_container;
$phpbb_container = new phpbb_mock_container_builder();
$phpbb_container->set('file_downloader', new \phpbb\file_downloader());
$hostname = 'version.phpbb.com';
if (!checkdnsrr($hostname, 'A'))
{
$this->markTestSkipped(sprintf(
'Could not find a DNS record for hostname %s. ' .
'Assuming network is down.',
$hostname
));
}
$errstr = $errno = null;
$file = get_remote_file($hostname, '/phpbb', '30x.txt', $errstr, $errno);
$this->assertNotEquals(
0,
strlen($file),
'Failed asserting that the response is not empty.'
);
$this->assertSame(
'',
$errstr,
'Failed asserting that the error string is empty.'
);
$this->assertSame(
0,
$errno,
'Failed asserting that the error number is 0 (i.e. no error occurred).'
);
$lines = explode("\n", $file);
$this->assertGreaterThanOrEqual(
2,
count($lines),
'Failed asserting that the version file has at least two lines.'
);
$this->assertStringStartsWith(
'3.',
$lines[0],
"Failed asserting that the first line of the version file starts with '3.'"
);
$this->assertNotSame(
false,
filter_var($lines[1], FILTER_VALIDATE_URL),
'Failed asserting that the second line of the version file is a valid URL.'
);
$this->assertStringContainsString('http', $lines[1]);
$this->assertStringContainsString('phpbb.com', $lines[1], '', true);
}
}

View file

@ -172,19 +172,63 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case
if ($additional3 != null)
{
add_log($mode, $required1, $additional1, $additional2, $additional3);
$additional_data = [
'forum_id' => $required1,
'topic_id' => $additional1,
$additional3,
];
$phpbb_log->add($mode, $user_id, '', $additional2, false, $additional_data);
}
else if ($additional2 != null)
{
add_log($mode, $required1, $additional1, $additional2);
if ($mode == 'user')
{
$additional_data = [
'reportee_id' => $required1,
$additional2,
];
$log_operation = $additional1;
}
else if ($mode == 'mod')
{
$additional_data = [
'forum_id' => $required1,
'topic_id' => $additional1,
];
$log_operation = $additional2;
}
else
{
$log_operation = $required1;
$additional_data = [
$additional1,
$additional2,
];
}
$phpbb_log->add($mode, $user_id, '', $log_operation, false, $additional_data);
}
else if ($additional1 != null)
{
add_log($mode, $required1, $additional1);
if ($mode == 'user')
{
$additional_data = [
'reportee_id' => $required1,
];
$log_operation = $additional1;
}
else
{
$log_operation = $required1;
$additional_data = [
$additional1,
];
}
$phpbb_log->add($mode, $user_id, '', $log_operation, false, $additional_data);
}
else
{
add_log($mode, $required1);
$phpbb_log->add($mode, $user_id, '', $required1);
}
$result = $db->sql_query('SELECT user_id, log_type, log_operation, log_data, reportee_id, forum_id, topic_id

View file

@ -97,7 +97,7 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case
// Works as a workaround for tests
$phpbb_container->set('attachment.manager', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb_mock_event_dispatcher(), new \phpbb\attachment\resync($db), $storage));
phpbb_delete_user_pms($delete_user);
phpbb_delete_users_pms([$delete_user]);
$sql = 'SELECT msg_id
FROM ' . PRIVMSGS_TABLE;

View file

@ -13,15 +13,6 @@
class phpbb_request_var_test extends phpbb_test_case
{
/**
* Makes sure request_var has its standard behaviour.
*/
protected function setUp(): void
{
parent::setUp();
request_var(false, false, false, false, false);
}
/**
* @dataProvider request_variables
*/
@ -33,7 +24,8 @@ class phpbb_request_var_test extends phpbb_test_case
$_POST[$variable_name] = $variable_value;
$_REQUEST[$variable_name] = $variable_value;
$result = request_var($variable_name, $default, $multibyte);
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
$result = $request->variable($variable_name, $default, $multibyte);
$label = 'Requesting POST variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
$this->assertEquals($expected, $result, $label);
@ -50,7 +42,8 @@ class phpbb_request_var_test extends phpbb_test_case
$_GET[$variable_name] = $variable_value;
$_REQUEST[$variable_name] = $variable_value;
$result = request_var($variable_name, $default, $multibyte);
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
$result = $request->variable($variable_name, $default, $multibyte);
$label = 'Requesting GET variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
$this->assertEquals($expected, $result, $label);
@ -69,7 +62,8 @@ class phpbb_request_var_test extends phpbb_test_case
$_REQUEST[$variable_name] = false;
$_COOKIE[$variable_name] = $variable_value;
$result = request_var($variable_name, $default, $multibyte, true);
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
$result = $request->variable($variable_name, $default, $multibyte, \phpbb\request\request_interface::COOKIE);
$label = 'Requesting COOKIE variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
$this->assertEquals($expected, $result, $label);
@ -109,7 +103,8 @@ class phpbb_request_var_test extends phpbb_test_case
),
);
$result = request_var($path, $default);
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
$result = $request->variable($path, $default);
$this->assertEquals($expected, $result);
}

View file

@ -36,7 +36,7 @@ class phpbb_search_native_test extends phpbb_search_test_case
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');;
$user = new \phpbb\user($lang, '\phpbb\datetime');
$this->db = $this->new_dbal();
$tools_factory = new \phpbb\db\tools\factory();

View file

@ -40,16 +40,26 @@ class phpbb_security_hash_test extends phpbb_test_case
public function test_check_hash_with_phpass()
{
$this->assertTrue(phpbb_check_hash('test', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
$this->assertTrue(phpbb_check_hash('test', '$P$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
$this->assertFalse(phpbb_check_hash('foo', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
global $phpbb_container;
/** @var \phpbb\passwords\manager $passwords_manager */
$passwords_manager = $phpbb_container->get('passwords.manager');
$this->assertTrue($passwords_manager->check('test', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
$this->assertTrue($passwords_manager->check('test', '$P$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
$this->assertFalse($passwords_manager->check('foo', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
}
public function test_check_hash_with_large_input()
{
global $phpbb_container;
/** @var \phpbb\passwords\manager $passwords_manager */
$passwords_manager = $phpbb_container->get('passwords.manager');
// 16 MB password, should be rejected quite fast
$start_time = time();
$this->assertFalse(phpbb_check_hash(str_repeat('a', 1024 * 1024 * 16), '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
$this->assertFalse($passwords_manager->check(str_repeat('a', 1024 * 1024 * 16), '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
$this->assertLessThanOrEqual(5, time() - $start_time);
}
}

View file

@ -21,7 +21,6 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
$config = new \phpbb\config\config(array());
set_config(null, null, null, $config);
}
/**

View file

@ -20,7 +20,6 @@ class phpbb_text_processing_generate_text_for_storage_test extends phpbb_test_ca
parent::setUp();
$config = new \phpbb\config\config(array());
set_config(null, null, null, $config);
$phpbb_container = new phpbb_mock_container_builder;
$phpbb_container->set('config', $config);

View file

@ -0,0 +1,4 @@
3.0.14
https://www.phpbb.com/community/viewtopic.php?f=14&t=2313941
3.3.12
https://www.phpbb.com/community/viewtopic.php?t=2653732

View file

@ -1,4 +1,7 @@
<?php
use GuzzleHttp\Exception\RequestException;
/**
*
* This file is part of the phpBB Forum Software package.
@ -18,6 +21,11 @@ class version_helper_remote_test extends \phpbb_test_case
protected $version_helper;
protected $user;
// Guzzle mock data
protected $guzzle_status = 200; // Default to 200 status
protected $guzzle_data;
protected $guzzle_mock;
protected function setUp(): void
{
parent::setUp();
@ -41,7 +49,29 @@ class version_helper_remote_test extends \phpbb_test_case
->method('get')
->with($this->anything())
->will($this->returnValue(false));
$this->file_downloader = new phpbb_mock_file_downloader();
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
->addMethods(['set_data'])
->onlyMethods(['request'])
->getMock();
$this->guzzle_mock->method('set_data')
->will($this->returnCallback(function($data)
{
$this->guzzle_data = $data;
}
));
$this->guzzle_mock->method('request')
->will($this->returnCallback(function()
{
return new \GuzzleHttp\Psr7\Response($this->guzzle_status, [], $this->guzzle_data);
}
));
$this->file_downloader = $this->getMockBuilder('\phpbb\file_downloader')
->onlyMethods(['create_client'])
->getMock();
$this->file_downloader->method('create_client')
->will($this->returnValue($this->guzzle_mock));
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
@ -203,7 +233,7 @@ class version_helper_remote_test extends \phpbb_test_case
*/
public function test_get_versions($input, $valid_data, $expected_return = '', $expected_exception = '')
{
$this->file_downloader->set($input);
$this->guzzle_mock->set_data($input);
// version_helper->get_versions() doesn't return a value on VERSIONCHECK_FAIL but only throws exception
// so the $return is undefined. Define it here
@ -214,7 +244,7 @@ class version_helper_remote_test extends \phpbb_test_case
try {
$return = $this->version_helper->get_versions();
} catch (\phpbb\exception\runtime_exception $e) {
$this->assertEquals((string)$e->getMessage(), $expected_exception);
$this->assertEquals($expected_exception, $e->getMessage());
}
}
else
@ -224,4 +254,206 @@ class version_helper_remote_test extends \phpbb_test_case
$this->assertEquals($expected_return, $return);
}
public function test_version_phpbb_com()
{
$guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
->onlyMethods(['request'])
->getMock();
$guzzle_mock->method('request')
->will($this->returnCallback(function()
{
return new \GuzzleHttp\Psr7\Response(200, [], file_get_contents(__DIR__ . '/fixture/30x.txt'));
}
));
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
->onlyMethods(['create_client'])
->getMock();
$file_downloader->method('create_client')
->willReturn($guzzle_mock);
$hostname = 'version.phpbb.com';
$file = $file_downloader->get($hostname, '/phpbb', '30x.txt');
$errstr = $file_downloader->get_error_string();
$errno = $file_downloader->get_error_number();
$this->assertNotEquals(
0,
strlen($file),
'Failed asserting that the response is not empty.'
);
$this->assertSame(
'',
$errstr,
'Failed asserting that the error string is empty.'
);
$this->assertSame(
0,
$errno,
'Failed asserting that the error number is 0 (i.e. no error occurred).'
);
$lines = explode("\n", $file);
$this->assertGreaterThanOrEqual(
2,
count($lines),
'Failed asserting that the version file has at least two lines.'
);
$this->assertStringStartsWith(
'3.',
$lines[0],
"Failed asserting that the first line of the version file starts with '3.'"
);
$this->assertNotSame(
false,
filter_var($lines[1], FILTER_VALIDATE_URL),
'Failed asserting that the second line of the version file is a valid URL.'
);
$this->assertStringContainsString('http', $lines[1]);
$this->assertStringContainsString('phpbb.com', $lines[1], '', true);
}
public function test_file_downloader_file_not_found()
{
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
->onlyMethods(['request'])
->getMock();
$this->guzzle_mock->method('request')
->will($this->returnCallback(function()
{
return new \GuzzleHttp\Psr7\Response(404, [], '');
}
));
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
->onlyMethods(['create_client'])
->getMock();
$file_downloader->method('create_client')
->willReturn($this->guzzle_mock);
$this->expectException(\phpbb\exception\runtime_exception::class);
$this->expectExceptionMessage('FILE_NOT_FOUND');
$file_downloader->get('foo.com', 'bar', 'foo.txt');
}
public function test_file_downloader_exception_not_found()
{
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
->onlyMethods(['request'])
->getMock();
$this->guzzle_mock->method('request')
->will($this->returnCallback(function($method, $uri)
{
$request = new \GuzzleHttp\Psr7\Request('GET', $uri);
$response = new \GuzzleHttp\Psr7\Response(404, [], '');
throw new RequestException('FILE_NOT_FOUND', $request, $response);
}
));
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
->onlyMethods(['create_client'])
->getMock();
$file_downloader->method('create_client')
->willReturn($this->guzzle_mock);
$this->expectException(\phpbb\exception\runtime_exception::class);
$this->expectExceptionMessage('FILE_NOT_FOUND');
$file_downloader->get('foo.com', 'bar', 'foo.txt');
}
public function test_file_downloader_exception_moved()
{
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
->onlyMethods(['request'])
->getMock();
$this->guzzle_mock->method('request')
->will($this->returnCallback(function($method, $uri)
{
$request = new \GuzzleHttp\Psr7\Request('GET', $uri);
$response = new \GuzzleHttp\Psr7\Response(302, [], '');
throw new RequestException('FILE_MOVED', $request, $response);
}
));
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
->onlyMethods(['create_client'])
->getMock();
$file_downloader->method('create_client')
->willReturn($this->guzzle_mock);
$this->assertFalse($file_downloader->get('foo.com', 'bar', 'foo.txt'));
$this->assertEquals(302, $file_downloader->get_error_number());
$this->assertEquals('FILE_MOVED', $file_downloader->get_error_string());
}
public function test_file_downloader_exception_timeout()
{
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
->onlyMethods(['request'])
->getMock();
$this->guzzle_mock->method('request')
->will($this->returnCallback(function($method, $uri)
{
$request = new \GuzzleHttp\Psr7\Request('GET', $uri);
throw new RequestException('FILE_NOT_FOUND', $request);
}
));
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
->onlyMethods(['create_client'])
->getMock();
$file_downloader->method('create_client')
->willReturn($this->guzzle_mock);
$this->expectException(\phpbb\exception\runtime_exception::class);
$this->expectExceptionMessage('FSOCK_TIMEOUT');
$file_downloader->get('foo.com', 'bar', 'foo.txt');
}
public function test_file_downloader_exception_other()
{
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
->onlyMethods(['request'])
->getMock();
$this->guzzle_mock->method('request')
->will($this->returnCallback(function($method, $uri)
{
throw new \RuntimeException('FSOCK_NOT_SUPPORTED');
}
));
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
->onlyMethods(['create_client'])
->getMock();
$file_downloader->method('create_client')
->willReturn($this->guzzle_mock);
$this->expectException(\phpbb\exception\runtime_exception::class);
$this->expectExceptionMessage('FSOCK_DISABLED');
$file_downloader->get('foo.com', 'bar', 'foo.txt');
}
}