@@ -19,39 +19,39 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class ResetToken extends TimedJob { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param IConfig $config |
|
| 24 | - * @param ITimeFactory $timeFactory |
|
| 25 | - */ |
|
| 26 | - public function __construct( |
|
| 27 | - ITimeFactory $time, |
|
| 28 | - private IConfig $config, |
|
| 29 | - private IAppConfig $appConfig, |
|
| 30 | - private LoggerInterface $logger, |
|
| 31 | - ) { |
|
| 32 | - parent::__construct($time); |
|
| 33 | - // Run once an hour |
|
| 34 | - parent::setInterval(60 * 60); |
|
| 35 | - } |
|
| 22 | + /** |
|
| 23 | + * @param IConfig $config |
|
| 24 | + * @param ITimeFactory $timeFactory |
|
| 25 | + */ |
|
| 26 | + public function __construct( |
|
| 27 | + ITimeFactory $time, |
|
| 28 | + private IConfig $config, |
|
| 29 | + private IAppConfig $appConfig, |
|
| 30 | + private LoggerInterface $logger, |
|
| 31 | + ) { |
|
| 32 | + parent::__construct($time); |
|
| 33 | + // Run once an hour |
|
| 34 | + parent::setInterval(60 * 60); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param $argument |
|
| 39 | - */ |
|
| 40 | - protected function run($argument) { |
|
| 41 | - if ($this->config->getSystemValueBool('config_is_read_only')) { |
|
| 42 | - $this->logger->debug('Skipping `updater.secret` reset since config_is_read_only is set', ['app' => 'updatenotification']); |
|
| 43 | - return; |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * @param $argument |
|
| 39 | + */ |
|
| 40 | + protected function run($argument) { |
|
| 41 | + if ($this->config->getSystemValueBool('config_is_read_only')) { |
|
| 42 | + $this->logger->debug('Skipping `updater.secret` reset since config_is_read_only is set', ['app' => 'updatenotification']); |
|
| 43 | + return; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - $secretCreated = $this->appConfig->getValueInt('core', 'updater.secret.created'); |
|
| 47 | - // Delete old tokens after 2 days and also tokens without any created date |
|
| 48 | - $secretCreatedDiff = $this->time->getTime() - $secretCreated; |
|
| 49 | - if ($secretCreatedDiff >= 172800) { |
|
| 50 | - $this->config->deleteSystemValue('updater.secret'); |
|
| 51 | - $this->appConfig->deleteKey('core', 'updater.secret.created'); |
|
| 52 | - $this->logger->warning('Cleared old `updater.secret` that was created ' . $secretCreatedDiff . ' seconds ago', ['app' => 'updatenotification']); |
|
| 53 | - } else { |
|
| 54 | - $this->logger->debug('Keeping existing `updater.secret` that was created ' . $secretCreatedDiff . ' seconds ago', ['app' => 'updatenotification']); |
|
| 55 | - } |
|
| 56 | - } |
|
| 46 | + $secretCreated = $this->appConfig->getValueInt('core', 'updater.secret.created'); |
|
| 47 | + // Delete old tokens after 2 days and also tokens without any created date |
|
| 48 | + $secretCreatedDiff = $this->time->getTime() - $secretCreated; |
|
| 49 | + if ($secretCreatedDiff >= 172800) { |
|
| 50 | + $this->config->deleteSystemValue('updater.secret'); |
|
| 51 | + $this->appConfig->deleteKey('core', 'updater.secret.created'); |
|
| 52 | + $this->logger->warning('Cleared old `updater.secret` that was created ' . $secretCreatedDiff . ' seconds ago', ['app' => 'updatenotification']); |
|
| 53 | + } else { |
|
| 54 | + $this->logger->debug('Keeping existing `updater.secret` that was created ' . $secretCreatedDiff . ' seconds ago', ['app' => 'updatenotification']); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -49,9 +49,9 @@ |
||
| 49 | 49 | if ($secretCreatedDiff >= 172800) { |
| 50 | 50 | $this->config->deleteSystemValue('updater.secret'); |
| 51 | 51 | $this->appConfig->deleteKey('core', 'updater.secret.created'); |
| 52 | - $this->logger->warning('Cleared old `updater.secret` that was created ' . $secretCreatedDiff . ' seconds ago', ['app' => 'updatenotification']); |
|
| 52 | + $this->logger->warning('Cleared old `updater.secret` that was created '.$secretCreatedDiff.' seconds ago', ['app' => 'updatenotification']); |
|
| 53 | 53 | } else { |
| 54 | - $this->logger->debug('Keeping existing `updater.secret` that was created ' . $secretCreatedDiff . ' seconds ago', ['app' => 'updatenotification']); |
|
| 54 | + $this->logger->debug('Keeping existing `updater.secret` that was created '.$secretCreatedDiff.' seconds ago', ['app' => 'updatenotification']); |
|
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -25,52 +25,52 @@ |
||
| 25 | 25 | |
| 26 | 26 | class AdminController extends Controller { |
| 27 | 27 | |
| 28 | - public function __construct( |
|
| 29 | - string $appName, |
|
| 30 | - IRequest $request, |
|
| 31 | - private IJobList $jobList, |
|
| 32 | - private ISecureRandom $secureRandom, |
|
| 33 | - private IConfig $config, |
|
| 34 | - private IAppConfig $appConfig, |
|
| 35 | - private ITimeFactory $timeFactory, |
|
| 36 | - private IL10N $l10n, |
|
| 37 | - private LoggerInterface $logger, |
|
| 38 | - ) { |
|
| 39 | - parent::__construct($appName, $request); |
|
| 40 | - } |
|
| 28 | + public function __construct( |
|
| 29 | + string $appName, |
|
| 30 | + IRequest $request, |
|
| 31 | + private IJobList $jobList, |
|
| 32 | + private ISecureRandom $secureRandom, |
|
| 33 | + private IConfig $config, |
|
| 34 | + private IAppConfig $appConfig, |
|
| 35 | + private ITimeFactory $timeFactory, |
|
| 36 | + private IL10N $l10n, |
|
| 37 | + private LoggerInterface $logger, |
|
| 38 | + ) { |
|
| 39 | + parent::__construct($appName, $request); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param string $channel |
|
| 44 | - * @return DataResponse |
|
| 45 | - */ |
|
| 46 | - public function setChannel(string $channel): DataResponse { |
|
| 47 | - Util::setChannel($channel); |
|
| 48 | - $this->appConfig->setValueInt('core', 'lastupdatedat', 0); |
|
| 49 | - return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * @param string $channel |
|
| 44 | + * @return DataResponse |
|
| 45 | + */ |
|
| 46 | + public function setChannel(string $channel): DataResponse { |
|
| 47 | + Util::setChannel($channel); |
|
| 48 | + $this->appConfig->setValueInt('core', 'lastupdatedat', 0); |
|
| 49 | + return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return DataResponse |
|
| 54 | - */ |
|
| 55 | - public function createCredentials(): DataResponse { |
|
| 56 | - if ($this->config->getSystemValueBool('upgrade.disable-web')) { |
|
| 57 | - return new DataResponse(['status' => 'error', 'message' => $this->l10n->t('Web updater is disabled')], Http::STATUS_FORBIDDEN); |
|
| 58 | - } |
|
| 52 | + /** |
|
| 53 | + * @return DataResponse |
|
| 54 | + */ |
|
| 55 | + public function createCredentials(): DataResponse { |
|
| 56 | + if ($this->config->getSystemValueBool('upgrade.disable-web')) { |
|
| 57 | + return new DataResponse(['status' => 'error', 'message' => $this->l10n->t('Web updater is disabled')], Http::STATUS_FORBIDDEN); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - if ($this->config->getSystemValueBool('config_is_read_only')) { |
|
| 61 | - return new DataResponse(['status' => 'error', 'message' => $this->l10n->t('Configuration is read-only')], Http::STATUS_FORBIDDEN); |
|
| 62 | - } |
|
| 60 | + if ($this->config->getSystemValueBool('config_is_read_only')) { |
|
| 61 | + return new DataResponse(['status' => 'error', 'message' => $this->l10n->t('Configuration is read-only')], Http::STATUS_FORBIDDEN); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - // Create a new job and store the creation date |
|
| 65 | - $this->jobList->add(ResetToken::class); |
|
| 66 | - $this->appConfig->setValueInt('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
| 64 | + // Create a new job and store the creation date |
|
| 65 | + $this->jobList->add(ResetToken::class); |
|
| 66 | + $this->appConfig->setValueInt('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
| 67 | 67 | |
| 68 | - // Create a new token |
|
| 69 | - $newToken = $this->secureRandom->generate(64); |
|
| 70 | - $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
| 68 | + // Create a new token |
|
| 69 | + $newToken = $this->secureRandom->generate(64); |
|
| 70 | + $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
| 71 | 71 | |
| 72 | - $this->logger->warning('Created new `updater.secret`', ['app' => 'updatenotification']); |
|
| 72 | + $this->logger->warning('Created new `updater.secret`', ['app' => 'updatenotification']); |
|
| 73 | 73 | |
| 74 | - return new DataResponse($newToken); |
|
| 75 | - } |
|
| 74 | + return new DataResponse($newToken); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -17,122 +17,122 @@ |
||
| 17 | 17 | use Test\TestCase; |
| 18 | 18 | |
| 19 | 19 | class ResetTokenTest extends TestCase { |
| 20 | - protected BackgroundJobResetToken $resetTokenBackgroundJob; |
|
| 20 | + protected BackgroundJobResetToken $resetTokenBackgroundJob; |
|
| 21 | 21 | |
| 22 | - protected IConfig&MockObject $config; |
|
| 23 | - protected IAppConfig&MockObject $appConfig; |
|
| 24 | - protected ITimeFactory&MockObject $timeFactory; |
|
| 25 | - protected LoggerInterface&MockObject $logger; |
|
| 22 | + protected IConfig&MockObject $config; |
|
| 23 | + protected IAppConfig&MockObject $appConfig; |
|
| 24 | + protected ITimeFactory&MockObject $timeFactory; |
|
| 25 | + protected LoggerInterface&MockObject $logger; |
|
| 26 | 26 | |
| 27 | - protected function setUp(): void { |
|
| 28 | - parent::setUp(); |
|
| 29 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 30 | - $this->config = $this->createMock(IConfig::class); |
|
| 31 | - $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 32 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 33 | - $this->resetTokenBackgroundJob = new BackgroundJobResetToken( |
|
| 34 | - $this->timeFactory, |
|
| 35 | - $this->config, |
|
| 36 | - $this->appConfig, |
|
| 37 | - $this->logger, |
|
| 38 | - ); |
|
| 39 | - } |
|
| 27 | + protected function setUp(): void { |
|
| 28 | + parent::setUp(); |
|
| 29 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 30 | + $this->config = $this->createMock(IConfig::class); |
|
| 31 | + $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 32 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 33 | + $this->resetTokenBackgroundJob = new BackgroundJobResetToken( |
|
| 34 | + $this->timeFactory, |
|
| 35 | + $this->config, |
|
| 36 | + $this->appConfig, |
|
| 37 | + $this->logger, |
|
| 38 | + ); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Affirm if updater.secret.created <48 hours ago then `updater.secret` is left alone. |
|
| 43 | - */ |
|
| 44 | - public function testKeepSecretWhenCreatedRecently(): void { |
|
| 45 | - $this->timeFactory |
|
| 46 | - ->expects($this->atLeastOnce()) |
|
| 47 | - ->method('getTime') |
|
| 48 | - ->willReturn(1733069649); // "Sun, 01 Dec 2024 16:14:09 +0000" |
|
| 49 | - $this->appConfig |
|
| 50 | - ->expects($this->once()) |
|
| 51 | - ->method('getValueInt') |
|
| 52 | - ->with('core', 'updater.secret.created') |
|
| 53 | - ->willReturn(1733069649 - 1 * 24 * 60 * 60); // 24h prior: "Sat, 30 Nov 2024 16:14:09 +0000" |
|
| 54 | - $this->config |
|
| 55 | - ->expects($this->once()) |
|
| 56 | - ->method('getSystemValueBool') |
|
| 57 | - ->with('config_is_read_only') |
|
| 58 | - ->willReturn(false); |
|
| 59 | - $this->config |
|
| 60 | - ->expects($this->never()) |
|
| 61 | - ->method('deleteSystemValue'); |
|
| 62 | - $this->appConfig |
|
| 63 | - ->expects($this->never()) |
|
| 64 | - ->method('deleteKey'); |
|
| 65 | - $this->logger |
|
| 66 | - ->expects($this->never()) |
|
| 67 | - ->method('warning'); |
|
| 68 | - $this->logger |
|
| 69 | - ->expects($this->once()) |
|
| 70 | - ->method('debug'); |
|
| 41 | + /** |
|
| 42 | + * Affirm if updater.secret.created <48 hours ago then `updater.secret` is left alone. |
|
| 43 | + */ |
|
| 44 | + public function testKeepSecretWhenCreatedRecently(): void { |
|
| 45 | + $this->timeFactory |
|
| 46 | + ->expects($this->atLeastOnce()) |
|
| 47 | + ->method('getTime') |
|
| 48 | + ->willReturn(1733069649); // "Sun, 01 Dec 2024 16:14:09 +0000" |
|
| 49 | + $this->appConfig |
|
| 50 | + ->expects($this->once()) |
|
| 51 | + ->method('getValueInt') |
|
| 52 | + ->with('core', 'updater.secret.created') |
|
| 53 | + ->willReturn(1733069649 - 1 * 24 * 60 * 60); // 24h prior: "Sat, 30 Nov 2024 16:14:09 +0000" |
|
| 54 | + $this->config |
|
| 55 | + ->expects($this->once()) |
|
| 56 | + ->method('getSystemValueBool') |
|
| 57 | + ->with('config_is_read_only') |
|
| 58 | + ->willReturn(false); |
|
| 59 | + $this->config |
|
| 60 | + ->expects($this->never()) |
|
| 61 | + ->method('deleteSystemValue'); |
|
| 62 | + $this->appConfig |
|
| 63 | + ->expects($this->never()) |
|
| 64 | + ->method('deleteKey'); |
|
| 65 | + $this->logger |
|
| 66 | + ->expects($this->never()) |
|
| 67 | + ->method('warning'); |
|
| 68 | + $this->logger |
|
| 69 | + ->expects($this->once()) |
|
| 70 | + ->method('debug'); |
|
| 71 | 71 | |
| 72 | - static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]); |
|
| 73 | - } |
|
| 72 | + static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Affirm if updater.secret.created >48 hours ago then `updater.secret` is removed |
|
| 77 | - */ |
|
| 78 | - public function testSecretIsRemovedWhenOutdated(): void { |
|
| 79 | - $this->timeFactory |
|
| 80 | - ->expects($this->atLeastOnce()) |
|
| 81 | - ->method('getTime') |
|
| 82 | - ->willReturn(1455045234); // "Tue, 09 Feb 2016 19:13:54 +0000" |
|
| 83 | - $this->appConfig |
|
| 84 | - ->expects($this->once()) |
|
| 85 | - ->method('getValueInt') |
|
| 86 | - ->with('core', 'updater.secret.created') |
|
| 87 | - ->willReturn(1455045234 - 3 * 24 * 60 * 60); // 72h prior: "Sat, 06 Feb 2016 19:13:54 +0000" |
|
| 88 | - $this->config |
|
| 89 | - ->expects($this->once()) |
|
| 90 | - ->method('getSystemValueBool') |
|
| 91 | - ->with('config_is_read_only') |
|
| 92 | - ->willReturn(false); |
|
| 93 | - $this->config |
|
| 94 | - ->expects($this->once()) |
|
| 95 | - ->method('deleteSystemValue') |
|
| 96 | - ->with('updater.secret'); |
|
| 97 | - $this->appConfig |
|
| 98 | - ->expects($this->once()) |
|
| 99 | - ->method('deleteKey') |
|
| 100 | - ->with('core', 'updater.secret.created'); |
|
| 101 | - $this->logger |
|
| 102 | - ->expects($this->once()) |
|
| 103 | - ->method('warning'); |
|
| 104 | - $this->logger |
|
| 105 | - ->expects($this->never()) |
|
| 106 | - ->method('debug'); |
|
| 75 | + /** |
|
| 76 | + * Affirm if updater.secret.created >48 hours ago then `updater.secret` is removed |
|
| 77 | + */ |
|
| 78 | + public function testSecretIsRemovedWhenOutdated(): void { |
|
| 79 | + $this->timeFactory |
|
| 80 | + ->expects($this->atLeastOnce()) |
|
| 81 | + ->method('getTime') |
|
| 82 | + ->willReturn(1455045234); // "Tue, 09 Feb 2016 19:13:54 +0000" |
|
| 83 | + $this->appConfig |
|
| 84 | + ->expects($this->once()) |
|
| 85 | + ->method('getValueInt') |
|
| 86 | + ->with('core', 'updater.secret.created') |
|
| 87 | + ->willReturn(1455045234 - 3 * 24 * 60 * 60); // 72h prior: "Sat, 06 Feb 2016 19:13:54 +0000" |
|
| 88 | + $this->config |
|
| 89 | + ->expects($this->once()) |
|
| 90 | + ->method('getSystemValueBool') |
|
| 91 | + ->with('config_is_read_only') |
|
| 92 | + ->willReturn(false); |
|
| 93 | + $this->config |
|
| 94 | + ->expects($this->once()) |
|
| 95 | + ->method('deleteSystemValue') |
|
| 96 | + ->with('updater.secret'); |
|
| 97 | + $this->appConfig |
|
| 98 | + ->expects($this->once()) |
|
| 99 | + ->method('deleteKey') |
|
| 100 | + ->with('core', 'updater.secret.created'); |
|
| 101 | + $this->logger |
|
| 102 | + ->expects($this->once()) |
|
| 103 | + ->method('warning'); |
|
| 104 | + $this->logger |
|
| 105 | + ->expects($this->never()) |
|
| 106 | + ->method('debug'); |
|
| 107 | 107 | |
| 108 | - $this->invokePrivate($this->resetTokenBackgroundJob, 'run', [null]); |
|
| 109 | - } |
|
| 108 | + $this->invokePrivate($this->resetTokenBackgroundJob, 'run', [null]); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public function testRunWithExpiredTokenAndReadOnlyConfigFile(): void { // Affirm if config_is_read_only is set that the secret is never reset |
|
| 112 | - $this->timeFactory |
|
| 113 | - ->expects($this->never()) |
|
| 114 | - ->method('getTime'); |
|
| 115 | - $this->appConfig |
|
| 116 | - ->expects($this->never()) |
|
| 117 | - ->method('getValueInt'); |
|
| 118 | - $this->config |
|
| 119 | - ->expects($this->once()) |
|
| 120 | - ->method('getSystemValueBool') |
|
| 121 | - ->with('config_is_read_only') |
|
| 122 | - ->willReturn(true); |
|
| 123 | - $this->config |
|
| 124 | - ->expects($this->never()) |
|
| 125 | - ->method('deleteSystemValue'); |
|
| 126 | - $this->appConfig |
|
| 127 | - ->expects($this->never()) |
|
| 128 | - ->method('deleteKey'); |
|
| 129 | - $this->logger |
|
| 130 | - ->expects($this->never()) |
|
| 131 | - ->method('warning'); |
|
| 132 | - $this->logger |
|
| 133 | - ->expects($this->once()) |
|
| 134 | - ->method('debug'); |
|
| 111 | + public function testRunWithExpiredTokenAndReadOnlyConfigFile(): void { // Affirm if config_is_read_only is set that the secret is never reset |
|
| 112 | + $this->timeFactory |
|
| 113 | + ->expects($this->never()) |
|
| 114 | + ->method('getTime'); |
|
| 115 | + $this->appConfig |
|
| 116 | + ->expects($this->never()) |
|
| 117 | + ->method('getValueInt'); |
|
| 118 | + $this->config |
|
| 119 | + ->expects($this->once()) |
|
| 120 | + ->method('getSystemValueBool') |
|
| 121 | + ->with('config_is_read_only') |
|
| 122 | + ->willReturn(true); |
|
| 123 | + $this->config |
|
| 124 | + ->expects($this->never()) |
|
| 125 | + ->method('deleteSystemValue'); |
|
| 126 | + $this->appConfig |
|
| 127 | + ->expects($this->never()) |
|
| 128 | + ->method('deleteKey'); |
|
| 129 | + $this->logger |
|
| 130 | + ->expects($this->never()) |
|
| 131 | + ->method('warning'); |
|
| 132 | + $this->logger |
|
| 133 | + ->expects($this->once()) |
|
| 134 | + ->method('debug'); |
|
| 135 | 135 | |
| 136 | - $this->invokePrivate($this->resetTokenBackgroundJob, 'run', [null]); |
|
| 137 | - } |
|
| 136 | + $this->invokePrivate($this->resetTokenBackgroundJob, 'run', [null]); |
|
| 137 | + } |
|
| 138 | 138 | } |
@@ -23,91 +23,91 @@ |
||
| 23 | 23 | use Test\TestCase; |
| 24 | 24 | |
| 25 | 25 | class AdminControllerTest extends TestCase { |
| 26 | - protected IRequest&MockObject $request; |
|
| 27 | - protected IJobList&MockObject $jobList; |
|
| 28 | - protected ISecureRandom&MockObject $secureRandom; |
|
| 29 | - protected IConfig&MockObject $config; |
|
| 30 | - protected ITimeFactory&MockObject $timeFactory; |
|
| 31 | - protected IL10N&MockObject $l10n; |
|
| 32 | - protected IAppConfig&MockObject $appConfig; |
|
| 33 | - protected LoggerInterface&MockObject $logger; |
|
| 26 | + protected IRequest&MockObject $request; |
|
| 27 | + protected IJobList&MockObject $jobList; |
|
| 28 | + protected ISecureRandom&MockObject $secureRandom; |
|
| 29 | + protected IConfig&MockObject $config; |
|
| 30 | + protected ITimeFactory&MockObject $timeFactory; |
|
| 31 | + protected IL10N&MockObject $l10n; |
|
| 32 | + protected IAppConfig&MockObject $appConfig; |
|
| 33 | + protected LoggerInterface&MockObject $logger; |
|
| 34 | 34 | |
| 35 | - protected AdminController $adminController; |
|
| 35 | + protected AdminController $adminController; |
|
| 36 | 36 | |
| 37 | - protected function setUp(): void { |
|
| 38 | - parent::setUp(); |
|
| 37 | + protected function setUp(): void { |
|
| 38 | + parent::setUp(); |
|
| 39 | 39 | |
| 40 | - $this->request = $this->createMock(IRequest::class); |
|
| 41 | - $this->jobList = $this->createMock(IJobList::class); |
|
| 42 | - $this->secureRandom = $this->createMock(ISecureRandom::class); |
|
| 43 | - $this->config = $this->createMock(IConfig::class); |
|
| 44 | - $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 45 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 46 | - $this->l10n = $this->createMock(IL10N::class); |
|
| 47 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 40 | + $this->request = $this->createMock(IRequest::class); |
|
| 41 | + $this->jobList = $this->createMock(IJobList::class); |
|
| 42 | + $this->secureRandom = $this->createMock(ISecureRandom::class); |
|
| 43 | + $this->config = $this->createMock(IConfig::class); |
|
| 44 | + $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 45 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 46 | + $this->l10n = $this->createMock(IL10N::class); |
|
| 47 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 48 | 48 | |
| 49 | - $this->adminController = new AdminController( |
|
| 50 | - 'updatenotification', |
|
| 51 | - $this->request, |
|
| 52 | - $this->jobList, |
|
| 53 | - $this->secureRandom, |
|
| 54 | - $this->config, |
|
| 55 | - $this->appConfig, |
|
| 56 | - $this->timeFactory, |
|
| 57 | - $this->l10n, |
|
| 58 | - $this->logger, |
|
| 59 | - ); |
|
| 60 | - } |
|
| 49 | + $this->adminController = new AdminController( |
|
| 50 | + 'updatenotification', |
|
| 51 | + $this->request, |
|
| 52 | + $this->jobList, |
|
| 53 | + $this->secureRandom, |
|
| 54 | + $this->config, |
|
| 55 | + $this->appConfig, |
|
| 56 | + $this->timeFactory, |
|
| 57 | + $this->l10n, |
|
| 58 | + $this->logger, |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function testCreateCredentials(): void { |
|
| 63 | - $this->jobList |
|
| 64 | - ->expects($this->once()) |
|
| 65 | - ->method('add') |
|
| 66 | - ->with(ResetToken::class); |
|
| 67 | - $this->secureRandom |
|
| 68 | - ->expects($this->once()) |
|
| 69 | - ->method('generate') |
|
| 70 | - ->with(64) |
|
| 71 | - ->willReturn('MyGeneratedToken'); |
|
| 72 | - $this->config |
|
| 73 | - ->expects($this->once()) |
|
| 74 | - ->method('setSystemValue') |
|
| 75 | - ->with('updater.secret'); |
|
| 76 | - $this->timeFactory |
|
| 77 | - ->expects($this->once()) |
|
| 78 | - ->method('getTime') |
|
| 79 | - ->willReturn(12345); |
|
| 80 | - $this->appConfig |
|
| 81 | - ->expects($this->once()) |
|
| 82 | - ->method('setValueInt') |
|
| 83 | - ->with('core', 'updater.secret.created', 12345); |
|
| 62 | + public function testCreateCredentials(): void { |
|
| 63 | + $this->jobList |
|
| 64 | + ->expects($this->once()) |
|
| 65 | + ->method('add') |
|
| 66 | + ->with(ResetToken::class); |
|
| 67 | + $this->secureRandom |
|
| 68 | + ->expects($this->once()) |
|
| 69 | + ->method('generate') |
|
| 70 | + ->with(64) |
|
| 71 | + ->willReturn('MyGeneratedToken'); |
|
| 72 | + $this->config |
|
| 73 | + ->expects($this->once()) |
|
| 74 | + ->method('setSystemValue') |
|
| 75 | + ->with('updater.secret'); |
|
| 76 | + $this->timeFactory |
|
| 77 | + ->expects($this->once()) |
|
| 78 | + ->method('getTime') |
|
| 79 | + ->willReturn(12345); |
|
| 80 | + $this->appConfig |
|
| 81 | + ->expects($this->once()) |
|
| 82 | + ->method('setValueInt') |
|
| 83 | + ->with('core', 'updater.secret.created', 12345); |
|
| 84 | 84 | |
| 85 | - $expected = new DataResponse('MyGeneratedToken'); |
|
| 86 | - $this->assertEquals($expected, $this->adminController->createCredentials()); |
|
| 87 | - } |
|
| 85 | + $expected = new DataResponse('MyGeneratedToken'); |
|
| 86 | + $this->assertEquals($expected, $this->adminController->createCredentials()); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - public function testCreateCredentialsAndWebUpdaterDisabled(): void { |
|
| 90 | - $this->config |
|
| 91 | - ->expects($this->once()) |
|
| 92 | - ->method('getSystemValueBool') |
|
| 93 | - ->with('upgrade.disable-web') |
|
| 94 | - ->willReturn(true); |
|
| 95 | - $this->jobList |
|
| 96 | - ->expects($this->never()) |
|
| 97 | - ->method('add'); |
|
| 98 | - $this->secureRandom |
|
| 99 | - ->expects($this->never()) |
|
| 100 | - ->method('generate'); |
|
| 101 | - $this->config |
|
| 102 | - ->expects($this->never()) |
|
| 103 | - ->method('setSystemValue'); |
|
| 104 | - $this->timeFactory |
|
| 105 | - ->expects($this->never()) |
|
| 106 | - ->method('getTime'); |
|
| 107 | - $this->appConfig |
|
| 108 | - ->expects($this->never()) |
|
| 109 | - ->method('setValueInt'); |
|
| 89 | + public function testCreateCredentialsAndWebUpdaterDisabled(): void { |
|
| 90 | + $this->config |
|
| 91 | + ->expects($this->once()) |
|
| 92 | + ->method('getSystemValueBool') |
|
| 93 | + ->with('upgrade.disable-web') |
|
| 94 | + ->willReturn(true); |
|
| 95 | + $this->jobList |
|
| 96 | + ->expects($this->never()) |
|
| 97 | + ->method('add'); |
|
| 98 | + $this->secureRandom |
|
| 99 | + ->expects($this->never()) |
|
| 100 | + ->method('generate'); |
|
| 101 | + $this->config |
|
| 102 | + ->expects($this->never()) |
|
| 103 | + ->method('setSystemValue'); |
|
| 104 | + $this->timeFactory |
|
| 105 | + ->expects($this->never()) |
|
| 106 | + ->method('getTime'); |
|
| 107 | + $this->appConfig |
|
| 108 | + ->expects($this->never()) |
|
| 109 | + ->method('setValueInt'); |
|
| 110 | 110 | |
| 111 | - $this->adminController->createCredentials(); |
|
| 112 | - } |
|
| 111 | + $this->adminController->createCredentials(); |
|
| 112 | + } |
|
| 113 | 113 | } |