Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2019-10-17 15:33:28 +0300
committerGitHub <noreply@github.com>2019-10-17 15:33:28 +0300
commit07a4b2577a15709b56b63b80f8af6e3f8040f036 (patch)
tree3b482cfea03f346eec3b46f70c1948acf2070b92
parentbd8dc102212efd16a13b8cf16b520c445fc0920b (diff)
parent29a1ac7799ea1af20a3635db6f240422e19b495b (diff)
Merge pull request #17511 from nextcloud/backport/16721/stable16
[stable16] Correctly handle emtpy string in proxyuserpwd config
-rw-r--r--lib/private/Http/Client/Client.php19
-rw-r--r--tests/lib/Http/Client/ClientTest.php34
2 files changed, 30 insertions, 23 deletions
diff --git a/lib/private/Http/Client/Client.php b/lib/private/Http/Client/Client.php
index 03b09bf54b7..0dde56b28f9 100644
--- a/lib/private/Http/Client/Client.php
+++ b/lib/private/Http/Client/Client.php
@@ -112,19 +112,20 @@ class Client implements IClient {
*
* @return string
*/
- private function getProxyUri(): string {
- $proxyHost = $this->config->getSystemValue('proxy', null);
- $proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null);
- $proxyUri = '';
+ private function getProxyUri(): ?string {
+ $proxyHost = $this->config->getSystemValue('proxy', '');
- if ($proxyUserPwd !== null) {
- $proxyUri .= $proxyUserPwd . '@';
+ if ($proxyHost === '' || $proxyHost === null) {
+ return null;
}
- if ($proxyHost !== null) {
- $proxyUri .= $proxyHost;
+
+ $proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', '');
+
+ if ($proxyUserPwd === '' || $proxyUserPwd === null) {
+ return $proxyHost;
}
- return $proxyUri;
+ return $proxyUserPwd . '@' . $proxyHost;
}
/**
diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php
index 7f12a824d17..ea825266198 100644
--- a/tests/lib/Http/Client/ClientTest.php
+++ b/tests/lib/Http/Client/ClientTest.php
@@ -49,27 +49,22 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->at(0))
->method('getSystemValue')
- ->with('proxy', null)
- ->willReturn(null);
- $this->config
- ->expects($this->at(1))
- ->method('getSystemValue')
- ->with('proxyuserpwd', null)
- ->willReturn(null);
- $this->assertSame('', self::invokePrivate($this->client, 'getProxyUri'));
+ ->with('proxy', '')
+ ->willReturn('');
+ $this->assertNull(self::invokePrivate($this->client, 'getProxyUri'));
}
public function testGetProxyUriProxyHostEmptyPassword() {
$this->config
->expects($this->at(0))
->method('getSystemValue')
- ->with('proxy', null)
+ ->with('proxy', '')
->willReturn('foo');
$this->config
->expects($this->at(1))
->method('getSystemValue')
- ->with('proxyuserpwd', null)
- ->willReturn(null);
+ ->with('proxyuserpwd', '')
+ ->willReturn('');
$this->assertSame('foo', self::invokePrivate($this->client, 'getProxyUri'));
}
@@ -77,12 +72,22 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->at(0))
->method('getSystemValue')
- ->with('proxy', null)
+ ->with(
+ $this->equalTo('proxy'),
+ $this->callback(function ($input) {
+ return $input === '';
+ })
+ )
->willReturn('foo');
$this->config
->expects($this->at(1))
->method('getSystemValue')
- ->with('proxyuserpwd', null)
+ ->with(
+ $this->equalTo('proxyuserpwd'),
+ $this->callback(function ($input) {
+ return $input === '';
+ })
+ )
->willReturn('username:password');
$this->assertSame('username:password@foo', self::invokePrivate($this->client, 'getProxyUri'));
}
@@ -260,7 +265,8 @@ class ClientTest extends \Test\TestCase {
->willReturn([]);
$this->assertEquals([
- 'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'
+ 'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',
+ 'proxy' => null,
], self::invokePrivate($this->client, 'getRequestOptions'));
}