From 82f15bd766be3a24d2527f536cd4558f51a978c0 Mon Sep 17 00:00:00 2001 From: Louis Chmn Date: Tue, 21 Oct 2025 12:20:34 +0200 Subject: [PATCH] refactor: adjust updater code to match code style Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Ferdinand Thiessen Signed-off-by: Louis Chmn --- .../lib/BackgroundJob/ResetToken.php | 4 ++-- .../tests/BackgroundJob/ResetTokenTest.php | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 9 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 de5925527f6..3845ee05be7 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') @@ -46,7 +49,7 @@ class ResetTokenTest extends TestCase { $this->appConfig ->expects($this->once()) ->method('getValueInt') - ->with('core', 'updater.secret.created', 1733069649) + ->with('core', 'updater.secret.created') ->willReturn(1733069649 - 1 * 24 * 60 * 60); // 24h prior: "Sat, 30 Nov 2024 16:14:09 +0000" $this->config ->expects($this->once()) @@ -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') @@ -77,7 +83,7 @@ class ResetTokenTest extends TestCase { $this->appConfig ->expects($this->once()) ->method('getValueInt') - ->with('core', 'updater.secret.created', 1455045234) + ->with('core', 'updater.secret.created') ->willReturn(1455045234 - 3 * 24 * 60 * 60); // 72h prior: "Sat, 06 Feb 2016 19:13:54 +0000" $this->config ->expects($this->once()) @@ -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');