Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilteredIteratorTest: improve tests #550

Merged
merged 2 commits into from
Sep 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions tests/Utility/FilteredIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,25 @@
use WpOrg\Requests\Tests\TestCase;
use WpOrg\Requests\Utility\FilteredIterator;

/**
* @coversDefaultClass \WpOrg\Requests\Utility\FilteredIterator
*/
final class FilteredIteratorTest extends TestCase {

/**
* Tests against insecure deserialization of untrusted data.
*
* @link https://github.com/WordPress/Requests/security/advisories/GHSA-52qp-jpq7-6c54
*
* @covers ::unserialize
* @covers ::__unserialize
* @covers ::__wakeup
*
* @dataProvider dataSerializeDeserializeObjects
*
* @param \ArrayIterator $value Value to test with.
*
* @return void
*/
public function testDeserializeRequestUtilityFilteredIteratorObjects($value) {
$serialized = serialize($value);
Expand All @@ -19,18 +35,35 @@ public function testDeserializeRequestUtilityFilteredIteratorObjects($value) {
$property = $reflection->getProperty('callback');
$property->setAccessible(true);
$callback_value = $property->getValue($new_value);
$this->assertSame(null, $callback_value);
$this->assertNull($callback_value, 'Callback is not null');
} else {
$this->assertEquals($value->count(), unserialize($serialized)->count());
$this->assertSame(
$value->count(),
unserialize($serialized)->count(),
'Unserialized count is not equivalent'
);
}
}

/**
* Data provider.
*
* @return array
*/
public function dataSerializeDeserializeObjects() {
return array(
array(new FilteredIterator(array(1), 'md5')),
array(new FilteredIterator(array(1, 2), 'sha1')),
array(new FilteredIterator(array(1, 2, 3), 'doesnotexist')),
array(new ArrayIterator(array(1, 2, 3))),
'FilteredIterator object with one value, callback: md5' => array(
'value' => new FilteredIterator(array(1), 'md5'),
),
'FilteredIterator object with two values, callback: sha1' => array(
'value' => new FilteredIterator(array(1, 2), 'sha1'),
),
'FilteredIterator object with three values, non-existent callback' => array(
'value' => new FilteredIterator(array(1, 2, 3), 'doesnotexist'),
),
'ArrayIterator object with three values, no callback' => array(
'value' => new ArrayIterator(array(1, 2, 3)),
),
);
}
}