diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-10-26 15:51:51 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-11-07 12:25:03 +0100 |
commit | 086d3ceecc211f255dd24e6ffaed553a6ca2046d (patch) | |
tree | fe562be92cf748d1dbee6d5b5cfadd28df7cd31e | |
parent | 147b29fca2f36cc0d633486e30b7694c157b26e0 (diff) | |
download | nextcloud-server-086d3ceecc211f255dd24e6ffaed553a6ca2046d.tar.gz nextcloud-server-086d3ceecc211f255dd24e6ffaed553a6ca2046d.zip |
Migrate code integrity to SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | apps/settings/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | apps/settings/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | apps/settings/lib/AppInfo/Application.php | 2 | ||||
-rw-r--r-- | apps/settings/lib/Controller/CheckSetupController.php | 2 | ||||
-rw-r--r-- | apps/settings/lib/SetupChecks/CodeIntegrity.php | 63 | ||||
-rw-r--r-- | apps/settings/tests/Controller/CheckSetupControllerTest.php | 2 | ||||
-rw-r--r-- | core/js/setupchecks.js | 10 | ||||
-rw-r--r-- | core/js/tests/specs/setupchecksSpec.js | 21 |
8 files changed, 67 insertions, 35 deletions
diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index c69b49ec309..d18528ff4d4 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -74,6 +74,7 @@ return array( 'OCA\\Settings\\Settings\\Personal\\Security\\WebAuthn' => $baseDir . '/../lib/Settings/Personal/Security/WebAuthn.php', 'OCA\\Settings\\Settings\\Personal\\ServerDevNotice' => $baseDir . '/../lib/Settings/Personal/ServerDevNotice.php', 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => $baseDir . '/../lib/SetupChecks/CheckUserCertificates.php', + 'OCA\\Settings\\SetupChecks\\CodeIntegrity' => $baseDir . '/../lib/SetupChecks/CodeIntegrity.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => $baseDir . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => $baseDir . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\FileLocking' => $baseDir . '/../lib/SetupChecks/FileLocking.php', diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index eba8fadc98a..5512082304f 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -89,6 +89,7 @@ class ComposerStaticInitSettings 'OCA\\Settings\\Settings\\Personal\\Security\\WebAuthn' => __DIR__ . '/..' . '/../lib/Settings/Personal/Security/WebAuthn.php', 'OCA\\Settings\\Settings\\Personal\\ServerDevNotice' => __DIR__ . '/..' . '/../lib/Settings/Personal/ServerDevNotice.php', 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => __DIR__ . '/..' . '/../lib/SetupChecks/CheckUserCertificates.php', + 'OCA\\Settings\\SetupChecks\\CodeIntegrity' => __DIR__ . '/..' . '/../lib/SetupChecks/CodeIntegrity.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => __DIR__ . '/..' . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => __DIR__ . '/..' . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\FileLocking' => __DIR__ . '/..' . '/../lib/SetupChecks/FileLocking.php', diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index 0770418c3bb..518dc88bfa0 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -49,6 +49,7 @@ use OCA\Settings\Search\AppSearch; use OCA\Settings\Search\SectionSearch; use OCA\Settings\Search\UserSearch; use OCA\Settings\SetupChecks\CheckUserCertificates; +use OCA\Settings\SetupChecks\CodeIntegrity; use OCA\Settings\SetupChecks\DefaultPhoneRegionSet; use OCA\Settings\SetupChecks\EmailTestSuccessful; use OCA\Settings\SetupChecks\FileLocking; @@ -154,6 +155,7 @@ class Application extends App implements IBootstrap { ); }); $context->registerSetupCheck(CheckUserCertificates::class); + $context->registerSetupCheck(CodeIntegrity::class); $context->registerSetupCheck(DefaultPhoneRegionSet::class); $context->registerSetupCheck(EmailTestSuccessful::class); $context->registerSetupCheck(FileLocking::class); diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index f5849cce5a8..80dd6952980 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -752,8 +752,6 @@ Raw output 'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(), 'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'), 'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(), - 'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(), - 'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'), 'OpcacheSetupRecommendations' => $this->getOpcacheSetupRecommendations(), 'isSettimelimitAvailable' => $this->isSettimelimitAvailable(), 'hasFreeTypeSupport' => $this->hasFreeTypeSupport(), diff --git a/apps/settings/lib/SetupChecks/CodeIntegrity.php b/apps/settings/lib/SetupChecks/CodeIntegrity.php new file mode 100644 index 00000000000..234e1fbf058 --- /dev/null +++ b/apps/settings/lib/SetupChecks/CodeIntegrity.php @@ -0,0 +1,63 @@ +<?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 OC\IntegrityCheck\Checker; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\SetupCheck\ISetupCheck; +use OCP\SetupCheck\SetupResult; + +class CodeIntegrity implements ISetupCheck { + public function __construct( + private IL10N $l10n, + private IURLGenerator $urlGenerator, + private Checker $checker, + ) { + } + + public function getName(): string { + return $this->l10n->t('Code integrity'); + } + + public function getCategory(): string { + return 'security'; + } + + public function run(): SetupResult { + if (!$this->checker->isCodeCheckEnforced()) { + return SetupResult::info($this->l10n->t('Integrity checker has been disabled. Integrity cannot be verified.')); + } elseif ($this->checker->hasPassedCheck()) { + return SetupResult::success($this->l10n->t('No altered files')); + } else { + // FIXME: If setup check can link to settings pages this should link to /settings/integrity/failed and /settings/integrity/rescan?requesttoken=TOKEN + return SetupResult::error( + $this->l10n->t('Some files have not passed the integrity check.'), + $this->urlGenerator->linkToDocs('admin-code-integrity') + ); + } + } +} diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php index 693d80744ce..86305aecdc6 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -442,8 +442,6 @@ class CheckSetupControllerTest extends TestCase { 'forwardedForHeadersWorking' => false, 'reverseProxyDocs' => 'reverse-proxy-doc-link', 'isCorrectMemcachedPHPModuleInstalled' => true, - 'hasPassedCodeIntegrityCheck' => true, - 'codeIntegrityCheckerDocumentation' => 'http://docs.example.org/server/go.php?to=admin-code-integrity', 'OpcacheSetupRecommendations' => ['recommendation1', 'recommendation2'], 'isSettimelimitAvailable' => true, 'hasFreeTypeSupport' => false, diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js index 029096b43b2..80b6e077578 100644 --- a/core/js/setupchecks.js +++ b/core/js/setupchecks.js @@ -246,16 +246,6 @@ type: OC.SetupChecks.MESSAGE_TYPE_WARNING }); } - if(!data.hasPassedCodeIntegrityCheck) { - messages.push({ - msg: t('core', 'Some files have not passed the integrity check. Further information on how to resolve this issue can be found in the {linkstart1}documentation ↗{linkend}. ({linkstart2}List of invalid files…{linkend} / {linkstart3}Rescan…{linkend})') - .replace('{linkstart1}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.codeIntegrityCheckerDocumentation + '">') - .replace('{linkstart2}', '<a href="' + OC.generateUrl('/settings/integrity/failed') + '">') - .replace('{linkstart3}', '<a href="' + OC.generateUrl('/settings/integrity/rescan?requesttoken={requesttoken}', {'requesttoken': OC.requestToken}) + '">') - .replace(/{linkend}/g, '</a>'), - type: OC.SetupChecks.MESSAGE_TYPE_ERROR - }); - } if(data.OpcacheSetupRecommendations.length > 0) { var listOfOPcacheRecommendations = ""; data.OpcacheSetupRecommendations.forEach(function(element){ diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js index eaea1d2f5b8..fc5fa35a64e 100644 --- a/core/js/tests/specs/setupchecksSpec.js +++ b/core/js/tests/specs/setupchecksSpec.js @@ -227,7 +227,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -284,7 +283,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -341,7 +339,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -398,7 +395,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: false, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -453,7 +449,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -511,7 +506,6 @@ describe('OC.SetupChecks tests', function() { forwardedForHeadersWorking: false, reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html', isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -569,7 +563,6 @@ describe('OC.SetupChecks tests', function() { forwardedForHeadersWorking: true, reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html', isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -625,7 +618,6 @@ describe('OC.SetupChecks tests', function() { forwardedForHeadersWorking: true, reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html', isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: false, hasFreeTypeSupport: true, @@ -681,7 +673,6 @@ describe('OC.SetupChecks tests', function() { forwardedForHeadersWorking: true, reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html', isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -756,7 +747,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -818,7 +808,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: ['recommendation1', 'recommendation2'], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -873,7 +862,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: false, @@ -928,7 +916,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -987,7 +974,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -1043,7 +1029,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -1096,7 +1081,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -1152,7 +1136,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -1208,7 +1191,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -1263,7 +1245,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -1318,7 +1299,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, @@ -1380,7 +1360,6 @@ describe('OC.SetupChecks tests', function() { isFairUseOfFreePushService: true, forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, - hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, hasFreeTypeSupport: true, |