Improve unit tests for MysqlSslWarningSafeHosts setting
Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
parent
023cc8598f
commit
808b8eac33
@ -1724,9 +1724,11 @@ Generic settings
|
||||
|
||||
.. config:option:: $cfg['MysqlSslWarningSafeHosts']
|
||||
|
||||
:type: array
|
||||
:type: array [list of non-empty strings]
|
||||
:default: ``['127.0.0.1', 'localhost']``
|
||||
|
||||
.. versionadded:: 5.1.0
|
||||
|
||||
This search is case-sensitive and will match the exact string only.
|
||||
If your setup does not use SSL but is safe because you are using a
|
||||
local connection or private network, you can add your hostname or :term:`IP` to the list.
|
||||
@ -1734,14 +1736,11 @@ Generic settings
|
||||
|
||||
This check uses the value of :config:option:`$cfg['Servers'][$i]['host']`.
|
||||
|
||||
.. versionadded:: 5.1.0
|
||||
|
||||
Example configuration
|
||||
Example configuration:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$cfg['MysqlSslWarningSafeHosts'] = ['127.0.0.1', 'localhost', 'mariadb.local'];
|
||||
|
||||
$cfg['MysqlSslWarningSafeHosts'] = ['127.0.0.1', '::1', 'mariadb.local'];
|
||||
|
||||
.. config:option:: $cfg['ExecTimeLimit']
|
||||
|
||||
|
||||
@ -771,7 +771,7 @@ parameters:
|
||||
-
|
||||
message: '#^Cannot cast mixed to string\.$#'
|
||||
identifier: cast.string
|
||||
count: 45
|
||||
count: 44
|
||||
path: src/Config/Settings.php
|
||||
|
||||
-
|
||||
|
||||
@ -20,6 +20,7 @@ use function defined;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_int;
|
||||
use function is_scalar;
|
||||
use function is_string;
|
||||
use function min;
|
||||
use function sprintf;
|
||||
@ -67,7 +68,7 @@ use const VERSION_CHECK_DEFAULT;
|
||||
* PersistentConnections: bool,
|
||||
* ExecTimeLimit: int<0, max>,
|
||||
* SessionSavePath: string,
|
||||
* MysqlSslWarningSafeHosts: array<string>,
|
||||
* MysqlSslWarningSafeHosts: list<non-empty-string>,
|
||||
* MemoryLimit: string,
|
||||
* SkipLockedTables: bool,
|
||||
* ShowSQL: bool,
|
||||
@ -563,7 +564,7 @@ final class Settings
|
||||
*
|
||||
* @link https://docs.phpmyadmin.net/en/latest/config.html#cfg_MysqlSslWarningSafeHosts
|
||||
*
|
||||
* @var string[]
|
||||
* @var list<non-empty-string>
|
||||
*/
|
||||
public array $MysqlSslWarningSafeHosts;
|
||||
|
||||
@ -3349,7 +3350,7 @@ final class Settings
|
||||
/**
|
||||
* @param array<int|string, mixed> $settings
|
||||
*
|
||||
* @return string[]
|
||||
* @return list<non-empty-string>
|
||||
*/
|
||||
private function setMysqlSslWarningSafeHosts(array $settings): array
|
||||
{
|
||||
@ -3358,8 +3359,11 @@ final class Settings
|
||||
}
|
||||
|
||||
$hosts = [];
|
||||
/** @var mixed $host */
|
||||
foreach ($settings['MysqlSslWarningSafeHosts'] as $host) {
|
||||
if (! is_scalar($host)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$safeHost = (string) $host;
|
||||
if ($safeHost === '') {
|
||||
continue;
|
||||
|
||||
@ -37,7 +37,6 @@ use const ROOT_PATH;
|
||||
class SettingsTest extends TestCase
|
||||
{
|
||||
private const DEFAULT_VALUES = [
|
||||
'MysqlSslWarningSafeHosts' => ['127.0.0.1', 'localhost'],
|
||||
'MemoryLimit' => '-1',
|
||||
'SkipLockedTables' => false,
|
||||
'ShowSQL' => true,
|
||||
@ -307,7 +306,6 @@ class SettingsTest extends TestCase
|
||||
return [
|
||||
'null values' => [
|
||||
[
|
||||
['MysqlSslWarningSafeHosts', null, ['127.0.0.1', 'localhost']],
|
||||
['MemoryLimit', null, '-1'],
|
||||
['SkipLockedTables', null, false],
|
||||
['ShowSQL', null, true],
|
||||
@ -471,7 +469,6 @@ class SettingsTest extends TestCase
|
||||
],
|
||||
'valid values' => [
|
||||
[
|
||||
['MysqlSslWarningSafeHosts', ['test1', 'test2'], ['test1', 'test2']],
|
||||
['MemoryLimit', '16M', '16M'],
|
||||
['SkipLockedTables', true, true],
|
||||
['ShowSQL', false, false],
|
||||
@ -761,7 +758,6 @@ class SettingsTest extends TestCase
|
||||
'valid values 11' => [[['NavigationTreeDefaultTabTable2', '', '']]],
|
||||
'valid values with type coercion' => [
|
||||
[
|
||||
['MysqlSslWarningSafeHosts', ['127.0.0.1' => 'local', false, 1234 => 1234], ['local', '1234']],
|
||||
['MemoryLimit', 1234, '1234'],
|
||||
['SkipLockedTables', 1, true],
|
||||
['ShowSQL', 0, false],
|
||||
@ -893,7 +889,6 @@ class SettingsTest extends TestCase
|
||||
],
|
||||
'invalid values' => [
|
||||
[
|
||||
['MysqlSslWarningSafeHosts', 'invalid', ['127.0.0.1', 'localhost']],
|
||||
['CookieSameSite', 'invalid', 'Strict'],
|
||||
['LoginCookieValidity', 0, 1440],
|
||||
['LoginCookieStore', -1, 0],
|
||||
@ -1496,4 +1491,30 @@ class SettingsTest extends TestCase
|
||||
yield 'valid value 5' => ['desc', 'DESC'];
|
||||
yield 'invalid value' => ['invalid', 'NONE'];
|
||||
}
|
||||
|
||||
/** @param list<non-empty-string> $expected */
|
||||
#[DataProvider('valuesForMysqlSslWarningSafeHostsProvider')]
|
||||
public function testMysqlSslWarningSafeHosts(mixed $actual, array $expected): void
|
||||
{
|
||||
$settings = new Settings(['MysqlSslWarningSafeHosts' => $actual]);
|
||||
$settingsArray = $settings->asArray();
|
||||
self::assertSame($expected, $settings->MysqlSslWarningSafeHosts);
|
||||
self::assertSame($expected, $settingsArray['MysqlSslWarningSafeHosts']);
|
||||
}
|
||||
|
||||
/** @return iterable<string, array{mixed, list<non-empty-string>}> */
|
||||
public static function valuesForMysqlSslWarningSafeHostsProvider(): iterable
|
||||
{
|
||||
yield 'null value' => [null, ['127.0.0.1', 'localhost']];
|
||||
yield 'valid value' => [['local.host', '::1'], ['local.host', '::1']];
|
||||
yield 'valid value 2' => [['127.0.0.1', 'localhost'], ['127.0.0.1', 'localhost']];
|
||||
yield 'valid value 3' => [[], []];
|
||||
yield 'valid value with type coercion' => [
|
||||
['127.0.0.1' => 'local', 4321 => 1234, true],
|
||||
['local', '1234', '1'],
|
||||
];
|
||||
|
||||
yield 'invalid value' => ['invalid', ['127.0.0.1', 'localhost']];
|
||||
yield 'invalid list values' => [[false, [], ['localhost'], '', null, 'localhost'], ['localhost']];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user