refactor: adjust updater code to match code style

Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Louis Chmn <louis@chmn.me>
pull/55890/head
Louis Chmn 2025-10-21 12:20:34 +07:00 committed by backportbot[bot]
parent 4b968357be
commit 82f15bd766
2 changed files with 15 additions and 9 deletions

@ -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');

@ -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');