Merge pull request #24500 from owncloud/updater-server-configurable

Make update server URL configurable
This commit is contained in:
Thomas Müller 2016-05-09 17:41:25 +02:00
commit 51d7c87551
3 changed files with 38 additions and 65 deletions

View File

@ -471,6 +471,11 @@ $CONFIG = array(
*/ */
'updatechecker' => true, '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? * Is ownCloud connected to the Internet or running in a closed network?
*/ */

View File

@ -61,19 +61,15 @@ class VersionCheck {
/** /**
* Check if a new version is available * 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 * @return array|bool
*/ */
public function check($updaterUrl = null) { public function check() {
// Look up the cache - it is invalidated all 30 minutes // Look up the cache - it is invalidated all 30 minutes
if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) { if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) {
return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true); return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true);
} }
if (is_null($updaterUrl)) { $updaterUrl = $this->config->getSystemValue('updater.server.url', 'https://updates.owncloud.com/server/');
$updaterUrl = 'https://updates.owncloud.com/server/';
}
$this->config->setAppValue('core', 'lastupdatedat', time()); $this->config->setAppValue('core', 'lastupdatedat', time());

View File

@ -90,20 +90,25 @@ class VersionCheckTest extends \Test\TestCase {
->will($this->returnValue(0)); ->will($this->returnValue(0));
$this->config $this->config
->expects($this->at(1)) ->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') ->method('setAppValue')
->with('core', 'lastupdatedat', $this->isType('integer')); ->with('core', 'lastupdatedat', $this->isType('integer'));
$this->config $this->config
->expects($this->at(3)) ->expects($this->at(4))
->method('getAppValue') ->method('getAppValue')
->with('core', 'installedat') ->with('core', 'installedat')
->will($this->returnValue('installedat')); ->will($this->returnValue('installedat'));
$this->config $this->config
->expects($this->at(4)) ->expects($this->at(5))
->method('getAppValue') ->method('getAppValue')
->with('core', 'lastupdatedat') ->with('core', 'lastupdatedat')
->will($this->returnValue('lastupdatedat')); ->will($this->returnValue('lastupdatedat'));
$this->config $this->config
->expects($this->at(5)) ->expects($this->at(6))
->method('setAppValue') ->method('setAppValue')
->with('core', 'lastupdateResult', json_encode($expectedResult)); ->with('core', 'lastupdateResult', json_encode($expectedResult));
@ -131,20 +136,25 @@ class VersionCheckTest extends \Test\TestCase {
->will($this->returnValue(0)); ->will($this->returnValue(0));
$this->config $this->config
->expects($this->at(1)) ->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') ->method('setAppValue')
->with('core', 'lastupdatedat', $this->isType('integer')); ->with('core', 'lastupdatedat', $this->isType('integer'));
$this->config $this->config
->expects($this->at(3)) ->expects($this->at(4))
->method('getAppValue') ->method('getAppValue')
->with('core', 'installedat') ->with('core', 'installedat')
->will($this->returnValue('installedat')); ->will($this->returnValue('installedat'));
$this->config $this->config
->expects($this->at(4)) ->expects($this->at(5))
->method('getAppValue') ->method('getAppValue')
->with('core', 'lastupdatedat') ->with('core', 'lastupdatedat')
->will($this->returnValue('lastupdatedat')); ->will($this->returnValue('lastupdatedat'));
$this->config $this->config
->expects($this->at(5)) ->expects($this->at(6))
->method('setAppValue') ->method('setAppValue')
->with('core', 'lastupdateResult', 'false'); ->with('core', 'lastupdateResult', 'false');
@ -158,54 +168,6 @@ class VersionCheckTest extends \Test\TestCase {
$this->assertSame([], $this->updater->check()); $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 = '<?xml version="1.0"?>
<owncloud>
<version>8.0.4.2</version>
<versionstring>ownCloud 8.0.4</versionstring>
<url>https://download.owncloud.org/community/owncloud-8.0.4.zip</url>
<web>http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html</web>
</owncloud>';
$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() { public function testCheckWithEmptyValidXmlResponse() {
$expectedResult = [ $expectedResult = [
'version' => '', 'version' => '',
@ -221,15 +183,20 @@ class VersionCheckTest extends \Test\TestCase {
->will($this->returnValue(0)); ->will($this->returnValue(0));
$this->config $this->config
->expects($this->at(1)) ->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') ->method('setAppValue')
->with('core', 'lastupdatedat', $this->isType('integer')); ->with('core', 'lastupdatedat', $this->isType('integer'));
$this->config $this->config
->expects($this->at(3)) ->expects($this->at(4))
->method('getAppValue') ->method('getAppValue')
->with('core', 'installedat') ->with('core', 'installedat')
->will($this->returnValue('installedat')); ->will($this->returnValue('installedat'));
$this->config $this->config
->expects($this->at(4)) ->expects($this->at(5))
->method('getAppValue') ->method('getAppValue')
->with('core', 'lastupdatedat') ->with('core', 'lastupdatedat')
->will($this->returnValue('lastupdatedat')); ->will($this->returnValue('lastupdatedat'));
@ -260,20 +227,25 @@ class VersionCheckTest extends \Test\TestCase {
->will($this->returnValue(0)); ->will($this->returnValue(0));
$this->config $this->config
->expects($this->at(1)) ->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') ->method('setAppValue')
->with('core', 'lastupdatedat', $this->isType('integer')); ->with('core', 'lastupdatedat', $this->isType('integer'));
$this->config $this->config
->expects($this->at(3)) ->expects($this->at(4))
->method('getAppValue') ->method('getAppValue')
->with('core', 'installedat') ->with('core', 'installedat')
->will($this->returnValue('installedat')); ->will($this->returnValue('installedat'));
$this->config $this->config
->expects($this->at(4)) ->expects($this->at(5))
->method('getAppValue') ->method('getAppValue')
->with('core', 'lastupdatedat') ->with('core', 'lastupdatedat')
->will($this->returnValue('lastupdatedat')); ->will($this->returnValue('lastupdatedat'));
$this->config $this->config
->expects($this->at(5)) ->expects($this->at(6))
->method('setAppValue') ->method('setAppValue')
->with('core', 'lastupdateResult', json_encode($expectedResult)); ->with('core', 'lastupdateResult', json_encode($expectedResult));