Correctly handle emtpy string in proxyuserpwd config

As documented, the default value for config value proxyuserpwd is ''.
However, that value results in the error:
 "cURL error 5: Unsupported proxy syntax in '@'".
This patch handles the values of '' and null (the default in the code)
the same for config values proxyuserpwd and proxy.

Signed-off-by: Scott Shambarger <devel@shambarger.net>
This commit is contained in:
Scott Shambarger 2019-08-02 15:18:01 -07:00 committed by Arthur Schiwon
parent bb34e90866
commit 3fc86e639e
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
2 changed files with 20 additions and 6 deletions

View File

@ -112,12 +112,16 @@ class Client implements IClient {
*
* @return string
*/
private function getProxyUri(): string {
$proxyHost = $this->config->getSystemValue('proxy', null);
$proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null);
private function getProxyUri(): ?string {
$proxyHost = $this->config->getSystemValue('proxy', '');
if ($proxyHost === '' || $proxyHost === null) {
return null;
}
$proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', '');
$proxyUri = '';
if ($proxyUserPwd !== null) {
if ($proxyUserPwd === '' || $proxyUserPwd === null) {
$proxyUri .= $proxyUserPwd . '@';
}
if ($proxyHost !== null) {

View File

@ -77,12 +77,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'));
}