#64412 closed defect (bug) (fixed)
Sporadic unit test failure in Tests_REST_WpRestUrlDetailsController::test_get_items
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9.1 | Priority: | normal |
| Severity: | normal | Version: | 5.9 |
| Component: | Editor | Keywords: | has-patch has-unit-tests fixed-major dev-reviewed |
| Focuses: | rest-api | Cc: |
Description (last modified by )
In #54358 via [51973] tests for the URL Details endpoint were introduced. These used a https://placeholder-site.com URL as the test URL for the unit tests in Tests_REST_WpRestUrlDetailsController. As discussed in Slack, recently, one of these tests has been failing sporadically:
1) Tests_REST_WpRestUrlDetailsController::test_get_items Failed asserting that two arrays are identical. --- Expected +++ Actual @@ @@ Array &0 ( - 'title' => 'Example Website — - with encoded content.' - 'icon' => 'https://placeholder-site.com/favicon.ico?querystringaddedfortesting' - 'description' => 'Example description text here. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore.' - 'image' => 'https://placeholder-site.com/images/home/screen-themes.png?3' + 'code' => 'rest_invalid_param' + 'message' => 'Invalid parameter(s): url' + 'data' => Array &1 ( + 'status' => 400 + 'params' => Array &2 ( + 'url' => 'Invalid parameter.' + ) + 'details' => Array &3 () + ) ) /var/www/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php:131
Even though the HTTP request is intercepted with a mocked response via the pre_http_request filter, it appears this mocking is not complete. In particular, the wp-block-editor/v1/url-details endpoint includes a url param which has wp_http_validate_url() as its validate_callback. This validation function ends up calling gethostbyname(). Since https://placeholder-site.com is not an actual site, it appears that this gethostbyname() often returns with a failure. I can reproduce the unit test failure by patching wp_http_validate_url() as follows:
-
src/wp-includes/http.php
a b function wp_http_validate_url( $url ) { 593 593 $ip = $host; 594 594 } else { 595 595 $ip = gethostbyname( $host ); 596 if ( $ip === $host ) { // Error condition for gethostbyname().596 if ( true || $ip === $host ) { // Error condition for gethostbyname(). 597 597 return false; 598 598 } 599 599 }
I think we should simply use the domain for a real site, like https://example.com.
Change History (8)
This ticket was mentioned in Slack in #core by westonruter. View the logs.
8 weeks ago
This ticket was mentioned in PR #10625 on WordPress/wordpress-develop by @westonruter.
8 weeks ago
#2
- Keywords has-patch has-unit-tests added
#5
@
8 weeks ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening for 6.9 backport consideration.
#8
@
6 weeks ago
I just saw this pop up again: https://github.com/WordPress/wordpress-develop/actions/runs/20580202810/job/59105886273?pr=10653#step:14:534
Trac ticket: https://core.trac.wordpress.org/ticket/64412