diff options
author | Andrew Dolgov <[email protected]> | 2023-12-29 04:38:59 +0000 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2023-12-29 04:38:59 +0000 |
commit | a882eb13f7ab36f4bab26a290a8e5ab1c6f2fb34 (patch) | |
tree | 8b5d02b95db25cd8b4487749ec27ed0602d9d7ca /tests | |
parent | 51cd02fc3e476f9e64311a87e0b84dbd16f5a44f (diff) | |
parent | 91a91dac15907bbd9bd773da9e5c6f0b7ff19f5a (diff) |
Merge branch 'feature/early-fail-disallowed-redirects' into 'master'
Perform validation of redirect URLs during the redirect process.
See merge request tt-rss/tt-rss!17
Diffstat (limited to 'tests')
-rw-r--r-- | tests/UrlHelperTest.php | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tests/UrlHelperTest.php b/tests/UrlHelperTest.php index 58960add0..825c71e8e 100644 --- a/tests/UrlHelperTest.php +++ b/tests/UrlHelperTest.php @@ -74,6 +74,7 @@ final class UrlHelperTest extends TestCase { $result = UrlHelper::fetch('https://www.example.com'); $this->assertEquals(200, UrlHelper::$fetch_last_error_code); $this->assertEquals('Hello, World', $result); + $mock->reset(); foreach (['ftp://ftp.example.com', 'http://127.0.0.1', 'blah', '', 42, null] as $url) { $result = UrlHelper::fetch($url); @@ -83,24 +84,25 @@ final class UrlHelperTest extends TestCase { $mock->append(new Response(200, ['Content-Length' => (string) PHP_INT_MAX])); $result = UrlHelper::fetch('https://www.example.com/very-large-content-length'); $this->assertFalse($result); + $mock->reset(); $mock->append(new Response(301, ['Location' => 'https://www.example.com'])); $result = UrlHelper::fetch(['url' => 'https://example.com', 'followlocation' => false]); $this->assertFalse($result); + $mock->reset(); - $mock->append( - new Response(301, ['Location' => 'http://127.0.0.1']), - new Response(200, [], 'Hello, World'), - ); + $mock->append(new Response(301, ['Location' => 'http://127.0.0.1'])); $result = UrlHelper::fetch(['url' => 'https://example.com', 'followlocation' => true]); $this->assertFalse($result); - $this->assertEquals('URL received after redirection failed extended validation.', UrlHelper::$fetch_last_error); + $this->assertMatchesRegularExpression('%failed extended validation%', UrlHelper::$fetch_last_error); $this->assertEquals('http://127.0.0.1', UrlHelper::$fetch_effective_url); + $mock->reset(); $mock->append(new Response(200, [], '')); $result = UrlHelper::fetch('https://www.example.com'); $this->assertFalse($result); $this->assertEquals('Successful response, but no content was received.', UrlHelper::$fetch_last_error); + $mock->reset(); // Fake a 403 for basic auth and success with `CURLAUTH_ANY` in the retry attempt $mock->append( @@ -116,5 +118,6 @@ final class UrlHelperTest extends TestCase { $this->assertEquals(200, UrlHelper::$fetch_last_error_code); $this->assertEquals('Hello, World', $result); $this->assertEquals($mock->getLastOptions()['curl'][\CURLOPT_HTTPAUTH], \CURLAUTH_ANY); + $mock->reset(); } } |