diff options
Diffstat (limited to 'tests/lib/Http/Client/ClientTest.php')
-rw-r--r-- | tests/lib/Http/Client/ClientTest.php | 140 |
1 files changed, 59 insertions, 81 deletions
diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index 9c5bf1a6eb2..e76b66b52d7 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -66,16 +66,16 @@ class ClientTest extends \Test\TestCase { public function testGetProxyUriProxyHostEmptyPassword(): void { $this->config ->method('getSystemValue') - ->will($this->returnValueMap([ + ->willReturnMap([ ['proxyexclude', [], []], - ])); + ]); $this->config ->method('getSystemValueString') - ->will($this->returnValueMap([ + ->willReturnMap([ ['proxy', '', 'foo'], ['proxyuserpwd', '', ''], - ])); + ]); $this->assertEquals([ 'http' => 'foo', @@ -92,14 +92,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueString') - ->withConsecutive( - ['proxy', ''], - ['proxyuserpwd', ''], - ) - ->willReturnOnConsecutiveCalls( - 'foo', - 'username:password', - ); + ->willReturnMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', 'username:password'], + ]); $this->assertEquals([ 'http' => 'username:password@foo', 'https' => 'username:password@foo' @@ -115,14 +111,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueString') - ->withConsecutive( - ['proxy', ''], - ['proxyuserpwd', ''], - ) - ->willReturnOnConsecutiveCalls( - 'foo', - 'username:password', - ); + ->willReturnMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', 'username:password'], + ]); $this->assertEquals([ 'http' => 'username:password@foo', 'https' => 'username:password@foo', @@ -130,7 +122,14 @@ class ClientTest extends \Test\TestCase { ], self::invokePrivate($this->client, 'getProxyUri')); } - public function dataPreventLocalAddress():array { + public function testPreventLocalAddressThrowOnInvalidUri(): void { + $this->expectException(LocalServerException::class); + $this->expectExceptionMessage('Could not detect any host'); + + self::invokePrivate($this->client, 'preventLocalAddress', ['!@#$', []]); + } + + public static function dataPreventLocalAddress(): array { return [ ['https://localhost/foo.bar'], ['https://localHost/foo.bar'], @@ -146,16 +145,15 @@ class ClientTest extends \Test\TestCase { ['https://10.0.0.1'], ['https://another-host.local'], ['https://service.localhost'], - ['!@#$', true], // test invalid url ['https://normal.host.com'], ['https://com.one-.nextcloud-one.com'], ]; } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressDisabledByGlobalConfig(string $uri): void { $this->config->expects($this->once()) ->method('getSystemValueBool') @@ -166,9 +164,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressDisabledByOption(string $uri): void { $this->config->expects($this->never()) ->method('getSystemValueBool'); @@ -179,9 +177,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnGet(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -194,9 +192,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnHead(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -209,9 +207,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnPost(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -224,9 +222,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnPut(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -239,9 +237,9 @@ class ClientTest extends \Test\TestCase { } /** - * @dataProvider dataPreventLocalAddress * @param string $uri */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataPreventLocalAddress')] public function testPreventLocalAddressOnDelete(string $uri): void { $host = parse_url($uri, PHP_URL_HOST); $this->expectException(LocalServerException::class); @@ -256,21 +254,21 @@ class ClientTest extends \Test\TestCase { private function setUpDefaultRequestOptions(): void { $this->config ->method('getSystemValue') - ->will($this->returnValueMap([ + ->willReturnMap([ ['proxyexclude', [], []], - ])); + ]); $this->config ->method('getSystemValueString') - ->will($this->returnValueMap([ + ->willReturnMap([ ['proxy', '', 'foo'], ['proxyuserpwd', '', ''], - ])); + ]); $this->config ->method('getSystemValueBool') - ->will($this->returnValueMap([ + ->willReturnMap([ ['installed', false, true], ['allow_local_remote_servers', false, true], - ])); + ]); $this->certificateManager ->expects($this->once()) @@ -455,14 +453,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['installed', false], - ['allow_local_remote_servers', false], - ) - ->willReturnOnConsecutiveCalls( - false, - false, - ); + ->willReturnMap([ + ['installed', false, false], + ['allow_local_remote_servers', false, false], + ]); $this->config ->expects($this->once()) ->method('getSystemValueString') @@ -486,8 +480,8 @@ class ClientTest extends \Test\TestCase { 'on_redirect' => function ( \Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response, - \Psr\Http\Message\UriInterface $uri - ) { + \Psr\Http\Message\UriInterface $uri, + ): void { }, ], ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); @@ -497,14 +491,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['installed', false], - ['allow_local_remote_servers', false], - ) - ->willReturnOnConsecutiveCalls( - true, - false, - ); + ->willReturnMap([ + ['installed', false, true], + ['allow_local_remote_servers', false, false], + ]); $this->config ->expects($this->once()) ->method('getSystemValue') @@ -513,14 +503,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueString') - ->withConsecutive( - ['proxy', ''], - ['proxyuserpwd', ''], - ) - ->willReturnOnConsecutiveCalls( - 'foo', - '', - ); + ->willReturnMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', ''], + ]); $this->certificateManager ->expects($this->once()) ->method('getAbsoluteBundlePath') @@ -545,8 +531,8 @@ class ClientTest extends \Test\TestCase { 'on_redirect' => function ( \Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response, - \Psr\Http\Message\UriInterface $uri - ) { + \Psr\Http\Message\UriInterface $uri, + ): void { }, ], ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); @@ -556,14 +542,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['installed', false], - ['allow_local_remote_servers', false], - ) - ->willReturnOnConsecutiveCalls( - true, - false, - ); + ->willReturnMap([ + ['installed', false, true], + ['allow_local_remote_servers', false, false], + ]); $this->config ->expects($this->once()) ->method('getSystemValue') @@ -572,14 +554,10 @@ class ClientTest extends \Test\TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValueString') - ->withConsecutive( - ['proxy', ''], - ['proxyuserpwd', ''], - ) - ->willReturnOnConsecutiveCalls( - 'foo', - '', - ); + ->willReturnMap([ + ['proxy', '', 'foo'], + ['proxyuserpwd', '', ''], + ]); $this->certificateManager ->expects($this->once()) ->method('getAbsoluteBundlePath') @@ -605,8 +583,8 @@ class ClientTest extends \Test\TestCase { 'on_redirect' => function ( \Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response, - \Psr\Http\Message\UriInterface $uri - ) { + \Psr\Http\Message\UriInterface $uri, + ): void { }, ], ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); |