MDL-45221 admin: configexecutable admin settings should only accept files

This commit is contained in:
Andrew Nicols 2014-04-22 22:45:33 +08:00
parent 4f214c3b64
commit 29fe6d8155
3 changed files with 31 additions and 1 deletions

View file

@ -2352,7 +2352,7 @@ class admin_setting_configexecutable extends admin_setting_configfile {
$default = $this->get_defaultsetting(); $default = $this->get_defaultsetting();
if ($data) { 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">&#x2714;</span>'; $executable = '<span class="pathok">&#x2714;</span>';
} else { } else {
$executable = '<span class="patherror">&#x2718;</span>'; $executable = '<span class="patherror">&#x2718;</span>';

View file

@ -111,6 +111,36 @@ class core_admintree_testcase extends advanced_testcase {
$tree->add('root', new admin_category('bar', 'Bar'), ''); $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. * Saving of values.
*/ */

0
lib/tests/other/executable.php Executable file
View file