Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel <mail@danielkesselberg.de>2022-06-15 12:37:43 +0300
committerGitHub <noreply@github.com>2022-06-15 12:37:43 +0300
commit596ead787ba7f7148fceb04de9d7c08cece936bc (patch)
treec63a1cb70c662340ca07f8dfb3429b1d5bb340ee
parentda8450e854404a2feee7169e379f4f64f685e170 (diff)
parent956d895920107b9ae7bb2b4657f89c98a06c43b1 (diff)
Merge pull request #32584 from nextcloud/fix-ResetTokenBackgroundJob
Make sure ResetTokenBackgroundJob doesn't execute if config is read-only
-rw-r--r--apps/updatenotification/lib/ResetTokenBackgroundJob.php7
-rw-r--r--apps/updatenotification/tests/ResetTokenBackgroundJobTest.php32
2 files changed, 30 insertions, 9 deletions
diff --git a/apps/updatenotification/lib/ResetTokenBackgroundJob.php b/apps/updatenotification/lib/ResetTokenBackgroundJob.php
index 96a50c5ff7f..6e80f0fc0bf 100644
--- a/apps/updatenotification/lib/ResetTokenBackgroundJob.php
+++ b/apps/updatenotification/lib/ResetTokenBackgroundJob.php
@@ -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');
}
}
diff --git a/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php b/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php
index 129ba370980..56a82b5b726 100644
--- a/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php
+++ b/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php
@@ -57,6 +57,11 @@ class ResetTokenBackgroundJobTest extends TestCase {
->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]);
+ }
}