From cb9fe7327d6651f765ae18b6fb861b3b37343f51 Mon Sep 17 00:00:00 2001 From: "stoyan.b.georgiev" Date: Fri, 7 Apr 2023 12:47:37 +0300 Subject: [PATCH 1/3] Add exclude option for the command Fix some formatting Add feature test Fix issues after tests --- features/checksum-plugin.feature | 12 ++++++++++++ src/Checksum_Plugin_Command.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/features/checksum-plugin.feature b/features/checksum-plugin.feature index e70af037..b89ae4ac 100644 --- a/features/checksum-plugin.feature +++ b/features/checksum-plugin.feature @@ -173,3 +173,15 @@ Feature: Validate checksums for WordPress plugins """ "plugin_name":"duplicate-post","file":"duplicate-post.php","message":"Checksum does not match" """ + + Scenario: Skip plugin checksum verification + Given a WP install + And these installed and active plugins: + """ + hello-dolly + """ + When I try `wp plugin verify-checksums --all --exclude=hello-dolly` + Then STDOUT should contain: + """ + Verified 0 of 1 plugins (1 skipped). + """ \ No newline at end of file diff --git a/src/Checksum_Plugin_Command.php b/src/Checksum_Plugin_Command.php index e60b097d..3491fa2c 100644 --- a/src/Checksum_Plugin_Command.php +++ b/src/Checksum_Plugin_Command.php @@ -66,6 +66,9 @@ class Checksum_Plugin_Command extends Checksum_Base_Command { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * + * [--exclude=] + * : Comma separated list of plugin names that should be excluded from verifying. + * * ## EXAMPLES * * # Verify the checksums of all installed plugins @@ -83,17 +86,26 @@ public function __invoke( $args, $assoc_args ) { $strict = (bool) Utils\get_flag_value( $assoc_args, 'strict', false ); $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); $plugins = $fetcher->get_many( $all ? $this->get_all_plugin_names() : $args ); + $exclude = Utils\get_flag_value( $assoc_args, 'exclude', '' ); $version_arg = isset( $assoc_args['version'] ) ? $assoc_args['version'] : ''; + if ( empty( $plugins ) && ! $all ) { WP_CLI::error( 'You need to specify either one or more plugin slugs to check or use the --all flag to check all plugins.' ); } + $exclude_list = explode( ',', $exclude ); + $skips = 0; foreach ( $plugins as $plugin ) { $version = empty( $version_arg ) ? $this->get_plugin_version( $plugin->file ) : $version_arg; + if ( in_array( $plugin->name, $exclude_list, true ) ) { + $skips++; + continue; + } + if ( false === $version ) { WP_CLI::warning( "Could not retrieve the version for plugin {$plugin->name}, skipping." ); $skips++; From 90b0ac34263f3d554b59a65dda31de4ed83ededf Mon Sep 17 00:00:00 2001 From: "stoyan.b.georgiev" Date: Tue, 6 Jun 2023 14:08:02 +0300 Subject: [PATCH 2/3] Add Plugin is verified when --exclude isnt included and fix previous test Scenario --- features/checksum-plugin.feature | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/features/checksum-plugin.feature b/features/checksum-plugin.feature index b89ae4ac..0ddcc79a 100644 --- a/features/checksum-plugin.feature +++ b/features/checksum-plugin.feature @@ -174,14 +174,26 @@ Feature: Validate checksums for WordPress plugins "plugin_name":"duplicate-post","file":"duplicate-post.php","message":"Checksum does not match" """ - Scenario: Skip plugin checksum verification + Scenario: Plugin verification is skipped when the --exclude argument is included Given a WP install And these installed and active plugins: """ - hello-dolly + akismet """ - When I try `wp plugin verify-checksums --all --exclude=hello-dolly` + When I try `wp plugin verify-checksums --all --exclude=akismet` Then STDOUT should contain: """ Verified 0 of 1 plugins (1 skipped). + """ + + Scenario: Plugin is verified when the --exclude argument isn't included + Given a WP install + And these installed and active plugins: + """ + akismet + """ + When I try `wp plugin verify-checksums --all` + Then STDOUT should contain: + """ + Verified 1 of 1 plugins. """ \ No newline at end of file From d21621a70c5565508f3ef5dfca0bc92a02c63cb9 Mon Sep 17 00:00:00 2001 From: "stoyan.b.georgiev" Date: Thu, 8 Jun 2023 12:26:16 +0300 Subject: [PATCH 3/3] Fix unit tests and phpcs issues --- features/checksum-plugin.feature | 28 +++++++++++++++++++++++----- src/Checksum_Plugin_Command.php | 1 - 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/features/checksum-plugin.feature b/features/checksum-plugin.feature index 0ddcc79a..7e754741 100644 --- a/features/checksum-plugin.feature +++ b/features/checksum-plugin.feature @@ -176,10 +176,19 @@ Feature: Validate checksums for WordPress plugins Scenario: Plugin verification is skipped when the --exclude argument is included Given a WP install - And these installed and active plugins: + + When I run `wp plugin delete --all` + Then STDOUT should contain: """ - akismet + Success: """ + + When I run `wp plugin install akismet` + Then STDOUT should contain: + """ + Success: + """ + When I try `wp plugin verify-checksums --all --exclude=akismet` Then STDOUT should contain: """ @@ -188,12 +197,21 @@ Feature: Validate checksums for WordPress plugins Scenario: Plugin is verified when the --exclude argument isn't included Given a WP install - And these installed and active plugins: + + When I run `wp plugin delete --all` + Then STDOUT should contain: + """ + Success: + """ + + When I run `wp plugin install akismet` + Then STDOUT should contain: """ - akismet + Success: """ + When I try `wp plugin verify-checksums --all` Then STDOUT should contain: """ Verified 1 of 1 plugins. - """ \ No newline at end of file + """ diff --git a/src/Checksum_Plugin_Command.php b/src/Checksum_Plugin_Command.php index 3491fa2c..c65a80b6 100644 --- a/src/Checksum_Plugin_Command.php +++ b/src/Checksum_Plugin_Command.php @@ -89,7 +89,6 @@ public function __invoke( $args, $assoc_args ) { $exclude = Utils\get_flag_value( $assoc_args, 'exclude', '' ); $version_arg = isset( $assoc_args['version'] ) ? $assoc_args['version'] : ''; - if ( empty( $plugins ) && ! $all ) { WP_CLI::error( 'You need to specify either one or more plugin slugs to check or use the --all flag to check all plugins.' ); }