Repository navigation
Tests: Move cURL transport suite off live external HTTP - #15488
shail-mehta wants to merge 12 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The loopback exemption does not match bracketed IPv6 hosts returned by wp_parse_url, so valid IPv6 loopback fixture requests remain blocked and fail test post-conditions.
1 open issue
What changed in this PR
Moves the cURL transport tests toward offline execution using local HTTP fixtures, while retaining intentional live TLS smoke coverage.
Changes:
- Removes the cURL suite’s class-level
external-httpgroup and keeps it ontest_ssl(). - Requires local redirection fixtures instead of a live fallback and mocks the SSL request-argument check.
- Adds a loopback-host exemption to the test framework’s external-HTTP guard.
| File | Description |
|---|---|
tests/phpunit/tests/http/curl.php |
Removes class-level external-HTTP grouping. |
tests/phpunit/tests/http/base.php |
Requires local fixtures, mocks SSL argument coverage, and isolates live TLS testing. |
tests/phpunit/includes/abstract-testcase.php |
Adds loopback URL handling to the external-HTTP guard. |
Review effort: Balanced
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The loopback exemption allows redirects to public URLs to bypass the HTTP guard, leaving external requests unblocked and unrecorded in tests not marked for external access.
1 open issue
1 resolved since last review
Review effort: Balanced
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
lancewillett
left a comment
There was a problem hiding this comment.
Thanks, this does what it says. With the network off, on current trunk (11418a6):
Tests_HTTP_curlruns 26 tests and passes in single site and multisite.test_ssl()still runs live inexternal-http.- The full suite fails the same tests as trunk in single site, multisite and AJAX.
Two changes before this lands.
1. Limit the exemption to the fixture server. In WP_UnitTestCase_Base, it lets any core test outside external-http reach localhost or 127.0.0.1 on any port. Today only the cURL tests use it; I logged every request through it in a full run. But a future unmocked request to localhost would pass or fail depending on what the machine is running, which is what the guard is there to catch.
Only WP_HTTP_UnitTestCase needs this, for its own server. An override in base.php can allow just that host and port, and defer to the parent for everything else:
public function block_external_http_request( $response, array $args, string $url ) {
if ( false === $response && $this->is_fixture_url( $url ) ) {
add_action( 'requests-requests.before_redirect', array( $this, 'block_external_fixture_redirect' ) );
return $response;
}
return parent::block_external_http_request( $response, $args, $url );
}is_fixture_url() compares the URL's host and port with self::$file_stream_fixture_url, and the redirect check moves to base.php as well. That leaves abstract-testcase.php unchanged. I tried it locally: the same 26 tests pass in both modes.
2. test_https_url_without_ssl_verification() no longer tests #33978. The mock returns before WP_Http::request() sets $options['verify'] = false. If I change that block to keep the CA bundle when sslverify is false, which is the bug fixed in r34639, the test still passes. This version checks the options passed to Requests and stops before connecting:
protected $requests_options = array();
public function test_https_url_without_ssl_verification() {
remove_filter( 'pre_http_request', array( $this, 'block_external_http_request' ), PHP_INT_MAX );
add_action( 'requests-requests.before_request', array( $this, 'capture_requests_options' ), 10, 5 );
try {
$res = $this->wp_remote_head( 'https://wordpress.org/', array( 'sslverify' => false ) );
} finally {
remove_action( 'requests-requests.before_request', array( $this, 'capture_requests_options' ), 10 );
}
$this->assertWPError( $res );
$this->assertFalse( $this->requests_options['verify'] );
$this->assertFalse( $this->requests_options['verifyname'] );
}
public function capture_requests_options( $url, $headers, $data, $type, &$options ) {
$this->requests_options = $options;
throw new WpOrg\Requests\Exception( 'Stopped after capturing the request options.', 'test_stopped' );
}It passes in both modes and for the streams class, and fails with that change.
One smaller note: nothing in the fixture redirects off-host, so the redirect check never runs in a test. Fine to leave, but worth knowing.
AI review · claude-opus-5-5
Limit the external-HTTP guard override to WP_HTTP_UnitTestCase fixture host/port, and capture Requests verify options instead of mocking pre_http_request.
There was a problem hiding this comment.
🔵 Needs a closer look
The replacement assertions lose coverage that sslcertificates remains populated when verification is disabled, allowing an empty or missing CA-bundle argument to pass unnoticed.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
|
Thanks @lancewillett - both changes are in:
Also noted your point that the redirect guard is defensive - left it in place. One follow-up from CI: the redirect callback needed |
lancewillett
left a comment
There was a problem hiding this comment.
Thanks @shail-mehta, both changes work. I tested 3bace18 with no network access: all 26 cURL tests pass in single site and multisite, and --group http fails the same 3 offline tests as trunk. The new SSL test also fails if the #33978 bug comes back.
One thing left, which Copilot spotted: the rewrite drops the old check that sslcertificates is still set when sslverify is false. When I emptied the default CA bundle path in WP_Http::request(), every test still passed.
Could you restore $http_request_args and filter_http_request_args() from trunk, and use them alongside the new checks?
add_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
// ...
$this->assertNotEmpty( $this->http_request_args['sslcertificates'] );With that in place, the test fails on an empty path and passes otherwise, in both modes.
AI review · claude-opus-5-5
Keeps the #33978 CA-bundle path check alongside the Requests verify options captured before connecting.
There was a problem hiding this comment.
🟡 Changes recommended
The offline test retries an intentionally returned WP_Error, adding an unconditional 15-second delay per transport; calling the global wp_remote_head() directly would avoid the retries while preserving request/options coverage.
1 open issue
Review effort: Balanced
Use the global wp_remote_head() so the intentional capture error does not sleep through retry_on_error().
|
Thanks @lancewillett!
|
lancewillett
left a comment
There was a problem hiding this comment.
Thanks @shail-mehta, this is ready.
- The restored
sslcertificatesassertion now catches an empty default CA bundle. I blanked the default inWP_Http::request(), and the test fails for both curl and streams. - Calling
wp_remote_head()directly is right. The capture callback always returns an error, so the retry helper slept 15 seconds per transport for nothing.
Tested at bc13ffd, offline, single site and multisite:
- curl and streams: 54 tests; only the live
test_sslfails, since it needs network. --group http: 262 tests, with the same 3 offline DNS failures as trunk.
AI review · claude-opus-5-5
|
PR #15488 landed in https://core.trac.wordpress.org/changeset/65320 |
Follow-up to [34639], [64733], [65084]. Developed in: #15488 Props shailu25. See #63914. git-svn-id: https://develop.svn.wordpress.org/trunk@65320 602fd350-edb4-49c9-b593-d223f7449a82
Follow-up to [34639], [64733], [65084]. Developed in: WordPress/wordpress-develop#15488 Props shailu25. See #63914. Built from https://develop.svn.wordpress.org/trunk@65320 git-svn-id: http://core.svn.wordpress.org/trunk@64460 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Follow-up to [34639], [64733], [65084]. Developed in: WordPress#15488 Props shailu25. See #63914. git-svn-id: https://develop.svn.wordpress.org/trunk@65320 602fd350-edb4-49c9-b593-d223f7449a82


Trac ticket: #63914
What
Moves
Tests_HTTP_curlout of theexternal-httpgroup by running real cURL coverage against the local HTTP fixture, mocking the CA-bundle SSL-arg check, and keeping onlytest_ssl()as intentional live TLS smoke coverage.Why
curl.phpstayed inexternal-httpbecause of livewordpress.org/api.wordpress.orgdependencies. Redirect, stream, cookie, and header checks already prove transport behavior against the local fixture and do not need the public network.How
127.0.0.1,localhost,::1) in the external-HTTP guard so local fixture requests can run outsideexternal-httpapi.wordpress.orgfallbacktest_https_url_without_ssl_verification()to assertsslcertificates/sslverifyofflinetest_ssl()with method-level@group external-http@group external-httpfromtests/phpunit/tests/http/curl.phpTesting instructions
npm run env:start && npm run env:installnpm run test:php -- --filter Tests_HTTP_curl --exclude-group external-httpnpm run test:php -- --filter 'Tests_HTTP_curl::test_ssl' --group external-httpexternal-httpUse of AI Tools