From 8b428d84c0666d3ded46c20965784b2f5f5369fb Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 9 May 2016 11:25:58 +0200 Subject: [PATCH] Make update server URL configurable Currently testing the updates is a big problem and not really super easy possible. Since we now have a new updater server we should also make this configurable so that people can properly test updates. --- config/config.sample.php | 5 ++ lib/private/Updater/VersionCheck.php | 8 +-- tests/lib/updater/versioncheck.php | 90 ++++++++++------------------ 3 files changed, 38 insertions(+), 65 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index db662cfd74ff..0027a5333689 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -471,6 +471,11 @@ */ 'updatechecker' => true, +/** + * URL that ownCloud should use to look for updates + */ +'updater.server.url' => 'https://updates.owncloud.com/server/', + /** * Is ownCloud connected to the Internet or running in a closed network? */ diff --git a/lib/private/Updater/VersionCheck.php b/lib/private/Updater/VersionCheck.php index e42a1e2a40c2..7b330b53686c 100644 --- a/lib/private/Updater/VersionCheck.php +++ b/lib/private/Updater/VersionCheck.php @@ -61,19 +61,15 @@ public function __construct(IClientService $clientService, /** * Check if a new version is available * - * @param string $updaterUrl the url to check, i.e. 'http://apps.owncloud.com/updater.php' * @return array|bool */ - public function check($updaterUrl = null) { - + public function check() { // Look up the cache - it is invalidated all 30 minutes if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) { return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true); } - if (is_null($updaterUrl)) { - $updaterUrl = 'https://updates.owncloud.com/server/'; - } + $updaterUrl = $this->config->getSystemValue('updater.server.url', 'https://updates.owncloud.com/server/'); $this->config->setAppValue('core', 'lastupdatedat', time()); diff --git a/tests/lib/updater/versioncheck.php b/tests/lib/updater/versioncheck.php index 4613581a75f4..2122ca288008 100644 --- a/tests/lib/updater/versioncheck.php +++ b/tests/lib/updater/versioncheck.php @@ -90,20 +90,25 @@ public function testCheckWithoutUpdateUrl() { ->will($this->returnValue(0)); $this->config ->expects($this->at(1)) + ->method('getSystemValue') + ->with('updater.server.url', 'https://updates.owncloud.com/server/') + ->willReturn('https://updates.owncloud.com/server/'); + $this->config + ->expects($this->at(2)) ->method('setAppValue') ->with('core', 'lastupdatedat', $this->isType('integer')); $this->config - ->expects($this->at(3)) + ->expects($this->at(4)) ->method('getAppValue') ->with('core', 'installedat') ->will($this->returnValue('installedat')); $this->config - ->expects($this->at(4)) + ->expects($this->at(5)) ->method('getAppValue') ->with('core', 'lastupdatedat') ->will($this->returnValue('lastupdatedat')); $this->config - ->expects($this->at(5)) + ->expects($this->at(6)) ->method('setAppValue') ->with('core', 'lastupdateResult', json_encode($expectedResult)); @@ -131,20 +136,25 @@ public function testCheckWithInvalidXml() { ->will($this->returnValue(0)); $this->config ->expects($this->at(1)) + ->method('getSystemValue') + ->with('updater.server.url', 'https://updates.owncloud.com/server/') + ->willReturn('https://updates.owncloud.com/server/'); + $this->config + ->expects($this->at(2)) ->method('setAppValue') ->with('core', 'lastupdatedat', $this->isType('integer')); $this->config - ->expects($this->at(3)) + ->expects($this->at(4)) ->method('getAppValue') ->with('core', 'installedat') ->will($this->returnValue('installedat')); $this->config - ->expects($this->at(4)) + ->expects($this->at(5)) ->method('getAppValue') ->with('core', 'lastupdatedat') ->will($this->returnValue('lastupdatedat')); $this->config - ->expects($this->at(5)) + ->expects($this->at(6)) ->method('setAppValue') ->with('core', 'lastupdateResult', 'false'); @@ -158,54 +168,6 @@ public function testCheckWithInvalidXml() { $this->assertSame([], $this->updater->check()); } - public function testCheckWithUpdateUrl() { - $expectedResult = [ - 'version' => '8.0.4.2', - 'versionstring' => 'ownCloud 8.0.4', - 'url' => 'https://download.owncloud.org/community/owncloud-8.0.4.zip', - 'web' => 'http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html', - ]; - - $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue(0)); - $this->config - ->expects($this->at(1)) - ->method('setAppValue') - ->with('core', 'lastupdatedat', $this->isType('integer')); - $this->config - ->expects($this->at(3)) - ->method('getAppValue') - ->with('core', 'installedat') - ->will($this->returnValue('installedat')); - $this->config - ->expects($this->at(4)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue('lastupdatedat')); - $this->config - ->expects($this->at(5)) - ->method('setAppValue') - ->with('core', 'lastupdateResult', json_encode($expectedResult)); - - $updateXml = ' - - 8.0.4.2 - ownCloud 8.0.4 - https://download.owncloud.org/community/owncloud-8.0.4.zip - http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html -'; - $this->updater - ->expects($this->once()) - ->method('getUrlContent') - ->with($this->buildUpdateUrl('https://myupdater.com/')) - ->will($this->returnValue($updateXml)); - - $this->assertSame($expectedResult, $this->updater->check('https://myupdater.com/')); - } - public function testCheckWithEmptyValidXmlResponse() { $expectedResult = [ 'version' => '', @@ -221,15 +183,20 @@ public function testCheckWithEmptyValidXmlResponse() { ->will($this->returnValue(0)); $this->config ->expects($this->at(1)) + ->method('getSystemValue') + ->with('updater.server.url', 'https://updates.owncloud.com/server/') + ->willReturn('https://updates.owncloud.com/server/'); + $this->config + ->expects($this->at(2)) ->method('setAppValue') ->with('core', 'lastupdatedat', $this->isType('integer')); $this->config - ->expects($this->at(3)) + ->expects($this->at(4)) ->method('getAppValue') ->with('core', 'installedat') ->will($this->returnValue('installedat')); $this->config - ->expects($this->at(4)) + ->expects($this->at(5)) ->method('getAppValue') ->with('core', 'lastupdatedat') ->will($this->returnValue('lastupdatedat')); @@ -260,20 +227,25 @@ public function testCheckWithEmptyInvalidXmlResponse() { ->will($this->returnValue(0)); $this->config ->expects($this->at(1)) + ->method('getSystemValue') + ->with('updater.server.url', 'https://updates.owncloud.com/server/') + ->willReturn('https://updates.owncloud.com/server/'); + $this->config + ->expects($this->at(2)) ->method('setAppValue') ->with('core', 'lastupdatedat', $this->isType('integer')); $this->config - ->expects($this->at(3)) + ->expects($this->at(4)) ->method('getAppValue') ->with('core', 'installedat') ->will($this->returnValue('installedat')); $this->config - ->expects($this->at(4)) + ->expects($this->at(5)) ->method('getAppValue') ->with('core', 'lastupdatedat') ->will($this->returnValue('lastupdatedat')); $this->config - ->expects($this->at(5)) + ->expects($this->at(6)) ->method('setAppValue') ->with('core', 'lastupdateResult', json_encode($expectedResult));