diff --git a/apps/updatenotification/appinfo/app.php b/apps/updatenotification/appinfo/app.php index 54bef81305..a88861c094 100644 --- a/apps/updatenotification/appinfo/app.php +++ b/apps/updatenotification/appinfo/app.php @@ -21,7 +21,7 @@ if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) { $updater = new \OC\Updater\VersionCheck( - \OC::$server->getHTTPHelper(), + \OC::$server->getHTTPClientService(), \OC::$server->getConfig() ); $updateChecker = new \OCA\UpdateNotification\UpdateChecker( diff --git a/apps/updatenotification/appinfo/application.php b/apps/updatenotification/appinfo/application.php index e0e8dad3d7..08ff4abf76 100644 --- a/apps/updatenotification/appinfo/application.php +++ b/apps/updatenotification/appinfo/application.php @@ -35,7 +35,7 @@ class Application extends App { $container->registerService('AdminController', function(IAppContainer $c) { $updater = new \OC\Updater\VersionCheck( - \OC::$server->getHTTPHelper(), + \OC::$server->getHTTPClientService(), \OC::$server->getConfig() ); return new AdminController( diff --git a/lib/private/updater/versioncheck.php b/lib/private/updater/versioncheck.php index 2c93952fed..e42a1e2a40 100644 --- a/lib/private/updater/versioncheck.php +++ b/lib/private/updater/versioncheck.php @@ -33,28 +33,27 @@ namespace OC\Updater; -use OC\Hooks\BasicEmitter; -use OC\HTTPHelper; use OC_Util; +use OCP\Http\Client\IClientService; use OCP\IConfig; use OC\Setup; use OCP\Util; class VersionCheck { - /** @var \OC\HTTPHelper $helper */ - private $httpHelper; + /** @var IClientService */ + private $clientService; /** @var IConfig */ private $config; /** - * @param HTTPHelper $httpHelper + * @param IClientService $clientService * @param IConfig $config */ - public function __construct(HTTPHelper $httpHelper, + public function __construct(IClientService $clientService, IConfig $config) { - $this->httpHelper = $httpHelper; + $this->clientService = $clientService; $this->config = $config; } @@ -94,7 +93,7 @@ class VersionCheck { $url = $updaterUrl . '?version=' . $versionString; $tmp = []; - $xml = $this->httpHelper->getUrlContent($url); + $xml = $this->getUrlContent($url); if ($xml) { $loadEntities = libxml_disable_entity_loader(true); $data = @simplexml_load_string($xml); @@ -115,5 +114,20 @@ class VersionCheck { $this->config->setAppValue('core', 'lastupdateResult', json_encode($data)); return $tmp; } + + /** + * @codeCoverageIgnore + * @param string $url + * @return bool|resource|string + */ + protected function getUrlContent($url) { + try { + $client = $this->clientService->newClient(); + $response = $client->get($url); + return $response->getBody(); + } catch (\Exception $e) { + return false; + } + } } diff --git a/tests/lib/updater/versioncheck.php b/tests/lib/updater/versioncheck.php index 76afe893a7..4613581a75 100644 --- a/tests/lib/updater/versioncheck.php +++ b/tests/lib/updater/versioncheck.php @@ -29,24 +29,20 @@ use OCP\Util; class VersionCheckTest extends \Test\TestCase { /** @var IConfig| \PHPUnit_Framework_MockObject_MockObject */ private $config; - /** @var HTTPHelper | \PHPUnit_Framework_MockObject_MockObject*/ - private $httpHelper; - /** @var VersionCheck */ + /** @var VersionCheck | \PHPUnit_Framework_MockObject_MockObject*/ private $updater; public function setUp() { parent::setUp(); - $this->config = $this->getMockBuilder('\\OCP\\IConfig') + $this->config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); - $this->httpHelper = $this->getMockBuilder('\\OC\\HTTPHelper') + $clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService') ->disableOriginalConstructor() ->getMock(); - $this->updater = new VersionCheck( - $this->httpHelper, - $this->config - ); + $this->updater = $this->getMock('\OC\Updater\VersionCheck', + ['getUrlContent'], [$clientService, $this->config]); } /** @@ -118,7 +114,7 @@ class VersionCheckTest extends \Test\TestCase { https://download.owncloud.org/community/owncloud-8.0.4.zip http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html '; - $this->httpHelper + $this->updater ->expects($this->once()) ->method('getUrlContent') ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) @@ -153,7 +149,7 @@ class VersionCheckTest extends \Test\TestCase { ->with('core', 'lastupdateResult', 'false'); $updateXml = 'Invalid XML Response!'; - $this->httpHelper + $this->updater ->expects($this->once()) ->method('getUrlContent') ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) @@ -201,7 +197,7 @@ class VersionCheckTest extends \Test\TestCase { https://download.owncloud.org/community/owncloud-8.0.4.zip http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html '; - $this->httpHelper + $this->updater ->expects($this->once()) ->method('getUrlContent') ->with($this->buildUpdateUrl('https://myupdater.com/')) @@ -245,7 +241,7 @@ class VersionCheckTest extends \Test\TestCase { '; - $this->httpHelper + $this->updater ->expects($this->once()) ->method('getUrlContent') ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) @@ -282,7 +278,7 @@ class VersionCheckTest extends \Test\TestCase { ->with('core', 'lastupdateResult', json_encode($expectedResult)); $updateXml = ''; - $this->httpHelper + $this->updater ->expects($this->once()) ->method('getUrlContent') ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))