Merge pull request #7600 from JakubOnderka/fix-tests

fix: [test] After CLI setSetting change
pull/7589/head
Jakub Onderka 2021-07-26 13:22:28 +02:00 committed by GitHub
commit 9f773d7134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 10 deletions

View File

@ -146,7 +146,7 @@ jobs:
sudo -E su $USER -c 'app/Console/cake Admin setSetting "MISP.host_org_id" 1'
sudo -E su $USER -c 'app/Console/cake Admin setSetting "MISP.email" "info@admin.test"'
sudo -E su $USER -c 'app/Console/cake Admin setSetting "MISP.disable_emailing" false'
sudo -E su $USER -c 'app/Console/cake Admin setSetting "debug" true'
sudo -E su $USER -c 'app/Console/cake Admin setSetting --force "debug" true'
sudo -E su $USER -c 'app/Console/cake Admin setSetting "Plugin.CustomAuth_disable_logout" false'
sudo -E su $USER -c 'app/Console/cake Admin setSetting "MISP.redis_host" "127.0.0.1"'
sudo -E su $USER -c 'app/Console/cake Admin setSetting "MISP.redis_port" 6379'

View File

@ -1,5 +1,9 @@
<?php
App::uses('AppShell', 'Console/Command');
/**
* @property Server $Server
*/
class AdminShell extends AppShell
{
public $uses = array('Event', 'Post', 'Attribute', 'Job', 'User', 'Task', 'Allowedlist', 'Server', 'Organisation', 'AdminSetting', 'Galaxy', 'Taxonomy', 'Warninglist', 'Noticelist', 'ObjectTemplate', 'Bruteforce', 'Role', 'Feed');
@ -335,24 +339,26 @@ class AdminShell extends AppShell
$this->ConfigLoad->execute();
$setting_name = !isset($this->args[0]) ? null : $this->args[0];
$value = !isset($this->args[1]) ? null : $this->args[1];
if ($value === 'false') $value = 0;
if ($value === 'true') $value = 1;
if ($value === 'false') {
$value = 0;
} elseif ($value === 'true') {
$value = 1;
}
$cli_user = array('id' => 0, 'email' => 'SYSTEM', 'Organisation' => array('name' => 'SYSTEM'));
if (empty($setting_name) || $value === null) {
echo 'Invalid parameters. Usage: ' . APP . 'Console/cake Admin setSetting [setting_name] [setting_value]' . PHP_EOL;
} else {
$setting = $this->Server->getSettingData($setting_name);
if (empty($setting)) {
echo 'Invalid setting "' . $setting_name . '". Please make sure that the setting that you are attempting to change exists and if a module parameter, the modules are running.' . PHP_EOL;
exit(1);
$message = 'Invalid setting "' . $setting_name . '". Please make sure that the setting that you are attempting to change exists and if a module parameter, the modules are running.' . PHP_EOL;
$this->error(__('Setting change rejected.'), $message);
}
$result = $this->Server->serverSettingsEditValue($cli_user, $setting, $value, $this->params['force']);
if ($result === true) {
echo 'Setting "' . $setting_name . '" changed to ' . $value . PHP_EOL;
} else {
$message = __("The setting change was rejected. MISP considers the requested setting value as invalid and would lead to the following error:\n\n\"%s\"\n\nIf you still want to force this change, please supply the --force argument.\n", $result);
Shell::error(__('Setting change rejected.'), $message);
die();
$this->error(__('Setting change rejected.'), $message);
}
}
echo PHP_EOL;

View File

@ -2241,6 +2241,12 @@ class Server extends AppModel
}
}
/**
* @param string $setting
* @param mixed $value
* @return bool
* @throws Exception
*/
public function serverSettingsSaveValue($setting, $value)
{
// validate if current config.php is intact:
@ -2310,7 +2316,10 @@ class Server extends AppModel
if (empty(Configure::read('MISP.server_settings_skip_backup_rotate'))) {
$randomFilename = $this->generateRandomFileName();
// To protect us from 2 admin users having a concurrent file write to the config file, solar flares and the bogeyman
file_put_contents(APP . 'Config' . DS . $randomFilename, $settingsString);
if (file_put_contents(APP . 'Config' . DS . $randomFilename, $settingsString) === false) {
$this->loadLog()->createLogEntry('SYSTEM', 'error', 'Server', 0, 'Error: Could not create temp config file.');
return false;
}
rename(APP . 'Config' . DS . $randomFilename, APP . 'Config' . DS . 'config.php');
chmod(APP . 'Config' . DS . 'config.php', octdec($previous_file_perm));
$config_saved = file_get_contents(APP . 'Config' . DS . 'config.php');
@ -2327,7 +2336,7 @@ class Server extends AppModel
'action' => 'error',
'user_id' => 0,
'title' => 'Error: Something went wrong saving the config file, reverted to backup file.',
));
));
return false;
}
} else {
@ -6565,7 +6574,6 @@ class Server extends AppModel
'description' => __('The password, if set for Redis.'),
'value' => '',
'errorMessage' => '',
'test' => 'testForEmpty',
'type' => 'string',
'afterHook' => 'zmqAfterHook',
),