Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-29 06:45:10 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-29 06:45:10 +0300
commit6a9fe03ff29621beced7cbab4164872cb4cd4384 (patch)
treed2b4d3df9bff103349f0c77c07558abbedbbe931 /test
parent000bf397a4ae33ea8334917614c70d2cbcea7546 (diff)
parentadd68b47e314fb74c6e6c11bafbbed6ed8c74344 (diff)
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
-rw-r--r--test/classes/Config/ServerConfigChecksTest.php74
-rw-r--r--test/classes/Setup/ConfigGeneratorTest.php30
2 files changed, 92 insertions, 12 deletions
diff --git a/test/classes/Config/ServerConfigChecksTest.php b/test/classes/Config/ServerConfigChecksTest.php
index 9e64d14e60..2d26e221b5 100644
--- a/test/classes/Config/ServerConfigChecksTest.php
+++ b/test/classes/Config/ServerConfigChecksTest.php
@@ -11,6 +11,10 @@ use ReflectionException;
use ReflectionProperty;
use function array_keys;
+use function mb_strlen;
+use function str_repeat;
+
+use const SODIUM_CRYPTO_SECRETBOX_KEYBYTES;
/**
* @covers \PhpMyAdmin\Config\ServerConfigChecks
@@ -100,8 +104,10 @@ class ServerConfigChecksTest extends AbstractTestCase
);
}
- public function testBlowfishCreate(): void
+ public function testBlowfish(): void
{
+ $_SESSION[$this->sessionID] = [];
+ $_SESSION[$this->sessionID]['blowfish_secret'] = null;
$_SESSION[$this->sessionID]['Servers'] = [
'1' => [
'host' => 'localhost',
@@ -110,7 +116,6 @@ class ServerConfigChecksTest extends AbstractTestCase
'AllowRoot' => false,
],
];
-
$_SESSION[$this->sessionID]['AllowArbitraryServer'] = false;
$_SESSION[$this->sessionID]['LoginCookieValidity'] = -1;
$_SESSION[$this->sessionID]['LoginCookieStore'] = 0;
@@ -123,28 +128,73 @@ class ServerConfigChecksTest extends AbstractTestCase
$configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
$configChecker->performConfigChecks();
- $this->assertEquals(
- ['blowfish_secret_created'],
- array_keys($_SESSION['messages']['notice'])
- );
-
- $this->assertArrayNotHasKey('error', $_SESSION['messages']);
+ /**
+ * @var mixed $secret
+ * @psalm-suppress TypeDoesNotContainType
+ */
+ $secret = $_SESSION[$this->sessionID]['blowfish_secret'] ?? '';
+ $this->assertIsString($secret);
+ $this->assertSame(SODIUM_CRYPTO_SECRETBOX_KEYBYTES, mb_strlen($secret, '8bit'));
+ $messages = $_SESSION['messages'] ?? null;
+ $this->assertIsArray($messages);
+ $this->assertArrayHasKey('notice', $messages);
+ $this->assertIsArray($messages['notice']);
+ $this->assertArrayHasKey('blowfish_secret_created', $messages['notice']);
+ $this->assertArrayNotHasKey('error', $messages);
}
- public function testBlowfish(): void
+ public function testBlowfishWithInvalidSecret(): void
{
- $_SESSION[$this->sessionID]['blowfish_secret'] = 'sec';
-
+ $_SESSION[$this->sessionID] = [];
+ $_SESSION[$this->sessionID]['blowfish_secret'] = str_repeat('a', SODIUM_CRYPTO_SECRETBOX_KEYBYTES + 1);
$_SESSION[$this->sessionID]['Servers'] = [
'1' => [
'host' => 'localhost',
+ 'ssl' => true,
'auth_type' => 'cookie',
+ 'AllowRoot' => false,
],
];
$configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
$configChecker->performConfigChecks();
- $this->assertArrayHasKey('blowfish_warnings2', $_SESSION['messages']['error']);
+ /**
+ * @var mixed $secret
+ * @psalm-suppress TypeDoesNotContainType
+ */
+ $secret = $_SESSION[$this->sessionID]['blowfish_secret'] ?? '';
+ $this->assertIsString($secret);
+ $this->assertSame(SODIUM_CRYPTO_SECRETBOX_KEYBYTES, mb_strlen($secret, '8bit'));
+ $messages = $_SESSION['messages'] ?? null;
+ $this->assertIsArray($messages);
+ $this->assertArrayHasKey('notice', $messages);
+ $this->assertIsArray($messages['notice']);
+ $this->assertArrayHasKey('blowfish_secret_created', $messages['notice']);
+ $this->assertArrayNotHasKey('error', $messages);
+ }
+
+ public function testBlowfishWithValidSecret(): void
+ {
+ $_SESSION[$this->sessionID] = [];
+ $_SESSION[$this->sessionID]['blowfish_secret'] = str_repeat('a', SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
+ $_SESSION[$this->sessionID]['Servers'] = ['1' => ['host' => 'localhost', 'auth_type' => 'cookie']];
+
+ $configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
+ $configChecker->performConfigChecks();
+
+ /**
+ * @var mixed $secret
+ * @psalm-suppress TypeDoesNotContainType
+ */
+ $secret = $_SESSION[$this->sessionID]['blowfish_secret'] ?? '';
+ $this->assertIsString($secret);
+ $this->assertSame(SODIUM_CRYPTO_SECRETBOX_KEYBYTES, mb_strlen($secret, '8bit'));
+ $messages = $_SESSION['messages'] ?? null;
+ $this->assertIsArray($messages);
+ $this->assertArrayHasKey('notice', $messages);
+ $this->assertIsArray($messages['notice']);
+ $this->assertArrayNotHasKey('blowfish_secret_created', $messages['notice']);
+ $this->assertArrayNotHasKey('error', $messages);
}
}
diff --git a/test/classes/Setup/ConfigGeneratorTest.php b/test/classes/Setup/ConfigGeneratorTest.php
index 7aaaa10ec0..985feb404d 100644
--- a/test/classes/Setup/ConfigGeneratorTest.php
+++ b/test/classes/Setup/ConfigGeneratorTest.php
@@ -10,6 +10,13 @@ use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Version;
use ReflectionClass;
+use function explode;
+use function hex2bin;
+use function mb_strlen;
+use function str_repeat;
+
+use const SODIUM_CRYPTO_SECRETBOX_KEYBYTES;
+
/**
* @covers \PhpMyAdmin\Setup\ConfigGenerator
*/
@@ -115,6 +122,29 @@ class ConfigGeneratorTest extends AbstractTestCase
);
}
+ public function testGetVarExportForBlowfishSecret(): void
+ {
+ $reflection = new ReflectionClass(ConfigGenerator::class);
+ $method = $reflection->getMethod('getVarExport');
+ $method->setAccessible(true);
+
+ $this->assertEquals(
+ '$cfg[\'blowfish_secret\'] = \sodium_hex2bin(\''
+ . '6161616161616161616161616161616161616161616161616161616161616161\');' . "\n",
+ $method->invoke(null, 'blowfish_secret', str_repeat('a', SODIUM_CRYPTO_SECRETBOX_KEYBYTES), "\n")
+ );
+
+ /** @var string $actual */
+ $actual = $method->invoke(null, 'blowfish_secret', 'invalid secret', "\n");
+ $this->assertStringStartsWith('$cfg[\'blowfish_secret\'] = \sodium_hex2bin(\'', $actual);
+ $this->assertStringEndsWith('\');' . "\n", $actual);
+ $pieces = explode('\'', $actual);
+ $this->assertCount(5, $pieces);
+ $binaryString = hex2bin($pieces[3]);
+ $this->assertIsString($binaryString);
+ $this->assertSame(SODIUM_CRYPTO_SECRETBOX_KEYBYTES, mb_strlen($binaryString, '8bit'));
+ }
+
/**
* Test for ConfigGenerator::isZeroBasedArray
*/