mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-45221 admin: configexecutable admin settings should only accept files
This commit is contained in:
parent
4f214c3b64
commit
29fe6d8155
3 changed files with 31 additions and 1 deletions
|
@ -2352,7 +2352,7 @@ class admin_setting_configexecutable extends admin_setting_configfile {
|
|||
$default = $this->get_defaultsetting();
|
||||
|
||||
if ($data) {
|
||||
if (file_exists($data) and is_executable($data)) {
|
||||
if (file_exists($data) and !is_dir($data) and is_executable($data)) {
|
||||
$executable = '<span class="pathok">✔</span>';
|
||||
} else {
|
||||
$executable = '<span class="patherror">✘</span>';
|
||||
|
|
|
@ -111,6 +111,36 @@ class core_admintree_testcase extends advanced_testcase {
|
|||
$tree->add('root', new admin_category('bar', 'Bar'), '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing whether a configexecutable setting is executable.
|
||||
*/
|
||||
public function test_admin_setting_configexecutable() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$executable = new admin_setting_configexecutable('test1', 'Text 1', 'Help Path', '');
|
||||
|
||||
// Check for an invalid path.
|
||||
$result = $executable->output_html($CFG->dirroot . '/lib/tests/other/file_does_not_exist');
|
||||
$this->assertRegexp('/class="patherror"/', $result);
|
||||
|
||||
// Check for a directory.
|
||||
$result = $executable->output_html($CFG->dirroot);
|
||||
$this->assertRegexp('/class="patherror"/', $result);
|
||||
|
||||
// Check for a file which is not executable.
|
||||
$result = $executable->output_html($CFG->dirroot . '/config.php');
|
||||
$this->assertRegexp('/class="patherror"/', $result);
|
||||
|
||||
// Check for an executable file.
|
||||
$result = $executable->output_html($CFG->dirroot . '/lib/tests/other/executable.php');
|
||||
$this->assertRegexp('/class="pathok"/', $result);
|
||||
|
||||
// Check for no file specified.
|
||||
$result = $executable->output_html('');
|
||||
$this->assertRegexp('/name="s__test1" value=""/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving of values.
|
||||
*/
|
||||
|
|
0
lib/tests/other/executable.php
Executable file
0
lib/tests/other/executable.php
Executable file
Loading…
Add table
Add a link
Reference in a new issue