Skip to content

Commit

Permalink
Add an --exclude=<plugin> argument to wp plugin verify-checksums (#…
Browse files Browse the repository at this point in the history
…104)

* Add exclude option for the command

Fix some formatting

Add feature test

Fix issues after tests

* Add Plugin is verified when --exclude isnt included and fix previous test Scenario

* Fix unit tests and phpcs issues
  • Loading branch information
stoyan-g authored Jun 8, 2023
1 parent 5da44c9 commit 6d2be27
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
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

0 comments on commit 6d2be27

Please sign in to comment.