Skip to content

Tests: Move cURL transport suite off live external HTTP - #15488

Closed
shail-mehta wants to merge 12 commits into
WordPress:trunkfrom
shail-mehta:tests/63914-curl-offline-local-fixture
Closed

shail-mehta wants to merge 12 commits into
WordPress:trunkfrom
shail-mehta:tests/63914-curl-offline-local-fixture

Conversation

@shail-mehta

@shail-mehta shail-mehta commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: #63914

What

Moves Tests_HTTP_curl out of the external-http group by running real cURL coverage against the local HTTP fixture, mocking the CA-bundle SSL-arg check, and keeping only test_ssl() as intentional live TLS smoke coverage.

Why

curl.php stayed in external-http because of live wordpress.org / api.wordpress.org dependencies. Redirect, stream, cookie, and header checks already prove transport behavior against the local fixture and do not need the public network.

How

  • Allow loopback hosts (127.0.0.1, localhost, ::1) in the external-HTTP guard so local fixture requests can run outside external-http
  • Require the local redirection fixture and remove the live api.wordpress.org fallback
  • Mock test_https_url_without_ssl_verification() to assert sslcertificates / sslverify offline
  • Keep test_ssl() with method-level @group external-http
  • Remove class-level @group external-http from tests/phpunit/tests/http/curl.php

Testing instructions

  1. Start the local environment: npm run env:start && npm run env:install
  2. Run: npm run test:php -- --filter Tests_HTTP_curl --exclude-group external-http
  3. Expect 26 tests, all passing, with no live HTTP
  4. Run: npm run test:php -- --filter 'Tests_HTTP_curl::test_ssl' --group external-http
  5. Expect the live SSL smoke test to still run in external-http

Use of AI Tools

  • Cursor

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.

🟡 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-http group and keeps it on test_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>

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.

🟡 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

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.

🟢 Approval recommended

No active review issues remain for the changes moving cURL tests to local HTTP fixtures while preserving intentional live TLS smoke coverage.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review November 5, 2026 15:51
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

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:

Props shailu25, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@shail-mehta shail-mehta self-assigned this Nov 5, 2026

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this does what it says. With the network off, on current trunk (11418a6):

  • Tests_HTTP_curl runs 26 tests and passes in single site and multisite. test_ssl() still runs live in external-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.

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.

🟡 Changes recommended

The redirect hook’s argument-count mismatch causes uncaught ArgumentCountError failures, and the offline rewrite removes the assertion protecting CA-bundle regression coverage.

2 open issues

Review effort: Balanced

Comment thread tests/phpunit/tests/http/base.php Resolved
Comment thread tests/phpunit/tests/http/base.php Resolved

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.

🔵 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

@shail-mehta

Copy link
Copy Markdown
Member Author

Thanks @lancewillett - both changes are in:

  • Fixture-only exemption in WP_HTTP_UnitTestCase; abstract-testcase.php unchanged.
  • test_https_url_without_ssl_verification() now asserts Requests verify / verifyname and stops before connecting.

Also noted your point that the redirect guard is defensive - left it in place.

One follow-up from CI: the redirect callback needed add_action( ..., 10, 5 ) so same-fixture redirects don’t hit an ArgumentCountError. That’s fixed now.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.
@shail-mehta
shail-mehta requested a balanced review from Copilot November 6, 2026 15:55

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.

🟡 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

Comment thread tests/phpunit/tests/http/base.php Resolved
Use the global wp_remote_head() so the intentional capture error does not
sleep through retry_on_error().
@shail-mehta

Copy link
Copy Markdown
Member Author

Thanks @lancewillett!

  • Restored $http_request_args / filter_http_request_args() and assertNotEmpty( …['sslcertificates'] ) alongside the Requests option checks.

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.

🟢 Approval recommended

No active review issues remain in the changes moving cURL transport coverage to local fixtures while retaining intentional live TLS smoke coverage.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @shail-mehta, this is ready.

  • The restored sslcertificates assertion now catches an empty default CA bundle. I blanked the default in WP_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_ssl fails, since it needs network.
  • --group http: 262 tests, with the same 3 offline DNS failures as trunk.

AI review · claude-opus-5-5

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit that referenced this pull request Nov 6, 2026
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
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 6, 2026
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
arshidkv12 pushed a commit to arshidkv12/wordpress-develop that referenced this pull request Nov 21, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants