Merge pull request #16433 from mauriciofauth/dbi-is-user-type

Refactor DatabaseInterface::isUserType method
This commit is contained in:
Maurício Meneghini Fauth 2020-10-25 21:02:40 -03:00 committed by GitHub
commit 9c5f8d1def
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 184 additions and 161 deletions

View File

@ -16,7 +16,7 @@ final class Common
{
public static function server(): void
{
global $db, $table, $viewing_mode, $err_url, $is_grantuser, $is_createuser, $dbi;
global $db, $table, $viewing_mode, $err_url, $dbi;
/**
* Handles some variables that may have been sent by the calling script
@ -34,11 +34,8 @@ final class Common
*/
$err_url = Url::getFromRoute('/');
$is_grantuser = $dbi->isUserType('grant');
$is_createuser = $dbi->isUserType('create');
// now, select the mysql db
if (! $dbi->isSuperuser()) {
if (! $dbi->isSuperUser()) {
return;
}

View File

@ -303,7 +303,7 @@ class OperationsController extends AbstractController
$hasAdjustPrivileges = $GLOBALS['db_priv'] && $GLOBALS['table_priv']
&& $GLOBALS['col_priv'] && $GLOBALS['proc_priv'] && $GLOBALS['is_reload_priv'];
$isDropDatabaseAllowed = ($this->dbi->isSuperuser() || $cfg['AllowUserDropDatabase'])
$isDropDatabaseAllowed = ($this->dbi->isSuperUser() || $cfg['AllowUserDropDatabase'])
&& ! $db_is_system_schema && $db !== 'mysql';
$switchToNew = isset($_SESSION['pma_switch_to_new']) && $_SESSION['pma_switch_to_new'];

View File

@ -41,7 +41,7 @@ class PrivilegesController extends AbstractController
*/
public function index(array $params): string
{
global $cfg, $text_dir, $is_createuser, $is_grantuser, $PMA_Theme;
global $cfg, $text_dir, $PMA_Theme;
$scriptName = Util::getScriptNameForOption(
$cfg['DefaultTabDatabase'],
@ -49,18 +49,18 @@ class PrivilegesController extends AbstractController
);
$privileges = [];
if ($this->dbi->isSuperuser()) {
if ($this->dbi->isSuperUser()) {
$privileges = $this->privileges->getAllPrivileges($params['checkprivsdb']);
}
return $this->template->render('database/privileges/index', [
'is_superuser' => $this->dbi->isSuperuser(),
'is_superuser' => $this->dbi->isSuperUser(),
'db' => $params['checkprivsdb'],
'database_url' => $scriptName,
'theme_image_path' => $PMA_Theme->getImgPath(),
'text_dir' => $text_dir,
'is_createuser' => $is_createuser,
'is_grantuser' => $is_grantuser,
'is_createuser' => $this->dbi->isCreateUser(),
'is_grantuser' => $this->dbi->isGrantUser(),
'privileges' => $privileges,
]);
}

View File

@ -782,7 +782,7 @@ final class ImportController extends AbstractController
if ($this->sql->hasNoRightsToDropDatabase(
$analyzed_sql_results,
$cfg['AllowUserDropDatabase'],
$this->dbi->isSuperuser()
$this->dbi->isSuperUser()
)) {
Generator::mysqlDie(
__('"DROP DATABASE" statements are disabled.'),

View File

@ -176,7 +176,7 @@ class DatabasesController extends AbstractController
'max_db_list' => $cfg['MaxDbList'],
'has_master_replication' => $primaryInfo['status'],
'has_slave_replication' => $replicaInfo['status'],
'is_drop_allowed' => $this->dbi->isSuperuser() || $cfg['AllowUserDropDatabase'],
'is_drop_allowed' => $this->dbi->isSuperUser() || $cfg['AllowUserDropDatabase'],
'theme_image_path' => $PMA_Theme->getImgPath(),
'text_dir' => $text_dir,
]);
@ -277,7 +277,7 @@ class DatabasesController extends AbstractController
if (! isset($params['drop_selected_dbs'])
|| ! $this->response->isAjax()
|| (! $this->dbi->isSuperuser() && ! $cfg['AllowUserDropDatabase'])
|| (! $this->dbi->isSuperUser() && ! $cfg['AllowUserDropDatabase'])
) {
$message = Message::error();
$json = ['message' => $message];

View File

@ -91,7 +91,7 @@ class PrivilegesController extends AbstractController
$this->response->addHTML('<div class="container-fluid">');
$this->render('server/privileges/subnav', [
'active' => 'privileges',
'is_super_user' => $this->dbi->isSuperuser(),
'is_super_user' => $this->dbi->isSuperUser(),
]);
}
@ -125,9 +125,10 @@ class PrivilegesController extends AbstractController
/**
* Checks if the user is allowed to do what they try to...
*/
if (! $this->dbi->isSuperuser() && ! $GLOBALS['is_grantuser']
&& ! $GLOBALS['is_createuser']
) {
$isGrantUser = $this->dbi->isGrantUser();
$isCreateUser = $this->dbi->isCreateUser();
if (! $this->dbi->isSuperUser() && ! $isGrantUser && ! $isCreateUser) {
$this->render('server/sub_page_header', [
'type' => 'privileges',
'is_image' => false,
@ -139,7 +140,7 @@ class PrivilegesController extends AbstractController
return;
}
if (! $GLOBALS['is_grantuser'] && ! $GLOBALS['is_createuser']) {
if (! $isGrantUser && ! $isCreateUser) {
$this->response->addHTML(Message::notice(
__('You do not have the privileges to administrate the users!')
)->getDisplay());
@ -245,7 +246,7 @@ class PrivilegesController extends AbstractController
* Assign users to user groups
*/
if (! empty($_POST['changeUserGroup']) && $cfgRelation['menuswork']
&& $this->dbi->isSuperuser() && $GLOBALS['is_createuser']
&& $this->dbi->isSuperUser() && $this->dbi->isCreateUser()
) {
$serverPrivileges->setUserGroup($username, $_POST['userGroup']);
$message = Message::success();

View File

@ -63,7 +63,7 @@ class ReplicationController extends AbstractController
$url_params = $params['url_params'];
}
if ($this->dbi->isSuperuser()) {
if ($this->dbi->isSuperUser()) {
$this->replicationGui->handleControlRequest();
}
@ -89,7 +89,7 @@ class ReplicationController extends AbstractController
$this->render('server/replication/index', [
'url_params' => $url_params,
'is_super_user' => $this->dbi->isSuperuser(),
'is_super_user' => $this->dbi->isSuperUser(),
'error_messages' => $errorMessages,
'is_master' => $primaryInfo['status'],
'master_configure' => $params['mr_configure'],

View File

@ -60,7 +60,7 @@ class MonitorController extends AbstractController
$form = [
'server_time' => (int) (microtime(true) * 1000),
'server_os' => SysInfo::getOs(),
'is_superuser' => $this->dbi->isSuperuser(),
'is_superuser' => $this->dbi->isSuperUser(),
'server_db_isLocal' => $this->data->dbIsLocal,
];

View File

@ -46,7 +46,7 @@ class UserGroupsController extends AbstractController
/**
* Only allowed to superuser
*/
if (! $this->dbi->isSuperuser()) {
if (! $this->dbi->isSuperUser()) {
$this->response->addHTML(
Message::error(__('No Privileges'))->getDisplay()
);
@ -57,7 +57,7 @@ class UserGroupsController extends AbstractController
$this->response->addHTML('<div class="container-fluid">');
$this->render('server/privileges/subnav', [
'active' => 'user-groups',
'is_super_user' => $this->dbi->isSuperuser(),
'is_super_user' => $this->dbi->isSuperUser(),
]);
/**

View File

@ -99,7 +99,7 @@ class VariablesController extends AbstractController
$this->render('server/variables/index', [
'variables' => $variables,
'filter_value' => $filterValue,
'is_superuser' => $this->dbi->isSuperuser(),
'is_superuser' => $this->dbi->isSuperUser(),
'is_mariadb' => $this->dbi->isMariaDB(),
]);
}

View File

@ -163,7 +163,7 @@ class SqlController extends AbstractController
if ($this->sql->hasNoRightsToDropDatabase(
$analyzed_sql_results,
$cfg['AllowUserDropDatabase'],
$this->dbi->isSuperuser()
$this->dbi->isSuperUser()
)) {
Generator::mysqlDie(
__('"DROP DATABASE" statements are disabled.'),

View File

@ -42,7 +42,7 @@ class PrivilegesController extends AbstractController
*/
public function index(array $params): string
{
global $cfg, $text_dir, $is_createuser, $is_grantuser, $PMA_Theme;
global $cfg, $text_dir, $PMA_Theme;
$scriptName = Util::getScriptNameForOption(
$cfg['DefaultTabTable'],
@ -50,7 +50,7 @@ class PrivilegesController extends AbstractController
);
$privileges = [];
if ($this->dbi->isSuperuser()) {
if ($this->dbi->isSuperUser()) {
$privileges = $this->privileges->getAllPrivileges(
$params['checkprivsdb'],
$params['checkprivstable']
@ -60,12 +60,12 @@ class PrivilegesController extends AbstractController
return $this->template->render('table/privileges/index', [
'db' => $params['checkprivsdb'],
'table' => $params['checkprivstable'],
'is_superuser' => $this->dbi->isSuperuser(),
'is_superuser' => $this->dbi->isSuperUser(),
'table_url' => $scriptName,
'theme_image_path' => $PMA_Theme->getImgPath(),
'text_dir' => $text_dir,
'is_createuser' => $is_createuser,
'is_grantuser' => $is_grantuser,
'is_createuser' => $this->dbi->isCreateUser(),
'is_grantuser' => $this->dbi->isGrantUser(),
'privileges' => $privileges,
]);
}

View File

@ -1783,7 +1783,7 @@ class Routines
// Since editing a procedure involved dropping and recreating, check also for
// CREATE ROUTINE privilege to avoid lost procedures.
$hasEditPrivilege = (Util::currentUserHasPrivilege('CREATE ROUTINE', $db)
&& $currentUser == $routineDefiner) || $this->dbi->isSuperuser();
&& $currentUser == $routineDefiner) || $this->dbi->isSuperUser();
// There is a problem with Util::currentUserHasPrivilege():
// it does not detect all kinds of privileges, for example
@ -1829,7 +1829,7 @@ class Routines
}
$hasExportPrivilege = (Util::currentUserHasPrivilege('CREATE ROUTINE', $db)
&& $currentUser == $routineDefiner) || $this->dbi->isSuperuser();
&& $currentUser == $routineDefiner) || $this->dbi->isSuperUser();
return $this->template->render('database/routines/row', [
'db' => $db,

View File

@ -1748,96 +1748,135 @@ class DatabaseInterface implements DbalInterface
return '@';
}
/**
* Checks if current user is superuser
*
* @return bool Whether user is a superuser
*/
public function isSuperuser(): bool
public function isSuperUser(): bool
{
return $this->isUserType('super');
}
/**
* Checks if current user has global create user/grant privilege
* or is a superuser (i.e. SELECT on mysql.users)
* while caching the result in session.
*
* @param string $type type of user to check for
* i.e. 'create', 'grant', 'super'
*
* @return bool Whether user is a given type of user
*/
public function isUserType(string $type): bool
{
if (Util::cacheExists('is_' . $type . 'user')) {
return Util::cacheGet('is_' . $type . 'user');
if (Util::cacheExists('is_superuser')) {
return Util::cacheGet('is_superuser');
}
// when connection failed we don't have a $userlink
if (! isset($this->links[self::CONNECT_USER])) {
if (! $this->isConnected()) {
return false;
}
// checking if user is logged in
if ($type === 'logged') {
return true;
$result = $this->tryQuery(
'SELECT 1 FROM mysql.user LIMIT 1',
self::CONNECT_USER,
self::QUERY_STORE
);
$isSuperUser = false;
if ($result) {
$isSuperUser = (bool) $this->numRows($result);
}
if (! $GLOBALS['cfg']['Server']['DisableIS'] || $type === 'super') {
// Prepare query for each user type check
$query = '';
if ($type === 'super') {
$query = 'SELECT 1 FROM mysql.user LIMIT 1';
} elseif ($type === 'create') {
[$user, $host] = $this->getCurrentUserAndHost();
$query = QueryGenerator::getInformationSchemaDataForCreateRequest($user, $host);
} elseif ($type === 'grant') {
[$user, $host] = $this->getCurrentUserAndHost();
$query = QueryGenerator::getInformationSchemaDataForGranteeRequest($user, $host);
}
$this->freeResult($result);
Util::cacheSet('is_superuser', $isSuperUser);
$is = false;
$result = $this->tryQuery(
$query,
self::CONNECT_USER,
self::QUERY_STORE
);
if ($result) {
$is = (bool) $this->numRows($result);
}
$this->freeResult($result);
} else {
$is = false;
$grants = $this->fetchResult(
'SHOW GRANTS FOR CURRENT_USER();',
null,
null,
self::CONNECT_USER,
self::QUERY_STORE
);
if ($grants) {
foreach ($grants as $grant) {
if ($type === 'create') {
if (strpos($grant, 'ALL PRIVILEGES ON *.*') !== false
|| strpos($grant, 'CREATE USER') !== false
) {
$is = true;
break;
}
} elseif ($type === 'grant') {
if (strpos($grant, 'WITH GRANT OPTION') !== false) {
$is = true;
break;
}
}
return $isSuperUser;
}
public function isGrantUser(): bool
{
global $cfg;
if (Util::cacheExists('is_grantuser')) {
return Util::cacheGet('is_grantuser');
}
if (! $this->isConnected()) {
return false;
}
$hasGrantPrivilege = false;
if ($cfg['Server']['DisableIS']) {
$grants = $this->getCurrentUserGrants();
foreach ($grants as $grant) {
if (strpos($grant, 'WITH GRANT OPTION') !== false) {
$hasGrantPrivilege = true;
break;
}
}
Util::cacheSet('is_grantuser', $hasGrantPrivilege);
return $hasGrantPrivilege;
}
Util::cacheSet('is_' . $type . 'user', $is);
[$user, $host] = $this->getCurrentUserAndHost();
$query = QueryGenerator::getInformationSchemaDataForGranteeRequest($user, $host);
$result = $this->tryQuery($query, self::CONNECT_USER, self::QUERY_STORE);
return $is;
if ($result) {
$hasGrantPrivilege = (bool) $this->numRows($result);
}
$this->freeResult($result);
Util::cacheSet('is_grantuser', $hasGrantPrivilege);
return $hasGrantPrivilege;
}
public function isCreateUser(): bool
{
global $cfg;
if (Util::cacheExists('is_createuser')) {
return Util::cacheGet('is_createuser');
}
if (! $this->isConnected()) {
return false;
}
$hasCreatePrivilege = false;
if ($cfg['Server']['DisableIS']) {
$grants = $this->getCurrentUserGrants();
foreach ($grants as $grant) {
if (strpos($grant, 'ALL PRIVILEGES ON *.*') !== false
|| strpos($grant, 'CREATE USER') !== false
) {
$hasCreatePrivilege = true;
break;
}
}
Util::cacheSet('is_createuser', $hasCreatePrivilege);
return $hasCreatePrivilege;
}
[$user, $host] = $this->getCurrentUserAndHost();
$query = QueryGenerator::getInformationSchemaDataForCreateRequest($user, $host);
$result = $this->tryQuery($query, self::CONNECT_USER, self::QUERY_STORE);
if ($result) {
$hasCreatePrivilege = (bool) $this->numRows($result);
}
$this->freeResult($result);
Util::cacheSet('is_createuser', $hasCreatePrivilege);
return $hasCreatePrivilege;
}
public function isConnected(): bool
{
return isset($this->links[self::CONNECT_USER]);
}
private function getCurrentUserGrants(): array
{
return $this->fetchResult(
'SHOW GRANTS FOR CURRENT_USER();',
null,
null,
self::CONNECT_USER,
self::QUERY_STORE
);
}
/**

View File

@ -493,19 +493,13 @@ interface DbalInterface
*
* @return bool Whether user is a superuser
*/
public function isSuperuser(): bool;
public function isSuperUser(): bool;
/**
* Checks if current user has global create user/grant privilege
* or is a superuser (i.e. SELECT on mysql.users)
* while caching the result in session.
*
* @param string $type type of user to check for
* i.e. 'create', 'grant', 'super'
*
* @return bool Whether user is a given type of user
*/
public function isUserType(string $type): bool;
public function isGrantUser(): bool;
public function isCreateUser(): bool;
public function isConnected(): bool;
/**
* Get the current user and host

View File

@ -259,7 +259,7 @@ class Footer
|| ! empty($GLOBALS['error_message'])
|| empty($GLOBALS['sql_query'])
|| ! isset($dbi)
|| ! $dbi->isUserType('logged')
|| ! $dbi->isConnected()
) {
return;
}

View File

@ -248,7 +248,7 @@ class Header
'confirm' => $GLOBALS['cfg']['Confirm'],
'LoginCookieValidity' => $GLOBALS['cfg']['LoginCookieValidity'],
'session_gc_maxlifetime' => (int) ini_get('session.gc_maxlifetime'),
'logged_in' => isset($dbi) ? $dbi->isUserType('logged') : false,
'logged_in' => isset($dbi) ? $dbi->isConnected() : false,
'is_https' => $GLOBALS['PMA_Config']->isHttps(),
'rootPath' => $GLOBALS['PMA_Config']->getRootPath(),
'arg_separator' => Url::getArgSeparator(),

View File

@ -262,9 +262,8 @@ class Menu
$updatable_view = $dbi->getTable($this->db, $this->table)
->isUpdatableView();
}
$is_superuser = $dbi->isSuperuser();
$isCreateOrGrantUser = $dbi->isUserType('grant')
|| $dbi->isUserType('create');
$is_superuser = $dbi->isSuperUser();
$isCreateOrGrantUser = $dbi->isGrantUser() || $dbi->isCreateUser();
$tabs = [];
@ -384,9 +383,8 @@ class Menu
$db_is_system_schema = Utilities::isSystemSchema($this->db);
$num_tables = count($dbi->getTables($this->db));
$is_superuser = $dbi->isSuperuser();
$isCreateOrGrantUser = $dbi->isUserType('grant')
|| $dbi->isUserType('create');
$is_superuser = $dbi->isSuperUser();
$isCreateOrGrantUser = $dbi->isGrantUser() || $dbi->isCreateUser();
/**
* Gets the relation settings
@ -506,9 +504,8 @@ class Menu
/** @var DatabaseInterface $dbi */
global $route, $dbi;
$is_superuser = $dbi->isSuperuser();
$isCreateOrGrantUser = $dbi->isUserType('grant')
|| $dbi->isUserType('create');
$is_superuser = $dbi->isSuperUser();
$isCreateOrGrantUser = $dbi->isGrantUser() || $dbi->isCreateUser();
if (Util::cacheExists('binary_logs')) {
$binary_logs = Util::cacheGet('binary_logs');
} else {

View File

@ -653,7 +653,7 @@ class Privileges
$row = $this->dbi->fetchSingleRow($sql_query);
}
if (empty($row)) {
if ($table === '*' && $this->dbi->isSuperuser()) {
if ($table === '*' && $this->dbi->isSuperUser()) {
$row = [];
if ($db === '*') {
$sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
@ -1068,7 +1068,7 @@ class Privileges
. $this->dbi->escapeString($_POST['pma_pw']) . "')";
} elseif ($serverType === 'MariaDB'
&& $serverVersion >= 50200
&& $this->dbi->isSuperuser()
&& $this->dbi->isSuperUser()
) {
// Use 'UPDATE `mysql`.`user` ...' Syntax for MariaDB 5.2+
if ($authentication_plugin === 'mysql_native_password') {
@ -1308,18 +1308,17 @@ class Privileges
*/
public function getHtmlForAddUser($dbname)
{
global $is_grantuser;
$isGrantUser = $this->dbi->isGrantUser();
$loginInformationFieldsNew = $this->getHtmlForLoginInformationFields('new');
$privilegesTable = '';
if ($is_grantuser) {
if ($isGrantUser) {
$privilegesTable = $this->getHtmlToDisplayPrivilegesTable('*', '*', false);
}
return $this->template->render('server/privileges/add_user', [
'database' => $dbname,
'login_information_fields_new' => $loginInformationFieldsNew,
'is_grant_user' => $is_grantuser,
'is_grant_user' => $isGrantUser,
'privileges_table' => $privilegesTable,
]);
}
@ -1695,8 +1694,6 @@ class Privileges
$hostname,
$username
) {
global $is_grantuser;
if (isset($GLOBALS['dbname'])) {
//if (preg_match('/\\\\(?:_|%)/i', $dbname)) {
if (preg_match('/(?<!\\\\)(?:_|%)/', $GLOBALS['dbname'])) {
@ -1729,7 +1726,7 @@ class Privileges
];
$extra_data['new_user_string'] = $this->template->render('server/privileges/new_user_ajax', [
'user' => $user,
'is_grantuser' => $is_grantuser,
'is_grantuser' => $this->dbi->isGrantUser(),
'initial' => $_GET['initial'] ?? '',
]);
@ -2014,7 +2011,7 @@ class Privileges
$onePrivilege['name'] = $name;
$onePrivilege['edit_link'] = '';
if ($GLOBALS['is_grantuser']) {
if ($this->dbi->isGrantUser()) {
$onePrivilege['edit_link'] = $this->getUserLink(
'edit',
$username,
@ -2124,8 +2121,6 @@ class Privileges
*/
public function getUsersOverview($result, array $db_rights, $themeImagePath, $text_dir)
{
global $is_grantuser, $is_createuser;
$cfgRelation = $this->relation->getRelationsParam();
while ($row = $this->dbi->fetchAssoc($result)) {
@ -2187,8 +2182,8 @@ class Privileges
'text_dir' => $text_dir,
'initial' => $_GET['initial'] ?? '',
'hosts' => $hosts,
'is_grantuser' => $is_grantuser,
'is_createuser' => $is_createuser,
'is_grantuser' => $this->dbi->isGrantUser(),
'is_createuser' => $this->dbi->isCreateUser(),
]);
}
@ -3016,7 +3011,7 @@ class Privileges
*/
public function getAddUserHtmlFieldset($db = '', $table = '')
{
if (! $GLOBALS['is_createuser']) {
if (! $this->dbi->isCreateUser()) {
return '';
}
$rel_params = [];
@ -3048,8 +3043,6 @@ class Privileges
*/
public function getHtmlForUserOverview($themeImagePath, $text_dir)
{
global $is_createuser;
$password_column = 'Password';
$server_type = Util::getServerType();
$serverVersion = $this->dbi->getVersion();
@ -3208,7 +3201,7 @@ class Privileges
'empty_user_notice' => $emptyUserNotice ?? '',
'initials' => $initials ?? '',
'users_overview' => $usersOverview ?? '',
'is_createuser' => $is_createuser,
'is_createuser' => $this->dbi->isCreateUser(),
'flush_notice' => $flushNotice ?? '',
]);
}
@ -3858,7 +3851,7 @@ class Privileges
$real_sql_query .= ';';
$sql_query .= ';';
// No Global GRANT_OPTION privilege
if (! $GLOBALS['is_grantuser']) {
if (! $this->dbi->isGrantUser()) {
$real_sql_query = '';
$sql_query = '';
}
@ -3958,7 +3951,7 @@ class Privileges
$isNew = ($serverType === 'MySQL' && $serverVersion >= 50507)
|| ($serverType === 'MariaDB' && $serverVersion >= 50200);
$hasMoreAuthPlugins = ($serverType === 'MySQL' && $serverVersion >= 50706)
|| ($this->dbi->isSuperuser() && $editOthers);
|| ($this->dbi->isSuperUser() && $editOthers);
$activeAuthPlugins = ['mysql_native_password' => __('Native MySQL authentication')];

View File

@ -27,14 +27,12 @@ class PrivilegesControllerTest extends AbstractTestCase
public function testIndex(): void
{
global $dbi, $db, $server, $cfg, $PMA_PHP_SELF, $is_grantuser, $is_createuser;
global $dbi, $db, $server, $cfg, $PMA_PHP_SELF;
$db = 'db';
$server = 0;
$cfg['Server']['DisableIS'] = false;
$PMA_PHP_SELF = 'index.php';
$is_grantuser = true;
$is_createuser = true;
$privileges = [];

View File

@ -27,15 +27,13 @@ class PrivilegesControllerTest extends AbstractTestCase
public function testIndex(): void
{
global $dbi, $db, $table, $server, $cfg, $PMA_PHP_SELF, $is_grantuser, $is_createuser;
global $dbi, $db, $table, $server, $cfg, $PMA_PHP_SELF;
$db = 'db';
$table = 'table';
$server = 0;
$cfg['Server']['DisableIS'] = false;
$PMA_PHP_SELF = 'index.php';
$is_grantuser = true;
$is_createuser = true;
$privileges = [];

View File

@ -36,6 +36,7 @@ class PrivilegesTest extends AbstractTestCase
protected function setUp(): void
{
parent::setUp();
parent::defineVersionConstants();
parent::setLanguage();
parent::setGlobalConfig();
parent::setTheme();
@ -111,11 +112,14 @@ class PrivilegesTest extends AbstractTestCase
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$dbi->expects($this->any())->method('isCreateUser')
->will($this->returnValue(true));
$dbi->expects($this->any())->method('isGrantUser')
->will($this->returnValue(true));
$GLOBALS['dbi'] = $dbi;
$this->serverPrivileges->dbi = $dbi;
$this->serverPrivileges->relation->dbi = $dbi;
$GLOBALS['is_grantuser'] = true;
$GLOBALS['is_createuser'] = true;
$GLOBALS['is_reload_priv'] = true;
}
@ -1290,6 +1294,8 @@ class PrivilegesTest extends AbstractTestCase
$dbi->expects($this->any())
->method('escapeString')
->will($this->returnArgument(0));
$dbi->expects($this->any())->method('isGrantUser')
->will($this->returnValue(true));
$GLOBALS['dbi'] = $dbi;
$this->serverPrivileges->dbi = $dbi;