Skip to content

Commit 2a8f5d6

Browse files
artongebackportbot[bot]
authored andcommitted
refactor: adjust updater code to match code style
Co-authored-by: Joas Schilling <[email protected]> Signed-off-by: Ferdinand Thiessen <[email protected]> Signed-off-by: Louis Chmn <[email protected]> [skip ci]
1 parent d015744 commit 2a8f5d6

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

apps/updatenotification/lib/BackgroundJob/ResetToken.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ protected function run($argument) {
4343
return;
4444
}
4545

46-
$secretCreated = $this->appConfig->getValueInt('core', 'updater.secret.created', $this->time->getTime());
47-
// Delete old tokens after 2 days
46+
$secretCreated = $this->appConfig->getValueInt('core', 'updater.secret.created');
47+
// Delete old tokens after 2 days and also tokens without any created date
4848
$secretCreatedDiff = $this->time->getTime() - $secretCreated;
4949
if ($secretCreatedDiff >= 172800) {
5050
$this->config->deleteSystemValue('updater.secret');

apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ protected function setUp(): void {
3636
);
3737
}
3838

39-
public function testRunWithNotExpiredToken(): void { // Affirm if updater.secret.created <48 hours ago then `updater.secret` is left alone
39+
/**
40+
* Affirm if updater.secret.created <48 hours ago then `updater.secret` is left alone.
41+
*/
42+
public function testKeepSecretWhenCreatedRecently(): void {
4043
$this->timeFactory
4144
->expects($this->atLeastOnce())
4245
->method('getTime')
4346
->willReturn(1733069649); // "Sun, 01 Dec 2024 16:14:09 +0000"
4447
$this->appConfig
4548
->expects($this->once())
4649
->method('getValueInt')
47-
->with('core', 'updater.secret.created', 1733069649)
50+
->with('core', 'updater.secret.created')
4851
->willReturn(1733069649 - 1 * 24 * 60 * 60); // 24h prior: "Sat, 30 Nov 2024 16:14:09 +0000"
4952
$this->config
5053
->expects($this->once())
@@ -64,18 +67,21 @@ public function testRunWithNotExpiredToken(): void { // Affirm if updater.secret
6467
->expects($this->once())
6568
->method('debug');
6669

67-
$this->invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
70+
static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
6871
}
6972

70-
public function testRunWithExpiredToken(): void { // Affirm if updater.secret.created >48 hours ago then `updater.secret` is removed
73+
/**
74+
* Affirm if updater.secret.created >48 hours ago then `updater.secret` is removed
75+
*/
76+
public function testSecretIsRemovedWhenOutdated(): void {
7177
$this->timeFactory
7278
->expects($this->atLeastOnce())
7379
->method('getTime')
7480
->willReturn(1455045234); // "Tue, 09 Feb 2016 19:13:54 +0000"
7581
$this->appConfig
7682
->expects($this->once())
7783
->method('getValueInt')
78-
->with('core', 'updater.secret.created', 1455045234)
84+
->with('core', 'updater.secret.created')
7985
->willReturn(1455045234 - 3 * 24 * 60 * 60); // 72h prior: "Sat, 06 Feb 2016 19:13:54 +0000"
8086
$this->config
8187
->expects($this->once())
@@ -102,8 +108,8 @@ public function testRunWithExpiredToken(): void { // Affirm if updater.secret.cr
102108

103109
public function testRunWithExpiredTokenAndReadOnlyConfigFile(): void { // Affirm if config_is_read_only is set that the secret is never reset
104110
$this->timeFactory
105-
->expects($this->never())
106-
->method('getTime');
111+
->expects($this->never())
112+
->method('getTime');
107113
$this->appConfig
108114
->expects($this->never())
109115
->method('getValueInt');

0 commit comments

Comments
 (0)