Fix Error When adding a user on MariaDB (#19002)

* Fix Error When adding a user on MariaDB

Signed-off-by: Robert Johnson Nallori <johnson361@gmail.com>

* Fix coding standard and static analysis issues

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>

* Add unit tests

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>


Fixes #18989
---------

Signed-off-by: Robert Johnson Nallori <johnson361@gmail.com>
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Co-authored-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Robert Johnson Nallori 2024-02-23 21:49:37 +05:30 committed by GitHub
parent cc56e4c81a
commit 54f14eaa6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 63 additions and 8 deletions

View File

@ -13182,7 +13182,7 @@ parameters:
-
message: "#^Parameter \\#1 \\$str of method PhpMyAdmin\\\\DatabaseInterface\\:\\:quoteString\\(\\) expects string, mixed given\\.$#"
count: 4
count: 5
path: src/Server/Privileges.php
-
@ -13235,11 +13235,6 @@ parameters:
count: 2
path: src/Server/Privileges.php
-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
count: 1
path: src/Server/Privileges.php
-
message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, mixed given\\.$#"
count: 2

View File

@ -10350,6 +10350,7 @@
<code><![CDATA[$_REQUEST['hostname']]]></code>
<code><![CDATA[$_REQUEST['username']]]></code>
<code>$dbname[0]</code>
<code>$hashedPassword</code>
<code>$oldUserGroup</code>
</PossiblyInvalidCast>
<PossiblyInvalidOperand>

View File

@ -3111,7 +3111,7 @@ class Privileges
$hashedPassword = $_POST['pma_pw'];
}
$createUserReal = sprintf($createUserStmt, $hashedPassword);
$createUserReal = sprintf($createUserStmt, $this->dbi->quoteString($hashedPassword));
}
$createUserShow = sprintf($createUserStmt, '\'***\'');
@ -3123,7 +3123,12 @@ class Privileges
$passwordSetReal = sprintf($passwordSetStmt, $slashedUsername, $slashedHostname, "''");
} else {
$hashedPassword = $this->getHashedPassword($_POST['pma_pw']);
$passwordSetReal = sprintf($passwordSetStmt, $slashedUsername, $slashedHostname, $hashedPassword);
$passwordSetReal = sprintf(
$passwordSetStmt,
$slashedUsername,
$slashedHostname,
$this->dbi->quoteString($hashedPassword),
);
}
$alterRealSqlQuery = '';

View File

@ -707,6 +707,60 @@ class PrivilegesTest extends AbstractTestCase
self::assertSame('CREATE USER \'PMA_username\'@\'PMA_hostname\' IDENTIFIED BY \'***\';', $createUserShow);
}
public function testGetSqlQueriesForDisplayAndAddUserMySql50500AndUserDefinedPassword(): void
{
$dbiDummy = $this->createDbiDummy();
$dbi = $this->createDatabaseInterface($dbiDummy);
$dbi->setVersion(['@@version' => '5.5.0']);
$dbiDummy->addResult('SELECT PASSWORD(\'pma_password\');', [['*ABCDEF']], ['PASSWORD(\'pma_password\')']);
$serverPrivileges = $this->getPrivileges($dbi);
$username = 'PMA_username';
$hostname = 'PMA_hostname';
$password = 'pma_password';
$_POST['pred_password'] = 'userdefined';
$_POST['pma_pw'] = 'pma_password';
[, , , , $passwordSetReal, $passwordSetShow] = $serverPrivileges->getSqlQueriesForDisplayAndAddUser(
$username,
$hostname,
$password,
);
self::assertSame('SET PASSWORD FOR \'PMA_username\'@\'PMA_hostname\' = \'*ABCDEF\';', $passwordSetReal);
self::assertSame('SET PASSWORD FOR \'PMA_username\'@\'PMA_hostname\' = \'***\';', $passwordSetShow);
$dbiDummy->assertAllQueriesConsumed();
}
public function testGetSqlQueriesForDisplayAndAddUserWithUserDefinedPassword(): void
{
$dbi = $this->createDatabaseInterface();
$dbi->setVersion(['@@version' => '10.4.3-MariaDB']);
$serverPrivileges = $this->getPrivileges($dbi);
$username = 'PMA_username';
$hostname = 'PMA_hostname';
$password = 'pma_password';
$_POST['pred_password'] = 'userdefined';
$_POST['pma_pw'] = 'pma_password';
[$createUserReal, $createUserShow] = $serverPrivileges->getSqlQueriesForDisplayAndAddUser(
$username,
$hostname,
$password,
);
self::assertSame(
'CREATE USER \'PMA_username\'@\'PMA_hostname\' IDENTIFIED BY \'pma_password\';',
$createUserReal,
);
self::assertSame('CREATE USER \'PMA_username\'@\'PMA_hostname\' IDENTIFIED BY \'***\';', $createUserShow);
}
public function testGetSqlQueriesForDisplayAndAddUser(): void
{
Config::getInstance()->selectedServer['DisableIS'] = false;