Skip to content

Add Behat scenarios testing SHA-512 enforcement and MD5 handling during update - #1098

Merged
swissspidy merged 3 commits into
mainfrom
add/sha-tests
Aug 3, 2026
Merged

Add Behat scenarios testing SHA-512 enforcement and MD5 handling during update#1098
swissspidy merged 3 commits into
mainfrom
add/sha-tests

Conversation

@swissspidy

@swissspidy swissspidy commented Aug 3, 2026

Copy link
Copy Markdown
Member

Follow-up to wp-cli/wp-cli#6370

Summary by CodeRabbit

  • Tests
    • Added CLI scenarios covering update verification failures and fallback behavior.
    • Verified handling of inaccessible or mismatched SHA-512 and MD5 metadata.
    • Confirmed expected error messages, output, and exit codes.

@swissspidy
swissspidy requested a review from a team as a code owner August 3, 2026 10:31
Copilot AI review requested due to automatic review settings August 3, 2026 10:31
@swissspidy swissspidy added scope:testing Related to testing scope:distribution Related to distribution labels Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: df6367d5-376d-46ac-bf89-2a2a9ead6e62

📥 Commits

Reviewing files that changed from the base of the PR and between 5f68db8 and c2875f4.

📒 Files selected for processing (1)
  • features/cli.feature
🚧 Files skipped from review as they are similar to previous changes (1)
  • features/cli.feature

📝 Walkthrough

Walkthrough

The CLI feature suite adds scenarios for SHA-512 metadata failures, SHA-512 mismatches, MD5 fallback warnings, and MD5 mismatches. The scenarios verify output, errors, warnings, and exit codes.

Changes

CLI update verification

Layer / File(s) Summary
SHA-512 verification failures
features/cli.feature
Adds scenarios for missing SHA-512 metadata and mismatched SHA-512 hashes. Both cases require an error and exit code 1. The suite retains the PHP version requirement failure assertion.
MD5 fallback verification
features/cli.feature
Adds scenarios for successful SHA-512 validation with missing MD5 metadata and for mismatched MD5 hashes. The scenarios verify warnings, output, errors, and exit codes.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the added Behat scenarios for SHA-512 enforcement and MD5 handling during CLI updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add/sha-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@features/cli.feature`:
- Around line 195-215: Extend the SHA-512 mismatch scenario in
features/cli.feature lines 195-215 to assert that {PHAR_PATH} --version still
reports WP-CLI 2.8.0. Add the same post-failure version assertion to the SHA-512
metadata access failure scenario in features/cli.feature lines 176-193 and the
MD5 mismatch scenario in features/cli.feature lines 244-264, confirming each
rejected update leaves the original Phar installed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cde81fc2-93bc-45f3-8893-af95c8895da9

📥 Commits

Reviewing files that changed from the base of the PR and between 9b1a001 and 5f68db8.

📒 Files selected for processing (1)
  • features/cli.feature

Comment thread features/cli.feature
Comment on lines +195 to +215
Scenario: Fail update when sha512 hash mismatches
Given an empty directory
And a new Phar with version "2.8.0"
And that HTTP requests to https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar.sha512 will respond with:
"""
HTTP/1.1 200 OK
Content-Type: text/plain

invalidsha512hash
"""

When I try `{PHAR_PATH} cli update --nightly --yes`
Then STDERR should contain:
"""
Error: sha512 hash for download
"""
And STDERR should contain:
"""
is different than the release hash (invalidsha512hash).
"""
And the return code should be 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Verify that a rejected update does not replace the Phar.

An error and exit code of 1 do not prove that verification prevented installation. A faulty implementation can replace {PHAR_PATH} and then report the verification failure.

  • features/cli.feature#L195-L215: After the SHA-512 mismatch, assert {PHAR_PATH} --version still returns WP-CLI 2.8.0.
  • features/cli.feature#L176-L193: After SHA-512 metadata access fails, assert {PHAR_PATH} --version still returns WP-CLI 2.8.0.
  • features/cli.feature#L244-L264: After the MD5 mismatch, assert {PHAR_PATH} --version still returns WP-CLI 2.8.0.
Proposed assertion
+    When I run `{PHAR_PATH} --version`
+    Then STDOUT should be:
+      """
+      WP-CLI 2.8.0
+      """
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Scenario: Fail update when sha512 hash mismatches
Given an empty directory
And a new Phar with version "2.8.0"
And that HTTP requests to https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar.sha512 will respond with:
"""
HTTP/1.1 200 OK
Content-Type: text/plain
invalidsha512hash
"""
When I try `{PHAR_PATH} cli update --nightly --yes`
Then STDERR should contain:
"""
Error: sha512 hash for download
"""
And STDERR should contain:
"""
is different than the release hash (invalidsha512hash).
"""
And the return code should be 1
Scenario: Fail update when sha512 hash mismatches
Given an empty directory
And a new Phar with version "2.8.0"
And that HTTP requests to https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar.sha512 will respond with:
"""
HTTP/1.1 200 OK
Content-Type: text/plain
invalidsha512hash
"""
When I try `{PHAR_PATH} cli update --nightly --yes`
Then STDERR should contain:
"""
Error: sha512 hash for download
"""
And STDERR should contain:
"""
is different than the release hash (invalidsha512hash).
"""
And the return code should be 1
When I run `{PHAR_PATH} --version`
Then STDOUT should be:
"""
WP-CLI 2.8.0
"""
📍 Affects 1 file
  • features/cli.feature#L195-L215 (this comment)
  • features/cli.feature#L176-L193
  • features/cli.feature#L244-L264
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@features/cli.feature` around lines 195 - 215, Extend the SHA-512 mismatch
scenario in features/cli.feature lines 195-215 to assert that {PHAR_PATH}
--version still reports WP-CLI 2.8.0. Add the same post-failure version
assertion to the SHA-512 metadata access failure scenario in
features/cli.feature lines 176-193 and the MD5 mismatch scenario in
features/cli.feature lines 244-264, confirming each rejected update leaves the
original Phar installed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Behat coverage to the WP-CLI bundle to validate the self-update integrity behavior introduced in wp-cli/wp-cli#6370, specifically enforcing SHA-512 verification while treating MD5 as a secondary/optional check.

Changes:

  • Added a scenario to ensure wp cli update --nightly fails when the SHA-512 hash cannot be retrieved.
  • Added a scenario to ensure wp cli update --nightly fails when the SHA-512 hash mismatches.
  • Added scenarios to ensure MD5 retrieval failures don’t block updates (when SHA-512 matches) and that MD5 mismatches are surfaced as failures.
Suppressed comments (1)

features/cli.feature:252

  • The mocked MD5 hash value (invalidmd5hash) is not a valid MD5 hex digest length. If the updater validates hash format, this scenario could fail due to format handling instead of the intended mismatch path. Use a valid 32-character hex string and update the expected error text accordingly.
      """
      HTTP/1.1 200 OK
      Content-Type: text/plain

      invalidmd5hash

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread features/cli.feature
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy
swissspidy merged commit 1ec917a into main Aug 3, 2026
66 checks passed
@swissspidy
swissspidy deleted the add/sha-tests branch August 3, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:distribution Related to distribution scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants