Skip to content

Commit

Permalink
Migrate memcache check to SetupCheck API
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Nov 7, 2023
1 parent 9ed9ffd commit 14c5162
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 70 deletions.
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
'OCA\\Settings\\SetupChecks\\FileLocking' => $baseDir . '/../lib/SetupChecks/FileLocking.php',
'OCA\\Settings\\SetupChecks\\InternetConnectivity' => $baseDir . '/../lib/SetupChecks/InternetConnectivity.php',
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => $baseDir . '/../lib/SetupChecks/MemcacheConfigured.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => $baseDir . '/../lib/SetupChecks/PhpGetEnv.php',
'OCA\\Settings\\SetupChecks\\PhpModules' => $baseDir . '/../lib/SetupChecks/PhpModules.php',
Expand Down
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\SetupChecks\\FileLocking' => __DIR__ . '/..' . '/../lib/SetupChecks/FileLocking.php',
'OCA\\Settings\\SetupChecks\\InternetConnectivity' => __DIR__ . '/..' . '/../lib/SetupChecks/InternetConnectivity.php',
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => __DIR__ . '/..' . '/../lib/SetupChecks/MemcacheConfigured.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpGetEnv.php',
'OCA\\Settings\\SetupChecks\\PhpModules' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpModules.php',
Expand Down
2 changes: 2 additions & 0 deletions apps/settings/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
use OCA\Settings\SetupChecks\FileLocking;
use OCA\Settings\SetupChecks\InternetConnectivity;
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
use OCA\Settings\SetupChecks\MemcacheConfigured;
use OCA\Settings\SetupChecks\PhpDefaultCharset;
use OCA\Settings\SetupChecks\PhpModules;
use OCA\Settings\SetupChecks\PhpGetEnv;
Expand Down Expand Up @@ -157,6 +158,7 @@ public function register(IRegistrationContext $context): void {
$context->registerSetupCheck(FileLocking::class);
$context->registerSetupCheck(InternetConnectivity::class);
$context->registerSetupCheck(LegacySSEKeyFormat::class);
$context->registerSetupCheck(MemcacheConfigured::class);
$context->registerSetupCheck(PhpDefaultCharset::class);
$context->registerSetupCheck(PhpModules::class);
$context->registerSetupCheck(PhpGetEnv::class);
Expand Down
10 changes: 0 additions & 10 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,6 @@ private function isFairUseOfFreePushService(): bool {
return $this->manager->isFairUseOfFreePushService();
}

/**
* Checks whether a local memcache is installed or not
* @return bool
*/
private function isMemcacheConfigured() {
return $this->config->getSystemValue('memcache.local', null) !== null;
}

/**
* Whether PHP can generate "secure" pseudorandom integers
*
Expand Down Expand Up @@ -775,8 +767,6 @@ public function check() {
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'isBruteforceThrottled' => $this->throttler->getAttempts($this->request->getRemoteAddress()) !== 0,
'bruteforceRemoteAddress' => $this->request->getRemoteAddress(),
'isMemcacheConfigured' => $this->isMemcacheConfigured(),
'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'),
'isRandomnessSecure' => $this->isRandomnessSecure(),
'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'),
'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(),
Expand Down
60 changes: 60 additions & 0 deletions apps/settings/lib/SetupChecks/MemcacheConfigured.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
*
* @author Côme Chilliet <come.chilliet@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\SetupChecks;

use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class MemcacheConfigured implements ISetupCheck {
public function __construct(
private IL10N $l10n,
private IConfig $config,
private IURLGenerator $urlGenerator,
) {
}

public function getName(): string {
return $this->l10n->t('Memcache');
}

public function getCategory(): string {
return 'system';
}

public function run(): SetupResult {
if ($this->config->getSystemValue('memcache.local', null) !== null) {
return SetupResult::success($this->l10n->t('Configured'));
} else {
return SetupResult::info(
$this->l10n->t('No memory cache has been configured. To enhance performance, please configure a memcache, if available.'),
$this->urlGenerator->linkToDocs('admin-performance')
);
}
}
}
30 changes: 0 additions & 30 deletions apps/settings/tests/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,34 +222,6 @@ public function removeTestDirectories() {
$this->dirsToRemove = [];
}

public function testIsMemcacheConfiguredFalse() {
$this->config->expects($this->once())
->method('getSystemValue')
->with('memcache.local', null)
->willReturn(null);

$this->assertFalse(
self::invokePrivate(
$this->checkSetupController,
'isMemcacheConfigured'
)
);
}

public function testIsMemcacheConfiguredTrue() {
$this->config->expects($this->once())
->method('getSystemValue')
->with('memcache.local', null)
->willReturn('SomeProvider');

$this->assertTrue(
self::invokePrivate(
$this->checkSetupController,
'isMemcacheConfigured'
)
);
}

/**
* @dataProvider dataForwardedForHeadersWorking
*
Expand Down Expand Up @@ -471,8 +443,6 @@ public function testCheck() {
'backgroundJobsUrl' => 'https://example.org',
],
'cronErrors' => [],
'isMemcacheConfigured' => true,
'memcacheDocs' => 'http://docs.example.org/server/go.php?to=admin-performance',
'isRandomnessSecure' => self::invokePrivate($this->checkSetupController, 'isRandomnessSecure'),
'securityDocs' => 'https://docs.example.org/server/8.1/admin_manual/configuration_server/hardening.html',
'isUsedTlsLibOutdated' => '',
Expand Down
8 changes: 0 additions & 8 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,6 @@
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
});
}
if(!data.isMemcacheConfigured) {
messages.push({
msg: t('core', 'No memory cache has been configured. To enhance performance, please configure a memcache, if available. Further information can be found in the {linkstart}documentation ↗{linkend}.')
.replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.memcacheDocs + '">')
.replace('{linkend}', '</a>'),
type: OC.SetupChecks.MESSAGE_TYPE_INFO
});
}
if(!data.isRandomnessSecure) {
messages.push({
msg: t('core', 'No suitable source for randomness found by PHP which is highly discouraged for security reasons. Further information can be found in the {linkstart}documentation ↗{linkend}.')
Expand Down
22 changes: 0 additions & 22 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ describe('OC.SetupChecks tests', function() {
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
memcacheDocs: 'https://docs.nextcloud.com/server/go.php?to=admin-performance',
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -289,7 +288,6 @@ describe('OC.SetupChecks tests', function() {
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
memcacheDocs: 'https://docs.nextcloud.com/server/go.php?to=admin-performance',
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -352,7 +350,6 @@ describe('OC.SetupChecks tests', function() {
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -412,7 +409,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: false,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -470,7 +466,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: false,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -528,7 +523,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -587,7 +581,6 @@ describe('OC.SetupChecks tests', function() {
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: false,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isCorrectMemcachedPHPModuleInstalled: true,
Expand Down Expand Up @@ -647,7 +640,6 @@ describe('OC.SetupChecks tests', function() {
isFairUseOfFreePushService: true,
isBruteforceThrottled: true,
bruteforceRemoteAddress: '::1',
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isCorrectMemcachedPHPModuleInstalled: true,
Expand Down Expand Up @@ -705,7 +697,6 @@ describe('OC.SetupChecks tests', function() {
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isCorrectMemcachedPHPModuleInstalled: true,
Expand Down Expand Up @@ -763,7 +754,6 @@ describe('OC.SetupChecks tests', function() {
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isCorrectMemcachedPHPModuleInstalled: true,
Expand Down Expand Up @@ -842,7 +832,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -907,7 +896,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -965,7 +953,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -1023,7 +1010,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -1085,7 +1071,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -1144,7 +1129,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -1200,7 +1184,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -1259,7 +1242,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -1318,7 +1300,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -1376,7 +1357,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -1434,7 +1414,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down Expand Up @@ -1499,7 +1478,6 @@ describe('OC.SetupChecks tests', function() {
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
isFairUseOfFreePushService: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
Expand Down

0 comments on commit 14c5162

Please sign in to comment.