aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2025-05-16 15:58:16 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2025-05-16 16:49:18 +0200
commit2ed082bdd80104c4b14a4cc4b38dd406bd75bd54 (patch)
tree7ff5c2051e9962ddc73b508d380e6202b97a60d8
parent37db7282299d11e3c3fd8ed079f1acccd5a24370 (diff)
downloadnextcloud-server-fix-updater-secret.tar.gz
nextcloud-server-fix-updater-secret.zip
refactor: adjust updater code to match code stylefix-updater-secret
Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r--apps/updatenotification/lib/BackgroundJob/ResetToken.php4
-rw-r--r--apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php16
2 files changed, 13 insertions, 7 deletions
diff --git a/apps/updatenotification/lib/BackgroundJob/ResetToken.php b/apps/updatenotification/lib/BackgroundJob/ResetToken.php
index 9a72295821a..9e700bc93ac 100644
--- a/apps/updatenotification/lib/BackgroundJob/ResetToken.php
+++ b/apps/updatenotification/lib/BackgroundJob/ResetToken.php
@@ -43,8 +43,8 @@ class ResetToken extends TimedJob {
return;
}
- $secretCreated = $this->appConfig->getValueInt('core', 'updater.secret.created', $this->time->getTime());
- // Delete old tokens after 2 days
+ $secretCreated = $this->appConfig->getValueInt('core', 'updater.secret.created');
+ // Delete old tokens after 2 days and also tokens without any created date
$secretCreatedDiff = $this->time->getTime() - $secretCreated;
if ($secretCreatedDiff >= 172800) {
$this->config->deleteSystemValue('updater.secret');
diff --git a/apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php b/apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php
index 31efcd5a63d..7bb0fe337b0 100644
--- a/apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php
+++ b/apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php
@@ -38,7 +38,10 @@ class ResetTokenTest extends TestCase {
);
}
- public function testRunWithNotExpiredToken(): void { // Affirm if updater.secret.created <48 hours ago then `updater.secret` is left alone
+ /**
+ * Affirm if updater.secret.created <48 hours ago then `updater.secret` is left alone.
+ */
+ public function testKeepSecretWhenCreatedRecently(): void {
$this->timeFactory
->expects($this->atLeastOnce())
->method('getTime')
@@ -66,10 +69,13 @@ class ResetTokenTest extends TestCase {
->expects($this->once())
->method('debug');
- $this->invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
+ static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
}
- public function testRunWithExpiredToken(): void { // Affirm if updater.secret.created >48 hours ago then `updater.secret` is removed
+ /**
+ * Affirm if updater.secret.created >48 hours ago then `updater.secret` is removed
+ */
+ public function testSecretIsRemovedWhenOutdated(): void {
$this->timeFactory
->expects($this->atLeastOnce())
->method('getTime')
@@ -104,8 +110,8 @@ class ResetTokenTest extends TestCase {
public function testRunWithExpiredTokenAndReadOnlyConfigFile(): void { // Affirm if config_is_read_only is set that the secret is never reset
$this->timeFactory
- ->expects($this->never())
- ->method('getTime');
+ ->expects($this->never())
+ ->method('getTime');
$this->appConfig
->expects($this->never())
->method('getValueInt');