Rebrand to "Nextcloud" and add 100% coverage

Noticed while debugging https://github.com/nextcloud/server/issues/2910

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Lukas Reschke 2017-01-02 14:51:16 +01:00
parent fc02564ea6
commit 5679f04cb1
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
2 changed files with 73 additions and 9 deletions

View File

@ -77,9 +77,10 @@ class Client implements IClient {
} }
} }
$this->client->setDefaultOption('headers/User-Agent', 'ownCloud Server Crawler'); $this->client->setDefaultOption('headers/User-Agent', 'Nextcloud Server Crawler');
if ($this->getProxyUri() !== '') { $proxyUri = $this->getProxyUri();
$this->client->setDefaultOption('proxy', $this->getProxyUri()); if ($proxyUri !== '') {
$this->client->setDefaultOption('proxy', $proxyUri);
} }
} }
@ -93,10 +94,10 @@ class Client implements IClient {
$proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null); $proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null);
$proxyUri = ''; $proxyUri = '';
if (!is_null($proxyUserPwd)) { if ($proxyUserPwd !== null) {
$proxyUri .= $proxyUserPwd . '@'; $proxyUri .= $proxyUserPwd . '@';
} }
if (!is_null($proxyHost)) { if ($proxyHost !== null) {
$proxyUri .= $proxyHost; $proxyUri .= $proxyHost;
} }

View File

@ -10,6 +10,7 @@ namespace Test\Http\Client;
use GuzzleHttp\Message\Response; use GuzzleHttp\Message\Response;
use OC\Http\Client\Client; use OC\Http\Client\Client;
use OC\Security\CertificateManager;
use OCP\ICertificateManager; use OCP\ICertificateManager;
use OCP\IConfig; use OCP\IConfig;
@ -17,11 +18,13 @@ use OCP\IConfig;
* Class ClientTest * Class ClientTest
*/ */
class ClientTest extends \Test\TestCase { class ClientTest extends \Test\TestCase {
/** @var \GuzzleHttp\Client */ /** @var \GuzzleHttp\Client|\PHPUnit_Framework_MockObject_MockObject */
private $guzzleClient; private $guzzleClient;
/** @var CertificateManager|\PHPUnit_Framework_MockObject_MockObject */
private $certificateManager;
/** @var Client */ /** @var Client */
private $client; private $client;
/** @var IConfig */ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config; private $config;
public function setUp() { public function setUp() {
@ -30,10 +33,10 @@ class ClientTest extends \Test\TestCase {
$this->guzzleClient = $this->getMockBuilder('\GuzzleHttp\Client') $this->guzzleClient = $this->getMockBuilder('\GuzzleHttp\Client')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$certificateManager = $this->createMock(ICertificateManager::class); $this->certificateManager = $this->createMock(ICertificateManager::class);
$this->client = new Client( $this->client = new Client(
$this->config, $this->config,
$certificateManager, $this->certificateManager,
$this->guzzleClient $this->guzzleClient
); );
} }
@ -109,4 +112,64 @@ class ClientTest extends \Test\TestCase {
->willReturn(new Response(1337)); ->willReturn(new Response(1337));
$this->assertEquals(1337, $this->client->options('http://localhost/', [])->getStatusCode()); $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');
}
} }