Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify a specific plugin version #108

Merged
merged 10 commits into from May 23, 2023
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -86,6 +86,9 @@ wp plugin verify-checksums [<plugin>...] [--all] [--strict] [--format=<format>]
If set, even "soft changes" like readme.txt changes will trigger
checksum errors.

[--version=<version>]
Verify checksums against a specific version of plugins.
semseysandor marked this conversation as resolved.
Show resolved Hide resolved

[--format=<format>]
Render output in a specific format.
---
Expand Down
18 changes: 18 additions & 0 deletions features/checksum-plugin.feature
Expand Up @@ -13,6 +13,24 @@ 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:
"""
"plugin_name":"duplicate-post","file":"duplicate-post-jetpack.php","message":"File is missing"
"""
And STDERR should be:
"""
Error: No plugins verified (1 failed).
"""
semseysandor marked this conversation as resolved.
Show resolved Hide resolved

Scenario: Modified plugin doesn't verify
Given a WP install

Expand Down
16 changes: 10 additions & 6 deletions src/Checksum_Plugin_Command.php
Expand Up @@ -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=<version>]
* : Verify checksums against a specific version of plugins.
semseysandor marked this conversation as resolved.
Show resolved Hide resolved
*
* [--format=<format>]
* : Render output in a specific format.
* ---
Expand Down Expand Up @@ -75,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'] : '';
semseysandor marked this conversation as resolved.
Show resolved Hide resolved

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.' );
Expand All @@ -88,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;
semseysandor marked this conversation as resolved.
Show resolved Hide resolved

if ( false === $version ) {
WP_CLI::warning( "Could not retrieve the version for plugin {$plugin->name}, skipping." );
Expand Down