mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #32890 from nextcloud/backport/32584/stable23
[stable23] Make sure ResetTokenBackgroundJob doesn't execute if config is read-only
This commit is contained in:
commit
9437cc8db2
2 changed files with 30 additions and 9 deletions
|
|
@ -26,7 +26,7 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace OCA\UpdateNotification;
|
||||
|
||||
use OC\BackgroundJob\TimedJob;
|
||||
use OCP\BackgroundJob\TimedJob;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\IConfig;
|
||||
|
||||
|
|
@ -48,8 +48,9 @@ class ResetTokenBackgroundJob extends TimedJob {
|
|||
*/
|
||||
public function __construct(IConfig $config,
|
||||
ITimeFactory $timeFactory) {
|
||||
parent::__construct($timeFactory);
|
||||
// Run all 10 minutes
|
||||
$this->setInterval(60 * 10);
|
||||
parent::setInterval(60 * 10);
|
||||
$this->config = $config;
|
||||
$this->timeFactory = $timeFactory;
|
||||
}
|
||||
|
|
@ -59,7 +60,7 @@ class ResetTokenBackgroundJob extends TimedJob {
|
|||
*/
|
||||
protected function run($argument) {
|
||||
// Delete old tokens after 2 days
|
||||
if ($this->timeFactory->getTime() - $this->config->getAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()) >= 172800) {
|
||||
if ($this->config->getSystemValueBool('config_is_read_only') === false && $this->timeFactory->getTime() - (int) $this->config->getAppValue('core', 'updater.secret.created', (string) $this->timeFactory->getTime()) >= 172800) {
|
||||
$this->config->deleteSystemValue('updater.secret');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,11 @@ class ResetTokenBackgroundJobTest extends TestCase {
|
|||
->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with('core', 'updater.secret.created', 123);
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getSystemValueBool')
|
||||
->with('config_is_read_only')
|
||||
->willReturn(false);
|
||||
$this->config
|
||||
->expects($this->never())
|
||||
->method('deleteSystemValue');
|
||||
|
|
@ -65,13 +70,9 @@ class ResetTokenBackgroundJobTest extends TestCase {
|
|||
|
||||
public function testRunWithExpiredToken() {
|
||||
$this->timeFactory
|
||||
->expects($this->at(0))
|
||||
->expects($this->exactly(2))
|
||||
->method('getTime')
|
||||
->willReturn(1455131633);
|
||||
$this->timeFactory
|
||||
->expects($this->at(1))
|
||||
->method('getTime')
|
||||
->willReturn(1455045234);
|
||||
->willReturnOnConsecutiveCalls(1455131633, 1455045234);
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getAppValue')
|
||||
|
|
@ -83,4 +84,23 @@ class ResetTokenBackgroundJobTest extends TestCase {
|
|||
|
||||
static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
|
||||
}
|
||||
|
||||
public function testRunWithExpiredTokenAndReadOnlyConfigFile() {
|
||||
$this->timeFactory
|
||||
->expects($this->never())
|
||||
->method('getTime');
|
||||
$this->config
|
||||
->expects($this->never())
|
||||
->method('getAppValue');
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getSystemValueBool')
|
||||
->with('config_is_read_only')
|
||||
->willReturn(true);
|
||||
$this->config
|
||||
->expects($this->never())
|
||||
->method('deleteSystemValue');
|
||||
|
||||
static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue