Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/private/Http/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ private function setDefaultOptions() {
}
}

$this->client->setDefaultOption('headers/User-Agent', 'ownCloud Server Crawler');
if ($this->getProxyUri() !== '') {
$this->client->setDefaultOption('proxy', $this->getProxyUri());
$this->client->setDefaultOption('headers/User-Agent', 'Nextcloud Server Crawler');
$proxyUri = $this->getProxyUri();
if ($proxyUri !== '') {
$this->client->setDefaultOption('proxy', $proxyUri);
}
}

Expand All @@ -93,10 +94,10 @@ private function getProxyUri() {
$proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null);
$proxyUri = '';

if (!is_null($proxyUserPwd)) {
if ($proxyUserPwd !== null) {
$proxyUri .= $proxyUserPwd . '@';
}
if (!is_null($proxyHost)) {
if ($proxyHost !== null) {
$proxyUri .= $proxyHost;
}

Expand Down
71 changes: 67 additions & 4 deletions tests/lib/Http/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@

use GuzzleHttp\Message\Response;
use OC\Http\Client\Client;
use OC\Security\CertificateManager;
use OCP\ICertificateManager;
use OCP\IConfig;

/**
* Class ClientTest
*/
class ClientTest extends \Test\TestCase {
/** @var \GuzzleHttp\Client */
/** @var \GuzzleHttp\Client|\PHPUnit_Framework_MockObject_MockObject */
private $guzzleClient;
/** @var CertificateManager|\PHPUnit_Framework_MockObject_MockObject */
private $certificateManager;
/** @var Client */
private $client;
/** @var IConfig */
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;

public function setUp() {
Expand All @@ -30,10 +33,10 @@ public function setUp() {
$this->guzzleClient = $this->getMockBuilder('\GuzzleHttp\Client')
->disableOriginalConstructor()
->getMock();
$certificateManager = $this->createMock(ICertificateManager::class);
$this->certificateManager = $this->createMock(ICertificateManager::class);
$this->client = new Client(
$this->config,
$certificateManager,
$this->certificateManager,
$this->guzzleClient
);
}
Expand Down Expand Up @@ -109,4 +112,64 @@ public function testOptions() {
->willReturn(new Response(1337));
$this->assertEquals(1337, $this->client->options('http://localhost/', [])->getStatusCode());
}

public function testHead() {
$this->guzzleClient->method('head')
->willReturn(new Response(1337));
$this->assertEquals(1337, $this->client->head('http://localhost/', [])->getStatusCode());
}

public function testSetDefaultOptionsWithNotInstalled() {
$this->config
->expects($this->at(0))
->method('getSystemValue')
->with('installed', false)
->willReturn(false);
$this->certificateManager
->expects($this->once())
->method('listCertificates')
->willReturn([]);
$this->guzzleClient
->expects($this->at(0))
->method('setDefaultOption')
->with('verify', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
$this->guzzleClient
->expects($this->at(1))
->method('setDefaultOption')
->with('headers/User-Agent', 'Nextcloud Server Crawler');

self::invokePrivate($this->client, 'setDefaultOptions');
}

public function testSetDefaultOptionsWithProxy() {
$this->config
->expects($this->at(0))
->method('getSystemValue')
->with('proxy', null)
->willReturn('foo');
$this->config
->expects($this->at(1))
->method('getSystemValue')
->with('proxyuserpwd', null)
->willReturn(null);
$this->certificateManager
->expects($this->once())
->method('getAbsoluteBundlePath')
->with(null)
->willReturn('/my/path.crt');
$this->guzzleClient
->expects($this->at(0))
->method('setDefaultOption')
->with('verify', '/my/path.crt');
$this->guzzleClient
->expects($this->at(1))
->method('setDefaultOption')
->with('headers/User-Agent', 'Nextcloud Server Crawler');
$this->guzzleClient
->expects($this->at(2))
->method('setDefaultOption')
->with('proxy', 'foo');

self::invokePrivate($this->client, 'setDefaultOptions');
}
}