Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable23] Make sure ResetTokenBackgroundJob doesn't execute if config is read-only #32890

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/updatenotification/lib/ResetTokenBackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
namespace OCA\UpdateNotification;

use OC\BackgroundJob\TimedJob;
use OCP\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;

Expand All @@ -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;
}
Expand All @@ -59,7 +60,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');
}
}
Expand Down
32 changes: 26 additions & 6 deletions apps/updatenotification/tests/ResetTokenBackgroundJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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')
Expand All @@ -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]);
}
}