Skip to content

Commit 1ec917a

Browse files
authored
Add Behat scenarios testing SHA-512 enforcement and MD5 handling during update (#1098)
1 parent faa30f2 commit 1ec917a

1 file changed

Lines changed: 90 additions & 2 deletions

File tree

‎features/cli.feature‎

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,95 @@ Feature: `wp cli` tasks
174174
WP-CLI {UPDATE_VERSION}
175175
"""
176176
177+
Scenario: Fail update when sha512 hash cannot be accessed
178+
Given an empty directory
179+
And a new Phar with version "2.8.0"
180+
And that HTTP requests to https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar.sha512 will respond with:
181+
"""
182+
HTTP/1.1 404 Not Found
183+
Content-Type: text/plain
184+
185+
Not Found
186+
"""
187+
188+
When I try `{PHAR_PATH} cli update --nightly --yes`
189+
Then STDERR should contain:
190+
"""
191+
Error: Couldn't access sha512 hash for release (HTTP code 404).
192+
"""
193+
And the return code should be 1
194+
195+
Scenario: Fail update when sha512 hash mismatches
196+
Given an empty directory
197+
And a new Phar with version "2.8.0"
198+
And that HTTP requests to https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar.sha512 will respond with:
199+
"""
200+
HTTP/1.1 200 OK
201+
Content-Type: text/plain
202+
203+
invalidsha512hash
204+
"""
205+
206+
When I try `{PHAR_PATH} cli update --nightly --yes`
207+
Then STDERR should contain:
208+
"""
209+
Error: sha512 hash for download
210+
"""
211+
And STDERR should contain:
212+
"""
213+
is different than the release hash (invalidsha512hash).
214+
"""
215+
And the return code should be 1
216+
217+
Scenario: Update succeeds when sha512 matches even if md5 cannot be accessed
218+
Given an empty directory
219+
And a new Phar with version "2.8.0"
220+
And that HTTP requests to https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar.md5 will respond with:
221+
"""
222+
HTTP/1.1 404 Not Found
223+
Content-Type: text/plain
224+
225+
Not Found
226+
"""
227+
228+
When I run `{PHAR_PATH} cli update --nightly --yes`
229+
Then STDOUT should contain:
230+
"""
231+
sha512 hash verified:
232+
"""
233+
And STDOUT should contain:
234+
"""
235+
Couldn't access md5 hash for release (HTTP code 404).
236+
"""
237+
And STDOUT should contain:
238+
"""
239+
Success: Updated WP-CLI to the latest nightly release.
240+
"""
241+
And STDERR should be empty
242+
And the return code should be 0
243+
244+
Scenario: Fail update when md5 hash mismatches
245+
Given an empty directory
246+
And a new Phar with version "2.8.0"
247+
And that HTTP requests to https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar.md5 will respond with:
248+
"""
249+
HTTP/1.1 200 OK
250+
Content-Type: text/plain
251+
252+
invalidmd5hash
253+
"""
254+
255+
When I try `{PHAR_PATH} cli update --nightly --yes`
256+
Then STDERR should contain:
257+
"""
258+
Error: md5 hash for download
259+
"""
260+
And STDERR should contain:
261+
"""
262+
is different than the release hash (invalidmd5hash).
263+
"""
264+
And the return code should be 1
265+
177266
Scenario: Prevent stable update when PHP version requirement is not met
178267
Given an empty directory
179268
And a new Phar with version "2.8.0"
@@ -212,5 +301,4 @@ Feature: `wp cli` tasks
212301
"""
213302
The requested update requires PHP 99.0.0 or higher.
214303
"""
215-
And the return code should be 1
216-
304+
And the return code should be 1

0 commit comments

Comments
 (0)