From 47ea43ea49e63129c0a731d8ac29e38920eda6ac Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 25 May 2022 08:51:16 +0200 Subject: [PATCH 1/3] Make sure ResetTokenBackgroundJob doesn't execute if config is read-only No need to try to delete the config key in config.php if we aren't allowed to. Signed-off-by: Thomas Citharel --- apps/updatenotification/lib/ResetTokenBackgroundJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/updatenotification/lib/ResetTokenBackgroundJob.php b/apps/updatenotification/lib/ResetTokenBackgroundJob.php index 96a50c5ff7f6d..0d07c7301d94c 100644 --- a/apps/updatenotification/lib/ResetTokenBackgroundJob.php +++ b/apps/updatenotification/lib/ResetTokenBackgroundJob.php @@ -59,7 +59,7 @@ public function __construct(IConfig $config, */ 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'); } } From 56727ba58b776732524a47ee42063653211fcd41 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 25 May 2022 08:52:39 +0200 Subject: [PATCH 2/3] Use OCP version of TimedJob instead of OC for ResetTokenBackgroundJob Signed-off-by: Thomas Citharel --- apps/updatenotification/lib/ResetTokenBackgroundJob.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/updatenotification/lib/ResetTokenBackgroundJob.php b/apps/updatenotification/lib/ResetTokenBackgroundJob.php index 0d07c7301d94c..6e80f0fc0bf76 100644 --- a/apps/updatenotification/lib/ResetTokenBackgroundJob.php +++ b/apps/updatenotification/lib/ResetTokenBackgroundJob.php @@ -26,7 +26,7 @@ */ 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; } From 956d895920107b9ae7bb2b4657f89c98a06c43b1 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 25 May 2022 08:58:10 +0200 Subject: [PATCH 3/3] Update tests after ResetTokenBackgroundJob changes Signed-off-by: Thomas Citharel --- .../tests/ResetTokenBackgroundJobTest.php | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php b/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php index 129ba37098063..56a82b5b726ab 100644 --- a/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php +++ b/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php @@ -56,6 +56,11 @@ public function testRunWithNotExpiredToken() { ->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 @@ public function testRunWithNotExpiredToken() { 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 @@ public function testRunWithExpiredToken() { 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]); + } }