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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This package implements the following commands:
Verifies WordPress files against WordPress.org's checksums.

~~~
wp core verify-checksums [--include-root] [--version=<version>] [--locale=<locale>] [--insecure]
wp core verify-checksums [--include-root] [--version=<version>] [--locale=<locale>] [--insecure] [--exclude=<files>]
~~~

Downloads md5 checksums for the current version from WordPress.org, and
Expand All @@ -43,6 +43,9 @@ site.
[--insecure]
Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.

[--exclude=<files>]
Exclude specific files from the checksum verification. Provide a comma-separated list of file paths.

**EXAMPLES**

# Verify checksums
Expand All @@ -64,7 +67,9 @@ site.
Warning: File doesn't verify against checksum: wp-config-sample.php
Error: WordPress installation doesn't verify against checksums.


# Verify checksums excluding specific files
$ wp core verify-checksums --exclude="wp-my-custom-file.php,readme.html"
Success: WordPress installation verifies against checksums.

### wp plugin verify-checksums

Expand Down
32 changes: 32 additions & 0 deletions features/checksum-core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,35 @@ Feature: Validate checksums for WordPress install
Success: WordPress installation verifies against checksums.
"""
And STDERR should be empty

Scenario: Verify core checksums with excluded files
Given a WP install
And "WordPress" replaced with "PressWord" in the readme.html file
And a wp-includes/some-filename.php file:
"""
sample content of some file
"""

When I try `wp core verify-checksums --exclude='readme.html,wp-includes/some-filename.php'`
Then STDERR should be empty
And STDOUT should be:
"""
Success: WordPress installation verifies against checksums.
"""
And the return code should be 0

Scenario: Verify core checksums with missing excluded file
Given a WP install
And "WordPress" replaced with "PressWord" in the readme.html file
And a wp-includes/some-filename.php file:
"""
sample content of some file
"""

When I try `wp core verify-checksums --exclude='wp-includes/some-filename.php'`
Then STDERR should be:
"""
Warning: File doesn't verify against checksum: readme.html
Error: WordPress installation doesn't verify against checksums.
"""
And the return code should be 1
25 changes: 25 additions & 0 deletions src/Checksum_Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class Checksum_Core_Command extends Checksum_Base_Command {
*/
private $include_root = false;

/**
* Files to exclude from the verification.
*
* @var array
*/
private $exclude_files = [];

/**
* Verifies WordPress files against WordPress.org's checksums.
*
Expand Down Expand Up @@ -44,6 +51,9 @@ class Checksum_Core_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=<files>]
* : Exclude specific files from the checksum verification. Provide a comma-separated list of file paths.
*
* ## EXAMPLES
*
* # Verify checksums
Expand All @@ -65,6 +75,10 @@ class Checksum_Core_Command extends Checksum_Base_Command {
* Warning: File doesn't verify against checksum: wp-config-sample.php
* Error: WordPress installation doesn't verify against checksums.
*
* # Verify checksums and exclude files
* $ wp core verify-checksums --exclude="readme.html"
* Success: WordPress installation verifies against checksums.
*
* @when before_wp_load
*/
public function __invoke( $args, $assoc_args ) {
Expand All @@ -83,6 +97,10 @@ public function __invoke( $args, $assoc_args ) {
$this->include_root = true;
}

if ( ! empty( $assoc_args['exclude'] ) ) {
$this->exclude_files = explode( ',', Utils\get_flag_value( $assoc_args, 'exclude', '' ) );
}

if ( empty( $wp_version ) ) {
$details = self::get_wp_details();
$wp_version = $details['wp_version'];
Expand Down Expand Up @@ -112,6 +130,10 @@ public function __invoke( $args, $assoc_args ) {
continue;
}

if ( in_array( $file, $this->exclude_files, true ) ) {
continue;
}

if ( ! file_exists( ABSPATH . $file ) ) {
WP_CLI::warning( "File doesn't exist: {$file}" );
$has_errors = true;
Expand All @@ -131,6 +153,9 @@ public function __invoke( $args, $assoc_args ) {

if ( ! empty( $additional_files ) ) {
foreach ( $additional_files as $additional_file ) {
if ( in_array( $additional_file, $this->exclude_files, true ) ) {
continue;
}
WP_CLI::warning( "File should not exist: {$additional_file}" );
}
}
Expand Down