Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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 plugin version.

[--format=<format>]
Render output in a specific format.
---
Expand Down
18 changes: 18 additions & 0 deletions features/checksum-plugin.feature
Original file line number Diff line number Diff line change
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).
"""

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

Expand Down
16 changes: 10 additions & 6 deletions src/Checksum_Plugin_Command.php
Original file line number Diff line number Diff line change
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 plugin version.
*
* [--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_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.' );
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_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." );
Expand Down