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
42 changes: 42 additions & 0 deletions features/checksum-plugin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,45 @@ Feature: Validate checksums for WordPress plugins
"""
"plugin_name":"duplicate-post","file":"duplicate-post.php","message":"Checksum does not match"
"""

Scenario: Plugin verification is skipped when the --exclude argument is included
Given a WP install

When I run `wp plugin delete --all`
Then STDOUT should contain:
"""
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:
"""
Verified 0 of 1 plugins (1 skipped).
"""

Scenario: Plugin is verified when the --exclude argument isn't included
Given a WP install

When I run `wp plugin delete --all`
Then STDOUT should contain:
"""
Success:
"""

When I run `wp plugin install akismet`
Then STDOUT should contain:
"""
Success:
"""

When I try `wp plugin verify-checksums --all`
Then STDOUT should contain:
"""
Verified 1 of 1 plugins.
"""
11 changes: 11 additions & 0 deletions src/Checksum_Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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=<name>]
* : Comma separated list of plugin names that should be excluded from verifying.
*
* ## EXAMPLES
*
* # Verify the checksums of all installed plugins
Expand All @@ -83,17 +86,25 @@ 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++;
Expand Down