mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
Merge branch 'wip_MDL-41593_m28_preventexecdefault' of https://github.com/skodak/moodle
This commit is contained in:
commit
a6396272f8
@ -2441,14 +2441,23 @@ class admin_setting_configfile extends admin_setting_configtext {
|
||||
'<div class="form-file defaultsnext"><input type="text" size="'.$this->size.'" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="'.s($data).'" />'.$executable.'</div>',
|
||||
$this->description, true, '', $default, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if execpatch has been disabled in config.php
|
||||
* Checks if execpatch has been disabled in config.php
|
||||
*/
|
||||
public function write_setting($data) {
|
||||
global $CFG;
|
||||
if (!empty($CFG->preventexecpath)) {
|
||||
if ($this->get_setting() === null) {
|
||||
// Use default during installation.
|
||||
$data = $this->get_defaultsetting();
|
||||
if ($data === null) {
|
||||
$data = '';
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
return parent::write_setting($data);
|
||||
}
|
||||
}
|
||||
|
@ -245,4 +245,57 @@ class core_admintree_testcase extends advanced_testcase {
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function test_preventexecpath() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
set_config('preventexecpath', 0);
|
||||
set_config('execpath', null, 'abc_cde');
|
||||
$this->assertFalse(get_config('abc_cde', 'execpath'));
|
||||
$setting = new admin_setting_configexecutable('abc_cde/execpath', 'some desc', '', '/xx/yy');
|
||||
$setting->write_setting('/oo/pp');
|
||||
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));
|
||||
|
||||
// Prevent changes.
|
||||
set_config('preventexecpath', 1);
|
||||
$setting->write_setting('/mm/nn');
|
||||
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));
|
||||
|
||||
// Use default in install.
|
||||
set_config('execpath', null, 'abc_cde');
|
||||
$setting->write_setting('/mm/nn');
|
||||
$this->assertSame('/xx/yy', get_config('abc_cde', 'execpath'));
|
||||
|
||||
// Use empty value if no default.
|
||||
$setting = new admin_setting_configexecutable('abc_cde/execpath', 'some desc', '', null);
|
||||
set_config('execpath', null, 'abc_cde');
|
||||
$setting->write_setting('/mm/nn');
|
||||
$this->assertSame('', get_config('abc_cde', 'execpath'));
|
||||
|
||||
// This also (most probably incorrectly) affects admin_setting_configfile.
|
||||
|
||||
set_config('preventexecpath', 0);
|
||||
set_config('execpath', null, 'abc_cde');
|
||||
$this->assertFalse(get_config('abc_cde', 'execpath'));
|
||||
$setting = new admin_setting_configfile('abc_cde/execpath', 'some desc', '', '/xx/yy');
|
||||
$setting->write_setting('/oo/pp');
|
||||
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));
|
||||
|
||||
// Prevent changes.
|
||||
set_config('preventexecpath', 1);
|
||||
$setting->write_setting('/mm/nn');
|
||||
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));
|
||||
|
||||
// Use default in install.
|
||||
set_config('execpath', null, 'abc_cde');
|
||||
$setting->write_setting('/mm/nn');
|
||||
$this->assertSame('/xx/yy', get_config('abc_cde', 'execpath'));
|
||||
|
||||
// Use empty value if no default.
|
||||
$setting = new admin_setting_configfile('abc_cde/execpath', 'some desc', '', null);
|
||||
set_config('execpath', null, 'abc_cde');
|
||||
$setting->write_setting('/mm/nn');
|
||||
$this->assertSame('', get_config('abc_cde', 'execpath'));
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user