Skip to content

Commit

Permalink
Merge pull request #7562 from nextcloud/fix-wrongly-cached-result
Browse files Browse the repository at this point in the history
Cache final result of update check
  • Loading branch information
rullzer authored Dec 19, 2017
2 parents b01d20c + 1beffa0 commit e550a3d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/private/Updater/VersionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ public function check() {
} else {
libxml_clear_errors();
}
} else {
$data = [];
}

// Cache the result
$this->config->setAppValue('core', 'lastupdateResult', json_encode($data));
$this->config->setAppValue('core', 'lastupdateResult', json_encode($tmp));
return $tmp;
}

Expand Down
53 changes: 52 additions & 1 deletion tests/lib/Updater/VersionCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function testCheckWithInvalidXml() {
$this->config
->expects($this->at(6))
->method('setAppValue')
->with('core', 'lastupdateResult', 'false');
->with('core', 'lastupdateResult', '[]');

$updateXml = 'Invalid XML Response!';
$this->updater
Expand Down Expand Up @@ -265,4 +265,55 @@ public function testCheckWithEmptyInvalidXmlResponse() {

$this->assertSame($expectedResult, $this->updater->check());
}

public function testCheckWithMissingAttributeXmlResponse() {
$expectedResult = [
'version' => '',
'versionstring' => '',
'url' => '',
'web' => '',
'autoupdater' => '',
];

$this->config
->expects($this->at(0))
->method('getAppValue')
->with('core', 'lastupdatedat')
->will($this->returnValue(0));
$this->config
->expects($this->at(1))
->method('getSystemValue')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1);
$this->config
->expects($this->at(2))
->method('setAppValue')
->with('core', 'lastupdatedat', $this->isType('integer'));
$this->config
->expects($this->at(4))
->method('getAppValue')
->with('core', 'installedat')
->will($this->returnValue('installedat'));
$this->config
->expects($this->at(5))
->method('getAppValue')
->with('core', 'lastupdatedat')
->will($this->returnValue('lastupdatedat'));

// missing autoupdater element should still not fail
$updateXml = '<?xml version="1.0"?>
<owncloud>
<version></version>
<versionstring></versionstring>
<url></url>
<web></web>
</owncloud>';
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/'))
->will($this->returnValue($updateXml));

$this->assertSame($expectedResult, $this->updater->check());
}
}

0 comments on commit e550a3d

Please sign in to comment.