From 8197f74484a27044fd0148af0b2a88ff14e9d36d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 08:57:00 +0000 Subject: [PATCH 01/12] GH Actions: Bump ramsey/composer-install from 2 to 3 Bumps [ramsey/composer-install](https://github.com/ramsey/composer-install) from 2 to 3. - [Release notes](https://github.com/ramsey/composer-install/releases) - [Commits](https://github.com/ramsey/composer-install/compare/v2...v3) --- updated-dependencies: - dependency-name: ramsey/composer-install dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/cs.yml | 2 +- .github/workflows/lint.yml | 4 ++-- .github/workflows/quicktest.yml | 2 +- .github/workflows/test.yml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 1faee6110..8c0f9d6a7 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -32,7 +32,7 @@ jobs: # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 27359b0fb..ff425bce8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -41,7 +41,7 @@ jobs: # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - normal if: ${{ matrix.php != '8.4' }} - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") @@ -49,7 +49,7 @@ jobs: # For PHP "nightly", we need to install with ignore platform reqs. - name: Install Composer dependencies - with ignore platform if: ${{ matrix.php == '8.4' }} - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: composer-options: --ignore-platform-req=php custom-cache-suffix: $(date -u "+%Y-%m") diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 96526549c..c22044b52 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -48,7 +48,7 @@ jobs: # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - normal - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6a512fb5..4f8b85e00 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,7 +61,7 @@ jobs: # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - normal if: ${{ matrix.php != '8.4' }} - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") @@ -69,7 +69,7 @@ jobs: # For PHP "nightly", we need to install with ignore platform reqs. - name: Install Composer dependencies - with ignore platform if: ${{ matrix.php == '8.4' }} - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: composer-options: --ignore-platform-req=php custom-cache-suffix: $(date -u "+%Y-%m") From f189e19c0d0159db7d37ecafcc4cfc17121cf0d1 Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Mon, 25 Mar 2024 17:07:50 +0700 Subject: [PATCH 02/12] [PHP 8.4] Fixes for implicit nullability deprecation (#865) Co-authored-by: jrfnl --- src/Cookie.php | 8 +++++++- tests/Cookie/ParseTest.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Cookie.php b/src/Cookie.php index e9ad899b5..b4a38e617 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -491,13 +491,19 @@ public static function parse($cookie_header, $name = '', $reference_time = null) * @param \WpOrg\Requests\Iri|null $origin URI for comparing cookie origins * @param int|null $time Reference time for expiration calculation * @return array + * + * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $origin argument is not null or an instance of the Iri class. */ - public static function parse_from_headers(Headers $headers, Iri $origin = null, $time = null) { + public static function parse_from_headers(Headers $headers, $origin = null, $time = null) { $cookie_headers = $headers->getValues('Set-Cookie'); if (empty($cookie_headers)) { return []; } + if ($origin !== null && !($origin instanceof Iri)) { + throw InvalidArgument::create(2, '$origin', Iri::class . ' or null', gettype($origin)); + } + $cookies = []; foreach ($cookie_headers as $header) { $parsed = self::parse($header, '', $time); diff --git a/tests/Cookie/ParseTest.php b/tests/Cookie/ParseTest.php index 3e29dd713..068ba502b 100644 --- a/tests/Cookie/ParseTest.php +++ b/tests/Cookie/ParseTest.php @@ -76,6 +76,37 @@ public function testParseInvalidReferenceTime() { Cookie::parse('test', 'test', 'now'); } + /** + * Verify parsing of cookies fails with an exception if the $origin parameter is passed anything but `null` + * or an instance of Iri. + * + * @dataProvider dataParseFromHeadersInvalidOrigin + * + * @covers ::parse_from_headers + * + * @param mixed $input Invalid parameter input. + * + * @return void + */ + public function testParseFromHeadersInvalidOrigin($input) { + $this->expectException(InvalidArgument::class); + $this->expectExceptionMessage('Argument #2 ($origin) must be of type WpOrg\Requests\Iri or null'); + + $headers = new Headers(); + $headers['Set-Cookie'] = 'name=value'; + + Cookie::parse_from_headers($headers, $input); + } + + /** + * Data Provider. + * + * @return array + */ + public static function dataParseFromHeadersInvalidOrigin() { + return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_NULL); + } + /** * Tests receiving an exception when the parse_from_headers() method received an invalid input type as `$reference_time`. * From d7721ee41d78799a6d21a7af242c71222c0fe782 Mon Sep 17 00:00:00 2001 From: schlessera <83631+schlessera@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:08:04 +0000 Subject: [PATCH 03/12] :lock_with_ink_pen: Update certificate bundle --- certificates/cacert.pem | 51 ++++++++++++++++++++++++++++++++-- certificates/cacert.pem.sha256 | 2 +- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/certificates/cacert.pem b/certificates/cacert.pem index d8fda7d1a..f78a6101a 100644 --- a/certificates/cacert.pem +++ b/certificates/cacert.pem @@ -1,7 +1,7 @@ ## ## Bundle of CA Root Certificates ## -## Certificate data from Mozilla as of: Tue Dec 12 04:12:04 2023 GMT +## Certificate data from Mozilla as of: Mon Mar 11 15:25:27 2024 GMT ## ## This is a bundle of X.509 certificates of public Certificate Authorities ## (CA). These were automatically extracted from Mozilla's root certificates @@ -14,7 +14,7 @@ ## Just configure this file as the SSLCACertificateFile. ## ## Conversion done with mk-ca-bundle.pl version 1.29. -## SHA256: 1970dd65858925d68498d2356aea6d03f764422523c5887deca8ce3ba9e1f845 +## SHA256: 4d96bd539f4719e9ace493757afbe4a23ee8579de1c97fbebc50bba3c12e8c1e ## @@ -3532,3 +3532,50 @@ dVwPaFsdZcJfMw8eD/A7hvWwTruc9+olBdytoptLFwG+Qt81IR2tq670v64fG9PiO/yzcnMcmyiQ iRM9HcEARwmWmjgb3bHPDcK0RPOWlc4yOo80nOAXx17Org3bhzjlP1v9mxnhMUF6cKojawHhRUzN lM47ni3niAIi9G7oyOzWPPO5std3eqx7 -----END CERTIFICATE----- + +Telekom Security TLS ECC Root 2020 +================================== +-----BEGIN CERTIFICATE----- +MIICQjCCAcmgAwIBAgIQNjqWjMlcsljN0AFdxeVXADAKBggqhkjOPQQDAzBjMQswCQYDVQQGEwJE +RTEnMCUGA1UECgweRGV1dHNjaGUgVGVsZWtvbSBTZWN1cml0eSBHbWJIMSswKQYDVQQDDCJUZWxl +a29tIFNlY3VyaXR5IFRMUyBFQ0MgUm9vdCAyMDIwMB4XDTIwMDgyNTA3NDgyMFoXDTQ1MDgyNTIz +NTk1OVowYzELMAkGA1UEBhMCREUxJzAlBgNVBAoMHkRldXRzY2hlIFRlbGVrb20gU2VjdXJpdHkg +R21iSDErMCkGA1UEAwwiVGVsZWtvbSBTZWN1cml0eSBUTFMgRUNDIFJvb3QgMjAyMDB2MBAGByqG +SM49AgEGBSuBBAAiA2IABM6//leov9Wq9xCazbzREaK9Z0LMkOsVGJDZos0MKiXrPk/OtdKPD/M1 +2kOLAoC+b1EkHQ9rK8qfwm9QMuU3ILYg/4gND21Ju9sGpIeQkpT0CdDPf8iAC8GXs7s1J8nCG6NC +MEAwHQYDVR0OBBYEFONyzG6VmUex5rNhTNHLq+O6zd6fMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0P +AQH/BAQDAgEGMAoGCCqGSM49BAMDA2cAMGQCMHVSi7ekEE+uShCLsoRbQuHmKjYC2qBuGT8lv9pZ +Mo7k+5Dck2TOrbRBR2Diz6fLHgIwN0GMZt9Ba9aDAEH9L1r3ULRn0SyocddDypwnJJGDSA3PzfdU +ga/sf+Rn27iQ7t0l +-----END CERTIFICATE----- + +Telekom Security TLS RSA Root 2023 +================================== +-----BEGIN CERTIFICATE----- +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 +-----END CERTIFICATE----- diff --git a/certificates/cacert.pem.sha256 b/certificates/cacert.pem.sha256 index 05b5db785..58082bbd1 100644 --- a/certificates/cacert.pem.sha256 +++ b/certificates/cacert.pem.sha256 @@ -1 +1 @@ -ccbdfc2fe1a0d7bbbb9cc15710271acf1bb1afe4c8f1725fe95c4c7733fcbe5a cacert.pem +1794c1d4f7055b7d02c2170337b61b48a2ef6c90d77e95444fd2596f4cac609f cacert.pem From 31ba95ab69028213b396cb02b8eb94d721f05768 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 25 Mar 2024 10:46:02 +0100 Subject: [PATCH 04/12] Changelog for release 2.0.11 * Includes updating the version number constant. --- CHANGELOG.md | 19 ++++++++++++++++++- src/Requests.php | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db8658f1e..eeff843d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,22 @@ Changelog ========= +2.0.11 +------ + +### Overview of changes +- Update bundled certificates as of 2024-03-11. [#864] +- Fixed: PHP 8.4 deprecation of the two parameter signature of `stream_context_set_option()`. [#822] Props [@jrfnl][gh-jrfnl] +- Fixed: PHP 8.4 deprecation of implicitly nullable parameter. [#865] Props [@Ayesh][gh-ayesh], [@jrfnl][gh-jrfnl] + Note: this fix constitutes an, albeit small, breaking change to the signature of the `Cookie::parse_from_headers()` method. + Classes which extend the `Cookie` class and overload the `parse_from_headers()` method should be updated for the new method signature. + Additionally, if code calling the `Cookie::parse_from_headers()` method would be wrapped in a `try - catch` to catch a potential PHP `TypeError` (PHP 7.0+) or `Exception` (PHP < 7.0) for when invalid data was passed as the `$origin` parameter, this code will need to be updated to now also catch a potential `WpOrg\Requests\Exception\InvalidArgumentException`. + As due diligence could not find any classes which would be affected by this BC-break, we have deemed it acceptable to include this fix in the 2.0.11 release. + +[#822]: https://github.com/WordPress/Requests/pull/822 +[#864]: https://github.com/WordPress/Requests/pull/864 +[#865]: https://github.com/WordPress/Requests/pull/865 + 2.0.10 ------ @@ -96,7 +112,7 @@ Changelog - Docs: the Hook documentation has been updated to reflect the current available hooks. [#646] - General housekeeping. [#635], [#649], [#650], [#653], [#655], [#658], [#660], [#661], [#662], [#669], [#671], [#672], [#674] -Props [@alpipego][gh-alpipego], [@costdev][gh-costdev], [@jegrandet][gh-jegrandet] [@jrfnl][gh-jrfnl], [@schlessera][gh-schlessera] +Props [@alpipego][gh-alpipego], [@costdev][gh-costdev], [@jegrandet][gh-jegrandet], [@jrfnl][gh-jrfnl], [@schlessera][gh-schlessera] [#674]: https://github.com/WordPress/Requests/pull/674 [#672]: https://github.com/WordPress/Requests/pull/672 @@ -1014,6 +1030,7 @@ Initial release! [gh-adri]: https://github.com/adri [gh-alpipego]: https://github.com/alpipego/ [gh-amandato]: https://github.com/amandato +[gh-ayesh]: https://github.com/Ayesh [gh-beutnagel]: https://github.com/beutnagel [gh-carlalexander]: https://github.com/carlalexander [gh-catharsisjelly]: https://github.com/catharsisjelly diff --git a/src/Requests.php b/src/Requests.php index 9390800b6..ba3d286b2 100644 --- a/src/Requests.php +++ b/src/Requests.php @@ -146,7 +146,7 @@ class Requests { * * @var string */ - const VERSION = '2.0.10'; + const VERSION = '2.0.11'; /** * Selected transport name From 5d54c398cc5c6467a79ab7b0f42e3f258f7589d8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 3 Jun 2024 11:46:59 +0200 Subject: [PATCH 05/12] CS: always clarify operator precedence when mixing boolean operators --- src/IdnaEncoder.php | 12 ++++++------ src/Ipv6.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/IdnaEncoder.php b/src/IdnaEncoder.php index 209531887..d79846a83 100644 --- a/src/IdnaEncoder.php +++ b/src/IdnaEncoder.php @@ -223,18 +223,18 @@ protected static function utf8_to_codepoints($input) { } if (// Non-shortest form sequences are invalid - $length > 1 && $character <= 0x7F - || $length > 2 && $character <= 0x7FF - || $length > 3 && $character <= 0xFFFF + ($length > 1 && $character <= 0x7F) + || ($length > 2 && $character <= 0x7FF) + || ($length > 3 && $character <= 0xFFFF) // Outside of range of ucschar codepoints // Noncharacters || ($character & 0xFFFE) === 0xFFFE - || $character >= 0xFDD0 && $character <= 0xFDEF + || ($character >= 0xFDD0 && $character <= 0xFDEF) || ( // Everything else not in ucschar - $character > 0xD7FF && $character < 0xF900 + ($character > 0xD7FF && $character < 0xF900) || $character < 0x20 - || $character > 0x7E && $character < 0xA0 + || ($character > 0x7E && $character < 0xA0) || $character > 0xEFFFD ) ) { diff --git a/src/Ipv6.php b/src/Ipv6.php index a45ce0759..ab88a700a 100644 --- a/src/Ipv6.php +++ b/src/Ipv6.php @@ -163,7 +163,7 @@ public static function check_ipv6($ip) { list($ipv6, $ipv4) = self::split_v6_v4($ip); $ipv6 = explode(':', $ipv6); $ipv4 = explode('.', $ipv4); - if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) { + if ((count($ipv6) === 8 && count($ipv4) === 1) || (count($ipv6) === 6 && count($ipv4) === 4)) { foreach ($ipv6 as $ipv6_part) { // The section can't be empty if ($ipv6_part === '') { From 75916e53ab604a7c1ba5ba4108bb04bf8b6769fc Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 3 Jun 2024 11:35:55 +0200 Subject: [PATCH 06/12] Tests: fix PHPUnit deprecation notices [1] Removes the key from the entries returned by the `TypeProviderHelper` methods. This puts the responsibility for having names for the individual entries in each dataset on the data provider methods in the tests (if so desired). This prevents the `TypeProviderHelper` class having influence on what the parameter names for test methods should be. This fixes a number of PHPUnit (10.5+) deprecation notices along the lines of "Providing invalid named argument $input for method WpOrg\Requests\Tests\*\*Test::test*() is deprecated and will not be supported in PHPUnit 11.0.". Includes minor documentation fix for the affected methods in the `TypeProviderHelper` class. --- tests/Cookie/NormalizeTest.php | 6 +- tests/Cookie/PathMatchesTest.php | 6 +- tests/Response/IsRedirectTest.php | 2 +- tests/TypeProviderHelper.php | 98 ++++++++----------------------- 4 files changed, 33 insertions(+), 79 deletions(-) diff --git a/tests/Cookie/NormalizeTest.php b/tests/Cookie/NormalizeTest.php index 7a4c74eac..489110e8c 100644 --- a/tests/Cookie/NormalizeTest.php +++ b/tests/Cookie/NormalizeTest.php @@ -282,7 +282,7 @@ public static function dataNormalizeAttributesExpiresUnsupportedType() { foreach ($types as $key => $value) { $data['Attribute normalization: expires: unsupported type - ' . $key] = [ 'attributes' => [ - 'expires' => $value['input'], + 'expires' => $value[0], ], 'expected' => [], ]; @@ -303,7 +303,7 @@ public static function dataNormalizeAttributesMaxAgeUnsupportedType() { foreach ($types as $key => $value) { $data['Attribute normalization: max-age: unsupported type - ' . $key] = [ 'attributes' => [ - 'max-age' => $value['input'], + 'max-age' => $value[0], ], 'expected' => [], ]; @@ -324,7 +324,7 @@ public static function dataNormalizeAttributesDomainUnsupportedType() { foreach ($types as $key => $value) { $data['Attribute normalization: domain: unsupported type - ' . $key] = [ 'attributes' => [ - 'domain' => $value['input'], + 'domain' => $value[0], ], 'expected' => [], ]; diff --git a/tests/Cookie/PathMatchesTest.php b/tests/Cookie/PathMatchesTest.php index 8faa2d44d..9c6e0725a 100644 --- a/tests/Cookie/PathMatchesTest.php +++ b/tests/Cookie/PathMatchesTest.php @@ -79,13 +79,13 @@ public static function dataPathMatchUndesiredInputTypes() { if (in_array($key, TypeProviderHelper::GROUP_EMPTY, true)) { $data['Match: "/" vs ' . $key] = [ 'original' => '/', - 'check' => $value['input'], + 'check' => $value[0], 'matches' => true, ]; $data['Non-match: "/test" vs ' . $key] = [ 'original' => '/test', - 'check' => $value['input'], + 'check' => $value[0], 'matches' => false, ]; @@ -98,7 +98,7 @@ public static function dataPathMatchUndesiredInputTypes() { */ $data['Non-match: "/" vs ' . $key] = [ 'original' => '/', - 'check' => $value['input'], + 'check' => $value[0], 'matches' => false, ]; } diff --git a/tests/Response/IsRedirectTest.php b/tests/Response/IsRedirectTest.php index 58c69e4e0..af8be667d 100644 --- a/tests/Response/IsRedirectTest.php +++ b/tests/Response/IsRedirectTest.php @@ -93,7 +93,7 @@ public static function dataNotRedirect() { $except[] = 'boolean false'; // No need to double test `false`. $invalid = TypeProviderHelper::getAllExcept($except); foreach ($invalid as $key => $type) { - $data['Invalid status code: ' . $key] = [$type['input']]; + $data['Invalid status code: ' . $key] = [$type[0]]; } return $data; diff --git a/tests/TypeProviderHelper.php b/tests/TypeProviderHelper.php index c686ba53a..83029433a 100644 --- a/tests/TypeProviderHelper.php +++ b/tests/TypeProviderHelper.php @@ -202,7 +202,7 @@ public static function cleanUp() { * Typically, one or more of the predefined "groups" (see the constants) * would be used here. * - * @return array + * @return array> */ public static function getAllExcept(array ...$except) { $except = array_flip(array_merge(...$except)); @@ -217,7 +217,7 @@ public static function getAllExcept(array ...$except) { * Typically, one or more of the predefined "groups" (see the constants) * would be used here. * - * @return array + * @return array> */ public static function getSelection(array ...$selection) { $selection = array_flip(array_merge(...$selection)); @@ -228,7 +228,7 @@ public static function getSelection(array ...$selection) { /** * Retrieve an array in data provider format with all typical PHP data types. * - * @return array + * @return array> */ public static function getAll() { if (isset(self::$memory_handle_open) === false) { @@ -241,75 +241,29 @@ public static function getAll() { } return [ - 'null' => [ - 'input' => null, - ], - 'boolean false' => [ - 'input' => false, - ], - 'boolean true' => [ - 'input' => true, - ], - 'integer 0' => [ - 'input' => 0, - ], - 'negative integer' => [ - 'input' => -123, - ], - 'positive integer' => [ - 'input' => 786687, - ], - 'float 0.0' => [ - 'input' => 0.0, - ], - 'negative float' => [ - 'input' => 5.600e-3, - ], - 'positive float' => [ - 'input' => 124.7, - ], - 'empty string' => [ - 'input' => '', - ], - 'numeric string' => [ - 'input' => '123', - ], - 'textual string' => [ - 'input' => 'foobar', - ], - 'textual string starting with numbers' => [ - 'input' => '123 My Street', - ], - 'empty array' => [ - 'input' => [], - ], - 'array with values, no keys' => [ - 'input' => [1, 2, 3], - ], - 'array with values, string keys' => [ - 'input' => ['a' => 1, 'b' => 2], - ], - 'plain object' => [ - 'input' => new stdClass(), - ], - 'Stringable object' => [ - 'input' => new StringableObject('value'), - ], - 'ArrayIterator object' => [ - 'input' => new ArrayIterator([1, 2, 3]), - ], - 'ArrayAccess object' => [ - 'input' => new ArrayAccessibleObject(), - ], - 'Iterator object, no array access' => [ - 'input' => new EmptyIterator(), - ], - 'resource (open file handle)' => [ - 'input' => self::$memory_handle_open, - ], - 'resource (closed file handle)' => [ - 'input' => self::$memory_handle_closed, - ], + 'null' => [null], + 'boolean false' => [false], + 'boolean true' => [true], + 'integer 0' => [0], + 'negative integer' => [-123], + 'positive integer' => [786687], + 'float 0.0' => [0.0], + 'negative float' => [5.600e-3], + 'positive float' => [124.7], + 'empty string' => [''], + 'numeric string' => ['123'], + 'textual string' => ['foobar'], + 'textual string starting with numbers' => ['123 My Street'], + 'empty array' => [[]], + 'array with values, no keys' => [[1, 2, 3]], + 'array with values, string keys' => [['a' => 1, 'b' => 2]], + 'plain object' => [new stdClass()], + 'Stringable object' => [new StringableObject('value')], + 'ArrayIterator object' => [new ArrayIterator([1, 2, 3])], + 'ArrayAccess object' => [new ArrayAccessibleObject()], + 'Iterator object, no array access' => [new EmptyIterator()], + 'resource (open file handle)' => [self::$memory_handle_open], + 'resource (closed file handle)' => [self::$memory_handle_closed], ]; } } From 39f55067054de73e2f5f8d98476d15f22df15d9a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 3 Jun 2024 11:36:49 +0200 Subject: [PATCH 07/12] Tests: fix PHPUnit deprecation notices [2] Ensure the keys in datasets match the parameter names of the test methods to which the datasets are being passed. This fixes a number of PHPUnit (10.5+) deprecation notices along the lines of "Providing invalid named argument $input for method WpOrg\Requests\Tests\*\*Test::test*() is deprecated and will not be supported in PHPUnit 11.0.". --- tests/Cookie/UriMatchesTest.php | 28 ++++++++++++------------- tests/Exception/Http/StatusCodeTest.php | 14 ++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/Cookie/UriMatchesTest.php b/tests/Cookie/UriMatchesTest.php index 749b7e9a9..6890ac052 100644 --- a/tests/Cookie/UriMatchesTest.php +++ b/tests/Cookie/UriMatchesTest.php @@ -75,28 +75,28 @@ public static function dataUrlMatch() { 'domain' => 'example.com', 'path' => '/', 'check' => 'http://example.com/', - 'matched' => true, + 'matches' => true, 'domain_matches' => true, ], 'Domain handling: same domain name, same TLD, different subdomain' => [ 'domain' => 'example.com', 'path' => '/', 'check' => 'http://www.example.com/', - 'matched' => false, + 'matches' => false, 'domain_matches' => true, ], 'Domain handling: same domain name, different TLD' => [ 'domain' => 'example.com', 'path' => '/', 'check' => 'http://example.net/', - 'matched' => false, + 'matches' => false, 'domain_matches' => false, ], 'Domain handling: same domain name, different TLD, different subdomain' => [ 'domain' => 'example.com', 'path' => '/', 'check' => 'http://www.example.net/', - 'matched' => false, + 'matches' => false, 'domain_matches' => false, ], @@ -105,14 +105,14 @@ public static function dataUrlMatch() { 'domain' => 'example.com', 'path' => '/test', 'check' => 'http://example.com/', - 'matched' => false, + 'matches' => false, 'domain_matches' => false, ], 'Path handling "/test": same domain name, same TLD, different subdomain, URI provided without path' => [ 'domain' => 'example.com', 'path' => '/test', 'check' => 'http://www.example.com/', - 'matched' => false, + 'matches' => false, 'domain_matches' => false, ], @@ -120,14 +120,14 @@ public static function dataUrlMatch() { 'domain' => 'example.com', 'path' => '/test', 'check' => 'http://example.com/test', - 'matched' => true, + 'matches' => true, 'domain_matches' => true, ], 'Path handling "/test": same domain name, same TLD, different subdomain, URI provided including path' => [ 'domain' => 'example.com', 'path' => '/test', 'check' => 'http://www.example.com/test', - 'matched' => false, + 'matches' => false, 'domain_matches' => true, ], @@ -135,14 +135,14 @@ public static function dataUrlMatch() { 'domain' => 'example.com', 'path' => '/test', 'check' => 'http://example.com/testing', - 'matched' => false, + 'matches' => false, 'domain_matches' => false, ], 'Path handling "/test": same domain name, same TLD, different subdomain, different path' => [ 'domain' => 'example.com', 'path' => '/test', 'check' => 'http://www.example.com/testing', - 'matched' => false, + 'matches' => false, 'domain_matches' => false, ], @@ -150,14 +150,14 @@ public static function dataUrlMatch() { 'domain' => 'example.com', 'path' => '/test', 'check' => 'http://example.com/test/', - 'matched' => true, + 'matches' => true, 'domain_matches' => true, ], 'Path handling "/test": same domain name, same TLD, different subdomain, URI provided including path with trailing slash' => [ 'domain' => 'example.com', 'path' => '/test', 'check' => 'http://www.example.com/test/', - 'matched' => false, + 'matches' => false, 'domain_matches' => true, ], @@ -166,14 +166,14 @@ public static function dataUrlMatch() { 'domain' => 'example.com', 'path' => '/test/', 'check' => 'http://example.com/', - 'matched' => false, + 'matches' => false, 'domain_matches' => false, ], 'Path handling "/test/" (incl trailing slash): same domain name, same TLD, different subdomain, URI provided without path' => [ 'domain' => 'example.com', 'path' => '/test/', 'check' => 'http://www.example.com/', - 'matched' => false, + 'matches' => false, 'domain_matches' => false, ], ]; diff --git a/tests/Exception/Http/StatusCodeTest.php b/tests/Exception/Http/StatusCodeTest.php index 28af67b78..62c993870 100644 --- a/tests/Exception/Http/StatusCodeTest.php +++ b/tests/Exception/Http/StatusCodeTest.php @@ -88,19 +88,19 @@ public static function dataUnknownStatusCodes() { return [ 'null (or not passed)' => [ - 'expectedCode' => 0, + 'expected_code' => 0, ], 'integer error code as data' => [ - 'expectedCode' => 0, - 'data' => 507, + 'expected_code' => 0, + 'data' => 507, ], 'Response object with status code' => [ - 'expectedCode' => 12345, - 'data' => $response_with_status, + 'expected_code' => 12345, + 'data' => $response_with_status, ], 'Response object without status code' => [ - 'expectedCode' => 0, - 'data' => $response_without_status, + 'expected_code' => 0, + 'data' => $response_without_status, ], ]; } From 1f45ea4d3bb2fb24cefd9a4d9f1da4dbd36d223a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 3 Jun 2024 11:39:45 +0200 Subject: [PATCH 08/12] Tests: fix PHPUnit deprecation notices [3] Make sure data providers only pass the arguments supported by the test. This fixes a number of PHPUnit (10.5+) deprecation notices along the lines of "Providing invalid named argument $* for method WpOrg\Requests\Tests\*\*Test::test*() is deprecated and will not be supported in PHPUnit 11.0.". --- tests/Cookie/Jar/NormalizeCookieTest.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/Cookie/Jar/NormalizeCookieTest.php b/tests/Cookie/Jar/NormalizeCookieTest.php index f90afb9d8..6c9fb3a9e 100644 --- a/tests/Cookie/Jar/NormalizeCookieTest.php +++ b/tests/Cookie/Jar/NormalizeCookieTest.php @@ -16,7 +16,7 @@ final class NormalizeCookieTest extends TestCase { /** * Verify that cookie normalization works on both prebaked and unbaked cookies when not passing a key. * - * @dataProvider dataNormalization + * @dataProvider dataNormalizationWithoutKey * * @param mixed $cookie Cookie header value, possibly pre-parsed (object). * @@ -30,10 +30,25 @@ public function testNormalizationWithoutKey($cookie) { $this->assertSame(self::COOKIE_VALUE, (string) $result, 'Cookie value is not the expected value'); } + /** + * Data provider. + * + * @return array + */ + public static function dataNormalizationWithoutKey() { + $data = self::dataNormalizationWithKey(); + + foreach ($data as $set_name => $set_value) { + unset($data[$set_name]['expected_name']); + } + + return $data; + } + /** * Verify that cookie normalization works on both prebaked and unbaked cookies when passing a key. * - * @dataProvider dataNormalization + * @dataProvider dataNormalizationWithKey * * @param mixed $cookie Cookie header value, possibly pre-parsed (object). * @@ -55,7 +70,7 @@ public function testNormalizationWithKey($cookie, $expected_name) { * * @return array */ - public static function dataNormalization() { + public static function dataNormalizationWithKey() { return [ 'unbaked cookie (string)' => [ 'cookie' => self::COOKIE_VALUE, From 8bc7a621634c6145748585041d44271bc9c2e2db Mon Sep 17 00:00:00 2001 From: Shane Bishop Date: Sat, 2 Dec 2023 10:38:31 -0700 Subject: [PATCH 09/12] Allow integers as cookie names Modify data validation checks, exception messages, and docblocks to allow cookie names to be integers. This affects both the constructor and the parse() method. Also modified unit tests to allow strings and integers, and to validate the updated exception messages. --- src/Cookie.php | 18 +++++++++--------- tests/Cookie/ConstructorTest.php | 13 +++++++++++-- tests/Cookie/ParseTest.php | 17 +++++++++++++---- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/Cookie.php b/src/Cookie.php index b4a38e617..5069ae1c1 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -67,7 +67,7 @@ class Cookie { /** * Create a new cookie object * - * @param string $name The name of the cookie. + * @param int|string $name The name of the cookie. * @param string $value The value for the cookie. * @param array|\WpOrg\Requests\Utility\CaseInsensitiveDictionary $attributes Associative array of attribute data * @param array $flags The flags for the cookie. @@ -82,8 +82,8 @@ class Cookie { * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $reference_time argument is not an integer or null. */ public function __construct($name, $value, $attributes = [], $flags = [], $reference_time = null) { - if (is_string($name) === false) { - throw InvalidArgument::create(1, '$name', 'string', gettype($name)); + if (is_int($name) === false && is_string($name) === false) { + throw InvalidArgument::create(1, '$name', 'integer|string', gettype($name)); } if (is_string($value) === false) { @@ -102,7 +102,7 @@ public function __construct($name, $value, $attributes = [], $flags = [], $refer throw InvalidArgument::create(5, '$reference_time', 'integer|null', gettype($reference_time)); } - $this->name = $name; + $this->name = (string) $name; $this->value = $value; $this->attributes = $attributes; $default_flags = [ @@ -426,9 +426,9 @@ public function format_for_set_cookie() { * is an intentional deviation from RFC 2109 and RFC 2616. RFC 6265 * specifies some of this handling, but not in a thorough manner. * - * @param string $cookie_header Cookie header value (from a Set-Cookie header) - * @param string $name - * @param int|null $reference_time + * @param int|string $cookie_header Cookie header value (from a Set-Cookie header) + * @param string $name + * @param int|null $reference_time * @return \WpOrg\Requests\Cookie Parsed cookie object * * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $cookie_header argument is not a string. @@ -439,8 +439,8 @@ public static function parse($cookie_header, $name = '', $reference_time = null) throw InvalidArgument::create(1, '$cookie_header', 'string', gettype($cookie_header)); } - if (is_string($name) === false) { - throw InvalidArgument::create(2, '$name', 'string', gettype($name)); + if (is_int($name) === false && is_string($name) === false) { + throw InvalidArgument::create(2, '$name', 'integer|string', gettype($name)); } $parts = explode(';', $cookie_header); diff --git a/tests/Cookie/ConstructorTest.php b/tests/Cookie/ConstructorTest.php index 0d4d6d0cf..9e76eeb6b 100644 --- a/tests/Cookie/ConstructorTest.php +++ b/tests/Cookie/ConstructorTest.php @@ -16,7 +16,7 @@ final class ConstructorTest extends TestCase { /** * Tests receiving an exception when the constructor received an invalid input type as `$name`. * - * @dataProvider dataInvalidStringInput + * @dataProvider dataInvalidName * * @param mixed $input Invalid parameter input. * @@ -24,11 +24,20 @@ final class ConstructorTest extends TestCase { */ public function testInvalidName($input) { $this->expectException(InvalidArgument::class); - $this->expectExceptionMessage('Argument #1 ($name) must be of type string'); + $this->expectExceptionMessage('Argument #1 ($name) must be of type integer|string'); new Cookie($input, 'value'); } + /** + * Data Provider. + * + * @return array + */ + public static function dataInvalidName() { + return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT,TypeProviderHelper::GROUP_STRING); + } + /** * Tests receiving an exception when the constructor received an invalid input type as `$value`. * diff --git a/tests/Cookie/ParseTest.php b/tests/Cookie/ParseTest.php index 068ba502b..e9da483a9 100644 --- a/tests/Cookie/ParseTest.php +++ b/tests/Cookie/ParseTest.php @@ -32,10 +32,19 @@ public function testParseInvalidCookieHeader($input) { Cookie::parse($input); } + /** + * Data Provider. + * + * @return array + */ + public static function dataInvalidStringInput() { + return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); + } + /** * Tests receiving an exception when the parse() method received an invalid input type as `$name`. * - * @dataProvider dataInvalidStringInput + * @dataProvider dataParseInvalidName * * @covers ::parse * @@ -45,7 +54,7 @@ public function testParseInvalidCookieHeader($input) { */ public function testParseInvalidName($input) { $this->expectException(InvalidArgument::class); - $this->expectExceptionMessage('Argument #2 ($name) must be of type string'); + $this->expectExceptionMessage('Argument #2 ($name) must be of type integer|string'); Cookie::parse('test', $input); } @@ -55,8 +64,8 @@ public function testParseInvalidName($input) { * * @return array */ - public static function dataInvalidStringInput() { - return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_STRING); + public static function dataParseInvalidName() { + return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT,TypeProviderHelper::GROUP_STRING); } /** From bd7cb6952faa16144216ae1b5698c211854f8f8a Mon Sep 17 00:00:00 2001 From: Shane Bishop Date: Fri, 16 Feb 2024 13:28:12 -0700 Subject: [PATCH 10/12] use RFC 2616 input validator Updated the Cookie token/name validation to use the new InputValidator::is_valid_rfc2616_token() method, updated the exception messages, and modified the test cases to look for the updated exceptions. --- src/Cookie.php | 10 +++++----- tests/Cookie/ConstructorTest.php | 4 ++-- tests/Cookie/ParseTest.php | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Cookie.php b/src/Cookie.php index 5069ae1c1..922861e95 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -75,15 +75,15 @@ class Cookie { * `'persistent'` and `'host-only'`. * @param int|null $reference_time Reference time for relative calculations. * - * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $name argument is not a string. + * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $name argument is not an integer or string that conforms to RFC 2616. * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $value argument is not a string. * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $attributes argument is not an array or iterable object with array access. * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $flags argument is not an array. * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $reference_time argument is not an integer or null. */ public function __construct($name, $value, $attributes = [], $flags = [], $reference_time = null) { - if (is_int($name) === false && is_string($name) === false) { - throw InvalidArgument::create(1, '$name', 'integer|string', gettype($name)); + if (InputValidator::is_valid_rfc2616_token($name) === false) { + throw InvalidArgument::create(1, '$name', 'integer|string and conform to RFC 2616', gettype($name)); } if (is_string($value) === false) { @@ -439,8 +439,8 @@ public static function parse($cookie_header, $name = '', $reference_time = null) throw InvalidArgument::create(1, '$cookie_header', 'string', gettype($cookie_header)); } - if (is_int($name) === false && is_string($name) === false) { - throw InvalidArgument::create(2, '$name', 'integer|string', gettype($name)); + if (InputValidator::is_valid_rfc2616_token($name) === false) { + throw InvalidArgument::create(2, '$name', 'integer|string and conform to RFC 2616', gettype($name)); } $parts = explode(';', $cookie_header); diff --git a/tests/Cookie/ConstructorTest.php b/tests/Cookie/ConstructorTest.php index 9e76eeb6b..02808ed63 100644 --- a/tests/Cookie/ConstructorTest.php +++ b/tests/Cookie/ConstructorTest.php @@ -24,7 +24,7 @@ final class ConstructorTest extends TestCase { */ public function testInvalidName($input) { $this->expectException(InvalidArgument::class); - $this->expectExceptionMessage('Argument #1 ($name) must be of type integer|string'); + $this->expectExceptionMessage('Argument #1 ($name) must be of type integer|string and conform to RFC 2616'); new Cookie($input, 'value'); } @@ -35,7 +35,7 @@ public function testInvalidName($input) { * @return array */ public static function dataInvalidName() { - return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT,TypeProviderHelper::GROUP_STRING); + return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, TypeProviderHelper::GROUP_STRING); } /** diff --git a/tests/Cookie/ParseTest.php b/tests/Cookie/ParseTest.php index e9da483a9..7b5df7666 100644 --- a/tests/Cookie/ParseTest.php +++ b/tests/Cookie/ParseTest.php @@ -54,7 +54,7 @@ public static function dataInvalidStringInput() { */ public function testParseInvalidName($input) { $this->expectException(InvalidArgument::class); - $this->expectExceptionMessage('Argument #2 ($name) must be of type integer|string'); + $this->expectExceptionMessage('Argument #2 ($name) must be of type integer|string and conform to RFC 2616'); Cookie::parse('test', $input); } @@ -65,7 +65,7 @@ public function testParseInvalidName($input) { * @return array */ public static function dataParseInvalidName() { - return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT,TypeProviderHelper::GROUP_STRING); + return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, TypeProviderHelper::GROUP_STRING); } /** From 71a266899e4086b2f97fa33ab63fb794994482af Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 3 Jun 2024 12:33:40 +0200 Subject: [PATCH 11/12] Allow for empty cookie $name when checking for validity --- src/Cookie.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Cookie.php b/src/Cookie.php index 922861e95..3cc0efcd4 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -82,7 +82,7 @@ class Cookie { * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $reference_time argument is not an integer or null. */ public function __construct($name, $value, $attributes = [], $flags = [], $reference_time = null) { - if (InputValidator::is_valid_rfc2616_token($name) === false) { + if ($name !== '' && InputValidator::is_valid_rfc2616_token($name) === false) { throw InvalidArgument::create(1, '$name', 'integer|string and conform to RFC 2616', gettype($name)); } @@ -439,7 +439,11 @@ public static function parse($cookie_header, $name = '', $reference_time = null) throw InvalidArgument::create(1, '$cookie_header', 'string', gettype($cookie_header)); } - if (InputValidator::is_valid_rfc2616_token($name) === false) { + if (is_string($name)) { + $name = trim($name); + } + + if ($name !== '' && InputValidator::is_valid_rfc2616_token($name) === false) { throw InvalidArgument::create(2, '$name', 'integer|string and conform to RFC 2616', gettype($name)); } @@ -463,6 +467,10 @@ public static function parse($cookie_header, $name = '', $reference_time = null) $name = trim($name); $value = trim($value); + if ($name !== '' && InputValidator::is_valid_rfc2616_token($name) === false) { + throw InvalidArgument::create(2, '$name', 'integer|string and conform to RFC 2616', gettype($name)); + } + // Attribute keys are handled case-insensitively $attributes = new CaseInsensitiveDictionary(); From bb82ab043cd9ab891da1256010c2e159f1b31dbe Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 3 Jun 2024 13:05:42 +0200 Subject: [PATCH 12/12] Cookie: allow for integers - improve tests The tests did now test that anything but integers as well as strings were rejected, but did not test that an input with a valid type, but an invalid value was also rejected. Fixed now. --- tests/Cookie/ConstructorTest.php | 4 +++- tests/Cookie/ParseTest.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Cookie/ConstructorTest.php b/tests/Cookie/ConstructorTest.php index 02808ed63..4c1010df4 100644 --- a/tests/Cookie/ConstructorTest.php +++ b/tests/Cookie/ConstructorTest.php @@ -35,7 +35,9 @@ public function testInvalidName($input) { * @return array */ public static function dataInvalidName() { - return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, TypeProviderHelper::GROUP_STRING); + $data = TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, TypeProviderHelper::GROUP_STRING); + $data['Valid string, but not a valid RFC 2616 token'] = ["some\ntext\rwith\tcontrol\echaracters\fin\vit"]; + return $data; } /** diff --git a/tests/Cookie/ParseTest.php b/tests/Cookie/ParseTest.php index 7b5df7666..a47e6c69b 100644 --- a/tests/Cookie/ParseTest.php +++ b/tests/Cookie/ParseTest.php @@ -65,7 +65,9 @@ public function testParseInvalidName($input) { * @return array */ public static function dataParseInvalidName() { - return TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, TypeProviderHelper::GROUP_STRING); + $data = TypeProviderHelper::getAllExcept(TypeProviderHelper::GROUP_INT, TypeProviderHelper::GROUP_STRING); + $data['Valid string, but not a valid RFC 2616 token'] = ["some\ntext\rwith\tcontrol\echaracters\fin\vit"]; + return $data; } /**