HTTP: Add support for the host-only flag to Wp_Http_Cookie.

Props soulseekah.
Fixes #43231.


git-svn-id: https://develop.svn.wordpress.org/trunk@45135 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2019-04-08 05:31:35 +00:00
parent 11e97aae1e
commit 3652d05fcf
4 changed files with 49 additions and 13 deletions

View File

@@ -199,4 +199,29 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
$this->assertSame( 'test', $cookie->name );
$this->assertSame( 'foo', $cookie->value );
}
/**
* @ticket 43231
*/
function test_get_cookie_host_only() {
// emulate WP_Http::request() internals
$requests_response = new Requests_Response();
$requests_response->cookies['test'] = Requests_Cookie::parse( 'test=foo; domain=.wordpress.org' );
$requests_response->cookies['test']->flags['host-only'] = false; // https://github.com/rmccue/Requests/issues/306
$http_response = new WP_HTTP_Requests_Response( $requests_response );
$response = $http_response->to_array();
// check the host_only flag in the resulting WP_Http_Cookie
$cookie = wp_remote_retrieve_cookie( $response, 'test' );
$this->assertEquals( $cookie->domain, 'wordpress.org' );
$this->assertFalse( $cookie->host_only, 'host-only flag not set' );
// regurgitate (Requests_Cookie -> WP_Http_Cookie -> Requests_Cookie)
$cookies = WP_Http::normalize_cookies( wp_remote_retrieve_cookies( $response ) );
$this->assertFalse( $cookies['test']->flags['host-only'], 'host-only flag data lost' );
}
}