Skip to content

Commit 85f862a

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
2 parents a47c076 + 2524e53 commit 85f862a

5 files changed

Lines changed: 69 additions & 26 deletions

File tree

phpstan-baseline.neon

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,11 +2940,6 @@ parameters:
29402940
count: 1
29412941
path: src/Controllers/Server/ImportController.php
29422942

2943-
-
2944-
message: "#^Cannot access offset \\(int\\|string\\) on mixed\\.$#"
2945-
count: 2
2946-
path: src/Controllers/Server/PrivilegesController.php
2947-
29482943
-
29492944
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
29502945
count: 5
@@ -2995,16 +2990,6 @@ parameters:
29952990
count: 2
29962991
path: src/Controllers/Server/PrivilegesController.php
29972992

2998-
-
2999-
message: "#^Parameter \\#2 \\$array of function implode expects array\\<string\\>, mixed given\\.$#"
3000-
count: 1
3001-
path: src/Controllers/Server/PrivilegesController.php
3002-
3003-
-
3004-
message: "#^Parameter \\#2 \\$array of function implode expects array\\|null, mixed given\\.$#"
3005-
count: 1
3006-
path: src/Controllers/Server/PrivilegesController.php
3007-
30082993
-
30092994
message: "#^Parameter \\#2 \\$hostname of method PhpMyAdmin\\\\Controllers\\\\Server\\\\PrivilegesController\\:\\:getExportPageTitle\\(\\) expects string, mixed given\\.$#"
30102995
count: 1
@@ -15701,7 +15686,7 @@ parameters:
1570115686
#^Call to deprecated method getInstance\\(\\) of class PhpMyAdmin\\\\Config\\:
1570215687
Use dependency injection instead\\.$#
1570315688
"""
15704-
count: 1
15689+
count: 2
1570515690
path: tests/unit/Controllers/Server/PrivilegesControllerTest.php
1570615691

1570715692
-

psalm-baseline.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,6 @@
24452445
<InvalidArrayOffset>
24462446
<code><![CDATA[$GLOBALS['dbname']]]></code>
24472447
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
2448-
<code><![CDATA[$GLOBALS['sql_query'][$key]]]></code>
24492448
</InvalidArrayOffset>
24502449
<MixedArgument>
24512450
<code><![CDATA[$dbName ?? '']]></code>
@@ -2461,12 +2460,6 @@
24612460
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
24622461
<code><![CDATA[$dbName]]></code>
24632462
</MixedAssignment>
2464-
<PossiblyInvalidArgument>
2465-
<code><![CDATA[$GLOBALS['sql_query']]]></code>
2466-
</PossiblyInvalidArgument>
2467-
<PossiblyUnusedReturnValue>
2468-
<code><![CDATA[Response]]></code>
2469-
</PossiblyUnusedReturnValue>
24702463
<RedundantConditionGivenDocblockType>
24712464
<code><![CDATA[! empty($GLOBALS['message']) && $GLOBALS['message'] instanceof Message]]></code>
24722465
</RedundantConditionGivenDocblockType>
@@ -12417,6 +12410,7 @@
1241712410
<file src="tests/unit/Controllers/Server/PrivilegesControllerTest.php">
1241812411
<DeprecatedMethod>
1241912412
<code><![CDATA[Config::getInstance()]]></code>
12413+
<code><![CDATA[Config::getInstance()]]></code>
1242012414
</DeprecatedMethod>
1242112415
</file>
1242212416
<file src="tests/unit/Controllers/Server/ShowEngineControllerTest.php">

src/Controllers/Server/PrivilegesController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ public function __invoke(ServerRequest $request): Response
188188
*/
189189
if ($request->hasBodyParam('update_privs')) {
190190
if (is_array($GLOBALS['dbname'])) {
191+
$statements = [];
191192
foreach ($GLOBALS['dbname'] as $key => $dbName) {
192-
[$GLOBALS['sql_query'][$key], $GLOBALS['message']] = $serverPrivileges->updatePrivileges(
193+
[$statements[$key], $GLOBALS['message']] = $serverPrivileges->updatePrivileges(
193194
$GLOBALS['username'] ?? '',
194195
$GLOBALS['hostname'] ?? '',
195196
$tablename ?? $routinename ?? '',
@@ -198,7 +199,7 @@ public function __invoke(ServerRequest $request): Response
198199
);
199200
}
200201

201-
$GLOBALS['sql_query'] = implode("\n", $GLOBALS['sql_query']);
202+
$GLOBALS['sql_query'] = implode("\n", $statements);
202203
} else {
203204
[$GLOBALS['sql_query'], $GLOBALS['message']] = $serverPrivileges->updatePrivileges(
204205
$GLOBALS['username'] ?? '',

src/Server/Privileges.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2241,7 +2241,6 @@ public function addUser(
22412241
];
22422242
}
22432243

2244-
$sqlQuery = '';
22452244
// Some reports were sent to the error reporting server with phpMyAdmin 5.1.0
22462245
// pred_username was reported to be not defined
22472246
$predUsername = $_POST['pred_username'] ?? '';

tests/unit/Controllers/Server/PrivilegesControllerTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpMyAdmin\Controllers\Server\PrivilegesController;
1010
use PhpMyAdmin\Current;
1111
use PhpMyAdmin\DatabaseInterface;
12+
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
1213
use PhpMyAdmin\Http\ServerRequest;
1314
use PhpMyAdmin\Template;
1415
use PhpMyAdmin\Tests\AbstractTestCase;
@@ -94,4 +95,67 @@ public function testPrivilegesController(): void
9495
$actual,
9596
);
9697
}
98+
99+
public function testUpdatePrivilegesForMultipleDatabases(): void
100+
{
101+
$config = Config::getInstance();
102+
$config->selectedServer['DisableIS'] = true;
103+
104+
$_REQUEST['username'] = $_POST['username'] = 'pma_test';
105+
$_REQUEST['hostname'] = $_POST['hostname'] = 'localhost';
106+
$_REQUEST['dbname'] = $_POST['dbname'] = ['test_db_1', 'test_db_2'];
107+
$_POST['Select_priv'] = 'Y';
108+
$_POST['grant_count'] = '18';
109+
$_POST['update_privs'] = '1';
110+
111+
$dbiDummy = $this->createDbiDummy();
112+
$dbiDummy->addSelectDb('mysql');
113+
// phpcs:disable Generic.Files.LineLength.TooLong
114+
$dbiDummy->addResult('SHOW GRANTS FOR CURRENT_USER();', [['GRANT ALL PRIVILEGES ON *.* TO `pma_test`@`localhost` WITH GRANT OPTION']], ['Grants for pma_test@localhost']);
115+
$dbiDummy->addResult('SHOW GRANTS FOR CURRENT_USER();', [['GRANT ALL PRIVILEGES ON *.* TO `pma_test`@`localhost` WITH GRANT OPTION']], ['Grants for pma_test@localhost']);
116+
$dbiDummy->addResult("REVOKE ALL PRIVILEGES ON `test_db_1`.* FROM 'pma_test'@'localhost';", []);
117+
$dbiDummy->addResult("REVOKE GRANT OPTION ON `test_db_1`.* FROM 'pma_test'@'localhost';", []);
118+
$dbiDummy->addResult("GRANT SELECT ON `test_db_1`.* TO 'pma_test'@'localhost';", []);
119+
$dbiDummy->addResult("REVOKE ALL PRIVILEGES ON `test_db_2`.* FROM 'pma_test'@'localhost';", []);
120+
$dbiDummy->addResult("REVOKE GRANT OPTION ON `test_db_2`.* FROM 'pma_test'@'localhost';", []);
121+
$dbiDummy->addResult("GRANT SELECT ON `test_db_2`.* TO 'pma_test'@'localhost';", []);
122+
$dbiDummy->addResult("SELECT '1' FROM `mysql`.`user` WHERE `User` = 'pma_test' AND `Host` = 'localhost';", [['1']]);
123+
$dbiDummy->addResult("SELECT * FROM `mysql`.`db` WHERE `User` = 'pma_test' AND `Host` = 'localhost' AND `Db` = 'test_db_1'", []);
124+
$dbiDummy->addResult('SHOW COLUMNS FROM `mysql`.`db`;', [['Host', 'char(255)', 'NO', 'PRI', '', ''], ['Db', 'char(64)', 'NO', 'PRI', '', ''], ['User', 'char(128)', 'NO', 'PRI', '', ''], ['Select_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Insert_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Update_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Delete_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Create_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Drop_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Grant_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['References_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Index_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Alter_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Create_tmp_table_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Lock_tables_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Create_view_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Show_view_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Create_routine_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Alter_routine_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Execute_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Event_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Trigger_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Delete_history_priv', "enum('N','Y')", 'NO', '', 'N', ''], ['Show_create_routine_priv', "enum('N','Y')", 'NO', '', 'N', '']], ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra']);
125+
// phpcs:enable
126+
127+
$dbi = $this->createDatabaseInterface($dbiDummy);
128+
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')->withParsedBody([
129+
'username' => 'pma_test',
130+
'hostname' => 'localhost',
131+
'dbname' => ['test_db_1', 'test_db_2'],
132+
'Select_priv' => 'Y',
133+
'grant_count' => '18',
134+
'update_privs' => '1',
135+
]);
136+
137+
$controller = new PrivilegesController(
138+
new ResponseRenderer(),
139+
new Template(),
140+
new Relation($dbi),
141+
$dbi,
142+
new UserPrivilegesFactory($dbi),
143+
$config,
144+
);
145+
$response = $controller($request);
146+
147+
$output = (string) $response->getBody();
148+
self::assertStringContainsString("You have updated the privileges for 'pma_test'@'localhost'.", $output);
149+
150+
// phpcs:disable Generic.Files.LineLength.TooLong
151+
$expectedSql = '<pre>' . "\n"
152+
. "REVOKE ALL PRIVILEGES ON `test_db_1`.* FROM 'pma_test'@'localhost'; REVOKE GRANT OPTION ON `test_db_1`.* FROM 'pma_test'@'localhost'; GRANT SELECT ON `test_db_1`.* TO 'pma_test'@'localhost'; \n"
153+
. "REVOKE ALL PRIVILEGES ON `test_db_2`.* FROM 'pma_test'@'localhost'; REVOKE GRANT OPTION ON `test_db_2`.* FROM 'pma_test'@'localhost'; GRANT SELECT ON `test_db_2`.* TO 'pma_test'@'localhost'; \n"
154+
. '</pre>';
155+
// phpcs:enable
156+
self::assertStringContainsString($expectedSql, $output);
157+
158+
$dbiDummy->assertAllSelectsConsumed();
159+
$dbiDummy->assertAllQueriesConsumed();
160+
}
97161
}

0 commit comments

Comments
 (0)