From 14fee64316a624b2a6da8bf385643e3f01358374 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 22 May 2023 17:30:53 +0200 Subject: [PATCH 01/10] add functional tests --- features/checksum-plugin.feature | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/features/checksum-plugin.feature b/features/checksum-plugin.feature index 8b1bb477..00ca9e9d 100644 --- a/features/checksum-plugin.feature +++ b/features/checksum-plugin.feature @@ -13,6 +13,16 @@ Feature: Validate checksums for WordPress plugins Success: Verified 1 of 1 plugins. """ + When I run `wp plugin verify-checksums duplicate-post --format=json --version=3.2.2` + Then STDOUT should contain: + """ + "plugin_name":"duplicate-post","file":"duplicate-post-jetpack.php","message":"File is missing" + """ + And STDERR should be: + """ + Error: No plugins verified (1 failed). + """ + Scenario: Modified plugin doesn't verify Given a WP install From 992be4eb19d42e909edfa6273b72f979ff526f71 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 22 May 2023 17:33:24 +0200 Subject: [PATCH 02/10] add --version option to plugin command --- src/Checksum_Plugin_Command.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Checksum_Plugin_Command.php b/src/Checksum_Plugin_Command.php index e66710cc..1a14c6b4 100644 --- a/src/Checksum_Plugin_Command.php +++ b/src/Checksum_Plugin_Command.php @@ -48,6 +48,9 @@ class Checksum_Plugin_Command extends Checksum_Base_Command { * : If set, even "soft changes" like readme.txt changes will trigger * checksum errors. * + * [--version=] + * : Verify checksums against a specific version of plugins. + * * [--format=] * : Render output in a specific format. * --- From c06ed3903d7d2e64c02871fd933c1479bf89f140 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 22 May 2023 17:35:00 +0200 Subject: [PATCH 03/10] plugin command: use version if supplied --- src/Checksum_Plugin_Command.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Checksum_Plugin_Command.php b/src/Checksum_Plugin_Command.php index 1a14c6b4..f7a50c86 100644 --- a/src/Checksum_Plugin_Command.php +++ b/src/Checksum_Plugin_Command.php @@ -78,11 +78,12 @@ class Checksum_Plugin_Command extends Checksum_Base_Command { */ public function __invoke( $args, $assoc_args ) { - $fetcher = new Fetchers\UnfilteredPlugin(); - $all = (bool) Utils\get_flag_value( $assoc_args, 'all', false ); - $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 ); + $fetcher = new Fetchers\UnfilteredPlugin(); + $all = (bool) Utils\get_flag_value( $assoc_args, 'all', false ); + $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 ); + $version_cli = 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.' ); @@ -91,7 +92,7 @@ public function __invoke( $args, $assoc_args ) { $skips = 0; foreach ( $plugins as $plugin ) { - $version = $this->get_plugin_version( $plugin->file ); + $version = empty( $version_cli ) ? $this->get_plugin_version( $plugin->file ) : $version_cli; if ( false === $version ) { WP_CLI::warning( "Could not retrieve the version for plugin {$plugin->name}, skipping." ); From 0bf565ef64224d49c8e88133e9aaf681abd48a79 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 22 May 2023 17:35:24 +0200 Subject: [PATCH 04/10] update README.md with --version --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d7e79677..a9be0c06 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,9 @@ wp plugin verify-checksums [...] [--all] [--strict] [--format=] If set, even "soft changes" like readme.txt changes will trigger checksum errors. + [--version=] + Verify checksums against a specific version of plugins. + [--format=] Render output in a specific format. --- From ff6659f7f2e3461d6840d630628ad04db72c5ad3 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 22 May 2023 18:57:55 +0200 Subject: [PATCH 05/10] tests: add check for return code=1 --- features/checksum-plugin.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/checksum-plugin.feature b/features/checksum-plugin.feature index 00ca9e9d..cd5bbc47 100644 --- a/features/checksum-plugin.feature +++ b/features/checksum-plugin.feature @@ -14,7 +14,8 @@ Feature: Validate checksums for WordPress plugins """ When I run `wp plugin verify-checksums duplicate-post --format=json --version=3.2.2` - Then STDOUT should contain: + Then the return code should be 1 + And STDOUT should contain: """ "plugin_name":"duplicate-post","file":"duplicate-post-jetpack.php","message":"File is missing" """ From 99b2bffd064a9607df8cfa0522528055452ffe6b Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 22 May 2023 22:56:54 +0200 Subject: [PATCH 06/10] tests: use `When I try` when error is expected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Wojciech SmoliƄski --- features/checksum-plugin.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/checksum-plugin.feature b/features/checksum-plugin.feature index cd5bbc47..b13d3884 100644 --- a/features/checksum-plugin.feature +++ b/features/checksum-plugin.feature @@ -13,7 +13,7 @@ Feature: Validate checksums for WordPress plugins Success: Verified 1 of 1 plugins. """ - When I run `wp plugin verify-checksums duplicate-post --format=json --version=3.2.2` + When I try `wp plugin verify-checksums duplicate-post --format=json --version=3.2.2` Then the return code should be 1 And STDOUT should contain: """ From 7661ed3a0fc8ad97d6127a07177dee633ea2b9b2 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 22 May 2023 23:12:07 +0200 Subject: [PATCH 07/10] tests: check successful validation also --- features/checksum-plugin.feature | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/features/checksum-plugin.feature b/features/checksum-plugin.feature index b13d3884..e70af037 100644 --- a/features/checksum-plugin.feature +++ b/features/checksum-plugin.feature @@ -13,6 +13,13 @@ Feature: Validate checksums for WordPress plugins Success: Verified 1 of 1 plugins. """ + When I run `wp plugin verify-checksums duplicate-post --format=json --version=3.2.1` + Then STDOUT should be: + """ + Success: Verified 1 of 1 plugins. + """ + And STDERR should be empty + When I try `wp plugin verify-checksums duplicate-post --format=json --version=3.2.2` Then the return code should be 1 And STDOUT should contain: From 8df484774be21c8bdac9cf6f40120d8cdf1a516a Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Tue, 23 May 2023 15:46:41 +0200 Subject: [PATCH 08/10] fix --version description Co-authored-by: Daniel Bachhuber --- src/Checksum_Plugin_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Checksum_Plugin_Command.php b/src/Checksum_Plugin_Command.php index f7a50c86..3b7c2b22 100644 --- a/src/Checksum_Plugin_Command.php +++ b/src/Checksum_Plugin_Command.php @@ -49,7 +49,7 @@ class Checksum_Plugin_Command extends Checksum_Base_Command { * checksum errors. * * [--version=] - * : Verify checksums against a specific version of plugins. + * : Verify checksums against a specific plugin version. * * [--format=] * : Render output in a specific format. From 6fb9ba229a4079a1d7547de6de3863e66393c89e Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Tue, 23 May 2023 15:47:02 +0200 Subject: [PATCH 09/10] README.md: fix --version description Co-authored-by: Daniel Bachhuber --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9be0c06..a06aabdd 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ wp plugin verify-checksums [...] [--all] [--strict] [--format=] checksum errors. [--version=] - Verify checksums against a specific version of plugins. + Verify checksums against a specific plugin version. [--format=] Render output in a specific format. From b7badc3b806e0b75e91167afad90e0af799bdd0f Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Tue, 23 May 2023 16:13:03 +0200 Subject: [PATCH 10/10] rename local variable --- src/Checksum_Plugin_Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Checksum_Plugin_Command.php b/src/Checksum_Plugin_Command.php index 3b7c2b22..e60b097d 100644 --- a/src/Checksum_Plugin_Command.php +++ b/src/Checksum_Plugin_Command.php @@ -83,7 +83,7 @@ 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 ); - $version_cli = isset( $assoc_args['version'] ) ? $assoc_args['version'] : ''; + $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.' ); @@ -92,7 +92,7 @@ public function __invoke( $args, $assoc_args ) { $skips = 0; foreach ( $plugins as $plugin ) { - $version = empty( $version_cli ) ? $this->get_plugin_version( $plugin->file ) : $version_cli; + $version = empty( $version_arg ) ? $this->get_plugin_version( $plugin->file ) : $version_arg; if ( false === $version ) { WP_CLI::warning( "Could not retrieve the version for plugin {$plugin->name}, skipping." );