From 033761fe9b555d02f6c0acc4ee956c010104968a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Mudr=C3=A1k?= Date: Thu, 6 Aug 2015 15:59:40 +0200 Subject: [PATCH] MDL-48494 admin: Fail validation of plugins with no component declared --- admin/tool/installaddon/classes/validator.php | 31 ++++++++++--------- .../lang/en/tool_installaddon.php | 3 ++ .../nocomponent/baz/lang/en/auth_baz.php | 3 ++ .../fixtures/nocomponent/baz/version.php | 5 +++ .../tests/fixtures/nolang/bah/version.php | 1 + .../fixtures/wronglang/bah/lang/en/bah.php | 3 ++ .../tests/fixtures/wronglang/bah/version.php | 4 +++ .../installaddon/tests/validator_test.php | 13 +++++++- admin/tool/installaddon/version.php | 2 +- 9 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 admin/tool/installaddon/tests/fixtures/nocomponent/baz/lang/en/auth_baz.php create mode 100644 admin/tool/installaddon/tests/fixtures/nocomponent/baz/version.php create mode 100644 admin/tool/installaddon/tests/fixtures/wronglang/bah/lang/en/bah.php create mode 100644 admin/tool/installaddon/tests/fixtures/wronglang/bah/version.php diff --git a/admin/tool/installaddon/classes/validator.php b/admin/tool/installaddon/classes/validator.php index 0bb3a413e18..0ae709727a8 100644 --- a/admin/tool/installaddon/classes/validator.php +++ b/admin/tool/installaddon/classes/validator.php @@ -322,21 +322,24 @@ class tool_installaddon_validator { $this->add_message(self::INFO, 'requiresmoodle', $this->versionphp['requires']); } - if (isset($info['plugin->component'])) { - $this->versionphp['component'] = $info['plugin->component']; - list($reqtype, $reqname) = core_component::normalize_component($this->versionphp['component']); - if ($reqtype !== $this->assertions['plugintype']) { - $this->add_message(self::ERROR, 'componentmismatchtype', array( - 'expected' => $this->assertions['plugintype'], - 'found' => $reqtype)); - return false; - } - if ($reqname !== $this->rootdir) { - $this->add_message(self::ERROR, 'componentmismatchname', $reqname); - return false; - } - $this->add_message(self::INFO, 'componentmatch', $this->versionphp['component']); + if (!isset($info['plugin->component'])) { + $this->add_message(self::ERROR, 'missingcomponent'); + return false; + } + + $this->versionphp['component'] = $info['plugin->component']; + list($reqtype, $reqname) = core_component::normalize_component($this->versionphp['component']); + if ($reqtype !== $this->assertions['plugintype']) { + $this->add_message(self::ERROR, 'componentmismatchtype', array( + 'expected' => $this->assertions['plugintype'], + 'found' => $reqtype)); + return false; + } + if ($reqname !== $this->rootdir) { + $this->add_message(self::ERROR, 'componentmismatchname', $reqname); + return false; } + $this->add_message(self::INFO, 'componentmatch', $this->versionphp['component']); if (isset($info['plugin->maturity'])) { $this->versionphp['maturity'] = $info['plugin->maturity']; diff --git a/admin/tool/installaddon/lang/en/tool_installaddon.php b/admin/tool/installaddon/lang/en/tool_installaddon.php index ade477ae00c..4f869cae41e 100644 --- a/admin/tool/installaddon/lang/en/tool_installaddon.php +++ b/admin/tool/installaddon/lang/en/tool_installaddon.php @@ -71,6 +71,9 @@ $string['validationmsg_filestatus_info'] = 'Attempting to extract file {$a->file $string['validationmsg_foundlangfile'] = 'Found language file'; $string['validationmsg_maturity'] = 'Declared maturity level'; $string['validationmsg_maturity_help'] = 'The plugin can declare its maturity level. If the maintainer considers the plugin stable, the declared maturity level will read MATURITY_STABLE. All other maturity levels (such as alpha or beta) should be considered unstable and a warning is raised.'; +$string['validationmsg_missingcomponent'] = 'Plugin does not declare its component name'; +$string['validationmsg_missingcomponent_help'] = 'All plugins must provide their full component name via the `$plugin->component` declaration in the version.php file.'; +$string['validationmsg_missingcomponent_link'] = 'Development:version.php'; $string['validationmsg_missingexpectedlangenfile'] = 'English language file name mismatch'; $string['validationmsg_missingexpectedlangenfile_info'] = 'The given plugin type is missing the expected English language file {$a}.'; $string['validationmsg_missinglangenfile'] = 'No English language file found'; diff --git a/admin/tool/installaddon/tests/fixtures/nocomponent/baz/lang/en/auth_baz.php b/admin/tool/installaddon/tests/fixtures/nocomponent/baz/lang/en/auth_baz.php new file mode 100644 index 00000000000..4422fa6f2cf --- /dev/null +++ b/admin/tool/installaddon/tests/fixtures/nocomponent/baz/lang/en/auth_baz.php @@ -0,0 +1,3 @@ +component missing in its version.php'; diff --git a/admin/tool/installaddon/tests/fixtures/nocomponent/baz/version.php b/admin/tool/installaddon/tests/fixtures/nocomponent/baz/version.php new file mode 100644 index 00000000000..f87367e5954 --- /dev/null +++ b/admin/tool/installaddon/tests/fixtures/nocomponent/baz/version.php @@ -0,0 +1,5 @@ +version = 2015080600; +$plugin->release = 'B.A.Z. Auth fake plugin'; +//$plugin->component is missing here so the validation must fail. diff --git a/admin/tool/installaddon/tests/fixtures/nolang/bah/version.php b/admin/tool/installaddon/tests/fixtures/nolang/bah/version.php index 3b473d4a118..9ac0924ae3c 100644 --- a/admin/tool/installaddon/tests/fixtures/nolang/bah/version.php +++ b/admin/tool/installaddon/tests/fixtures/nolang/bah/version.php @@ -1,3 +1,4 @@ version = 2014122455; +$plugin->component = 'mod_bah'; diff --git a/admin/tool/installaddon/tests/fixtures/wronglang/bah/lang/en/bah.php b/admin/tool/installaddon/tests/fixtures/wronglang/bah/lang/en/bah.php new file mode 100644 index 00000000000..70668e823db --- /dev/null +++ b/admin/tool/installaddon/tests/fixtures/wronglang/bah/lang/en/bah.php @@ -0,0 +1,3 @@ +version = 2014122455; +$plugin->component = 'block_bah'; diff --git a/admin/tool/installaddon/tests/validator_test.php b/admin/tool/installaddon/tests/validator_test.php index 709f2cca536..44eb3069f9f 100644 --- a/admin/tool/installaddon/tests/validator_test.php +++ b/admin/tool/installaddon/tests/validator_test.php @@ -145,6 +145,17 @@ class tool_installaddon_validator_testcase extends basic_testcase { $this->assertFalse($validator->execute()); $this->assertTrue($this->has_message($validator->get_messages(), $validator::ERROR, 'versionphpsyntax', '$module')); + $validator = testable_tool_installaddon_validator::instance($fixtures.'/nocomponent', array( + 'baz/' => true, + 'baz/version.php' => true, + 'baz/lang/' => true, + 'baz/lang/en/' => true, + 'baz/lang/en/auth_baz.php' => true)); + $validator->assert_plugin_type('auth'); + $validator->assert_moodle_version(0); + $this->assertFalse($validator->execute()); + $this->assertTrue($this->has_message($validator->get_messages(), $validator::ERROR, 'missingcomponent')); + $validator = testable_tool_installaddon_validator::instance($fixtures.'/plugindir', array( 'foobar/' => true, 'foobar/version.php' => true, @@ -216,7 +227,7 @@ class tool_installaddon_validator_testcase extends basic_testcase { $this->assertTrue($this->has_message($validator->get_messages(), $validator::WARNING, 'multiplelangenfiles')); $this->assertTrue(is_null($validator->get_language_file_name())); - $validator = testable_tool_installaddon_validator::instance($fixtures.'/nolang', array( + $validator = testable_tool_installaddon_validator::instance($fixtures.'/wronglang', array( 'bah/' => true, 'bah/version.php' => true, 'bah/lang/' => true, diff --git a/admin/tool/installaddon/version.php b/admin/tool/installaddon/version.php index 4c22571e434..00f0c61c07e 100644 --- a/admin/tool/installaddon/version.php +++ b/admin/tool/installaddon/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'tool_installaddon'; -$plugin->version = 2015051100; +$plugin->version = 2015080601; $plugin->requires = 2015050500; $plugin->maturity = MATURITY_STABLE; -- 2.43.0