Skip to content

Commit 07a4b25

Browse files
authored
Merge pull request #17511 from nextcloud/backport/16721/stable16
[stable16] Correctly handle emtpy string in proxyuserpwd config
2 parents bd8dc10 + 29a1ac7 commit 07a4b25

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

lib/private/Http/Client/Client.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,20 @@ private function getCertBundle() {
112112
*
113113
* @return string
114114
*/
115-
private function getProxyUri(): string {
116-
$proxyHost = $this->config->getSystemValue('proxy', null);
117-
$proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null);
118-
$proxyUri = '';
115+
private function getProxyUri(): ?string {
116+
$proxyHost = $this->config->getSystemValue('proxy', '');
119117

120-
if ($proxyUserPwd !== null) {
121-
$proxyUri .= $proxyUserPwd . '@';
118+
if ($proxyHost === '' || $proxyHost === null) {
119+
return null;
122120
}
123-
if ($proxyHost !== null) {
124-
$proxyUri .= $proxyHost;
121+
122+
$proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', '');
123+
124+
if ($proxyUserPwd === '' || $proxyUserPwd === null) {
125+
return $proxyHost;
125126
}
126127

127-
return $proxyUri;
128+
return $proxyUserPwd . '@' . $proxyHost;
128129
}
129130

130131
/**

tests/lib/Http/Client/ClientTest.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,40 +49,45 @@ public function testGetProxyUri() {
4949
$this->config
5050
->expects($this->at(0))
5151
->method('getSystemValue')
52-
->with('proxy', null)
53-
->willReturn(null);
54-
$this->config
55-
->expects($this->at(1))
56-
->method('getSystemValue')
57-
->with('proxyuserpwd', null)
58-
->willReturn(null);
59-
$this->assertSame('', self::invokePrivate($this->client, 'getProxyUri'));
52+
->with('proxy', '')
53+
->willReturn('');
54+
$this->assertNull(self::invokePrivate($this->client, 'getProxyUri'));
6055
}
6156

6257
public function testGetProxyUriProxyHostEmptyPassword() {
6358
$this->config
6459
->expects($this->at(0))
6560
->method('getSystemValue')
66-
->with('proxy', null)
61+
->with('proxy', '')
6762
->willReturn('foo');
6863
$this->config
6964
->expects($this->at(1))
7065
->method('getSystemValue')
71-
->with('proxyuserpwd', null)
72-
->willReturn(null);
66+
->with('proxyuserpwd', '')
67+
->willReturn('');
7368
$this->assertSame('foo', self::invokePrivate($this->client, 'getProxyUri'));
7469
}
7570

7671
public function testGetProxyUriProxyHostWithPassword() {
7772
$this->config
7873
->expects($this->at(0))
7974
->method('getSystemValue')
80-
->with('proxy', null)
75+
->with(
76+
$this->equalTo('proxy'),
77+
$this->callback(function ($input) {
78+
return $input === '';
79+
})
80+
)
8181
->willReturn('foo');
8282
$this->config
8383
->expects($this->at(1))
8484
->method('getSystemValue')
85-
->with('proxyuserpwd', null)
85+
->with(
86+
$this->equalTo('proxyuserpwd'),
87+
$this->callback(function ($input) {
88+
return $input === '';
89+
})
90+
)
8691
->willReturn('username:password');
8792
$this->assertSame('username:password@foo', self::invokePrivate($this->client, 'getProxyUri'));
8893
}
@@ -260,7 +265,8 @@ public function testSetDefaultOptionsWithNotInstalled() {
260265
->willReturn([]);
261266

262267
$this->assertEquals([
263-
'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'
268+
'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',
269+
'proxy' => null,
264270
], self::invokePrivate($this->client, 'getRequestOptions'));
265271
}
266272

0 commit comments

Comments
 (0)