From e977c59ae2aa30ca4a63bcd23b2b0e988766c3aa Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 20 Sep 2024 12:05:59 +0545 Subject: [PATCH 1/3] Detect possible updater inside vendor --- .../Checks/Plugin_Repo/Plugin_Updater_Check.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Updater_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Updater_Check.php index 46dae0007..dbeb76413 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Updater_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Updater_Check.php @@ -134,8 +134,22 @@ protected function look_for_update_uri_header( Check_Result $result ) { * @param array $php_files List of absolute PHP file paths. */ protected function look_for_updater_file( Check_Result $result, array $php_files ) { + // Possible extra files which are not included in default files list. + $updater_files = array( + 'vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php', + 'vendor/plugin-update-checker/plugin-update-checker.php', + 'vendor/kernl/kernl-update-checker/kernl-update-checker.php', + ); + + $plugin_path = $result->plugin()->path(); + + foreach ( $updater_files as $updater_file ) { + if ( file_exists( $plugin_path . $updater_file ) ) { + $php_files[] = $plugin_path . $updater_file; + } + } - $plugin_update_files = self::filter_files_by_regex( $php_files, '/plugin-update-checker\.php$/' ); + $plugin_update_files = self::filter_files_by_regex( $php_files, '/(plugin|kernl)-update-checker\.php$/' ); if ( $plugin_update_files ) { foreach ( $plugin_update_files as $file ) { From fb2619eaaf9d06476c1709bf23555130ba4086dc Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 20 Sep 2024 12:35:42 +0545 Subject: [PATCH 2/3] Add test for updater inside vendor folder --- .../load.php | 16 ++++++++++++++++ .../Checks/Plugin_Updater_Check_Tests.php | 19 +++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-updater-file-inside-vendor-errors/load.php diff --git a/tests/phpunit/testdata/plugins/test-plugin-updater-file-inside-vendor-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-updater-file-inside-vendor-errors/load.php new file mode 100644 index 000000000..1f2e766c0 --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-updater-file-inside-vendor-errors/load.php @@ -0,0 +1,16 @@ + array( + 'Update URI Header' => array( Plugin_Updater_Check::TYPE_PLUGIN_UPDATE_URI_HEADER, 'test-plugin-update-uri-header-errors/load.php', 'load.php', 'plugin_updater_detected', true, ), - 'Updater File' => array( + 'Updater File' => array( Plugin_Updater_Check::TYPE_PLUGIN_UPDATER_FILE, 'test-plugin-updater-file-errors/load.php', 'plugin-update-checker.php', 'plugin_updater_detected', true, ), - 'Plugin Updaters' => array( + 'Updater File Inside Vendor' => array( + Plugin_Updater_Check::TYPE_PLUGIN_UPDATER_FILE, + 'test-plugin-updater-file-inside-vendor-errors/load.php', + 'vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php', + 'plugin_updater_detected', + true, + ), + 'Plugin Updaters' => array( Plugin_Updater_Check::TYPE_PLUGIN_UPDATERS, 'test-plugin-updaters-errors/load.php', 'load.php', 'plugin_updater_detected', true, ), - 'Plugin Updaters Regex' => array( + 'Plugin Updaters Regex' => array( Plugin_Updater_Check::TYPE_PLUGIN_UPDATERS, 'test-plugin-updaters-regex-errors/load.php', 'load.php', 'plugin_updater_detected', true, ), - 'Updater Routines' => array( + 'Updater Routines' => array( Plugin_Updater_Check::TYPE_PLUGIN_UPDATER_ROUTINES, 'test-plugin-updater-routines-errors/load.php', 'load.php', 'update_modification_detected', false, ), - 'Updater Routines Regex' => array( + 'Updater Routines Regex' => array( Plugin_Updater_Check::TYPE_PLUGIN_UPDATER_ROUTINES, 'test-plugin-updater-routines-regex-errors/load.php', 'load.php', From 033fd6b6d21ccd4e8c02498db3bfe77cc360ea53 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 20 Sep 2024 12:41:50 +0545 Subject: [PATCH 3/3] Add vendor folder inside test files --- .gitignore | 2 +- .../plugin-update-checker/plugin-update-checker.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-updater-file-inside-vendor-errors/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php diff --git a/.gitignore b/.gitignore index a9deef5e9..38faa5dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,7 @@ build ############ node_modules/ -vendor/ +/vendor/ build-cs/vendor/ build-cs/composer.lock build-phpunit/vendor/ diff --git a/tests/phpunit/testdata/plugins/test-plugin-updater-file-inside-vendor-errors/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php b/tests/phpunit/testdata/plugins/test-plugin-updater-file-inside-vendor-errors/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php new file mode 100644 index 000000000..10e8b632c --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-updater-file-inside-vendor-errors/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php @@ -0,0 +1,3 @@ +