aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2023-10-19 15:41:23 +0200
committerGitHub <noreply@github.com>2023-10-19 15:41:23 +0200
commitb6c35b3be0a2c2a26e6409990a3855c36fa06ce9 (patch)
tree8c00ba871704c3a2dbf982704cbb3389bb66d8a8 /apps/settings
parent049804d02f05c6dc26109b25aec965e8f3188665 (diff)
parent789ff3f414fe9d128b6831b9981b2425ce0849d0 (diff)
downloadnextcloud-server-b6c35b3be0a2c2a26e6409990a3855c36fa06ce9.tar.gz
nextcloud-server-b6c35b3be0a2c2a26e6409990a3855c36fa06ce9.zip
Merge pull request #32550 from nextcloud/feat/api-cleanup-check
Add api to register setup checks
Diffstat (limited to 'apps/settings')
-rw-r--r--apps/settings/appinfo/routes.php1
-rw-r--r--apps/settings/composer/composer/autoload_classmap.php6
-rw-r--r--apps/settings/composer/composer/autoload_static.php6
-rw-r--r--apps/settings/lib/AppInfo/Application.php18
-rw-r--r--apps/settings/lib/Controller/CheckSetupController.php107
-rw-r--r--apps/settings/lib/SetupChecks/CheckUserCertificates.php54
-rw-r--r--apps/settings/lib/SetupChecks/DefaultPhoneRegionSet.php58
-rw-r--r--apps/settings/lib/SetupChecks/InternetConnectivity.php100
-rw-r--r--apps/settings/lib/SetupChecks/LdapInvalidUuids.php69
-rw-r--r--apps/settings/lib/SetupChecks/LegacySSEKeyFormat.php41
-rw-r--r--apps/settings/lib/SetupChecks/NeedsSystemAddressBookSync.php46
-rw-r--r--apps/settings/lib/SetupChecks/PhpDefaultCharset.php27
-rw-r--r--apps/settings/lib/SetupChecks/PhpOutdated.php54
-rw-r--r--apps/settings/lib/SetupChecks/PhpOutputBuffering.php27
-rw-r--r--apps/settings/lib/SetupChecks/ReadOnlyConfig.php55
-rw-r--r--apps/settings/lib/SetupChecks/SupportedDatabase.php55
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php144
-rw-r--r--apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php26
-rw-r--r--apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php22
-rw-r--r--apps/settings/tests/SetupChecks/SupportedDatabaseTest.php3
20 files changed, 463 insertions, 456 deletions
diff --git a/apps/settings/appinfo/routes.php b/apps/settings/appinfo/routes.php
index e238510b1a7..266237eabce 100644
--- a/apps/settings/appinfo/routes.php
+++ b/apps/settings/appinfo/routes.php
@@ -65,6 +65,7 @@ return [
['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST' , 'root' => ''],
['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET' , 'root' => ''],
['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET' , 'root' => ''],
+ ['name' => 'CheckSetup#setupCheckManager', 'url' => '/settings/setupcheck', 'verb' => 'GET' , 'root' => ''],
['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET' , 'root' => ''],
['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET' , 'root' => ''],
['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET' , 'root' => ''],
diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php
index a1e0b7632ca..c6b768e8b33 100644
--- a/apps/settings/composer/composer/autoload_classmap.php
+++ b/apps/settings/composer/composer/autoload_classmap.php
@@ -74,11 +74,13 @@ 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\\LdapInvalidUuids' => $baseDir . '/../lib/SetupChecks/LdapInvalidUuids.php',
+ 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => $baseDir . '/../lib/SetupChecks/DefaultPhoneRegionSet.php',
+ 'OCA\\Settings\\SetupChecks\\InternetConnectivity' => $baseDir . '/../lib/SetupChecks/InternetConnectivity.php',
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
- 'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync' => $baseDir . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
+ 'OCA\\Settings\\SetupChecks\\PhpOutdated' => $baseDir . '/../lib/SetupChecks/PhpOutdated.php',
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php',
+ 'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => $baseDir . '/../lib/SetupChecks/ReadOnlyConfig.php',
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => $baseDir . '/../lib/SetupChecks/SupportedDatabase.php',
'OCA\\Settings\\UserMigration\\AccountMigrator' => $baseDir . '/../lib/UserMigration/AccountMigrator.php',
'OCA\\Settings\\UserMigration\\AccountMigratorException' => $baseDir . '/../lib/UserMigration/AccountMigratorException.php',
diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php
index 1eef91c5d91..09053435970 100644
--- a/apps/settings/composer/composer/autoload_static.php
+++ b/apps/settings/composer/composer/autoload_static.php
@@ -89,11 +89,13 @@ 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\\LdapInvalidUuids' => __DIR__ . '/..' . '/../lib/SetupChecks/LdapInvalidUuids.php',
+ 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => __DIR__ . '/..' . '/../lib/SetupChecks/DefaultPhoneRegionSet.php',
+ 'OCA\\Settings\\SetupChecks\\InternetConnectivity' => __DIR__ . '/..' . '/../lib/SetupChecks/InternetConnectivity.php',
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
- 'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync' => __DIR__ . '/..' . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
+ 'OCA\\Settings\\SetupChecks\\PhpOutdated' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutdated.php',
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',
+ 'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => __DIR__ . '/..' . '/../lib/SetupChecks/ReadOnlyConfig.php',
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => __DIR__ . '/..' . '/../lib/SetupChecks/SupportedDatabase.php',
'OCA\\Settings\\UserMigration\\AccountMigrator' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigrator.php',
'OCA\\Settings\\UserMigration\\AccountMigratorException' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigratorException.php',
diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php
index c69826f7842..e6106cb9b1e 100644
--- a/apps/settings/lib/AppInfo/Application.php
+++ b/apps/settings/lib/AppInfo/Application.php
@@ -48,6 +48,15 @@ use OCA\Settings\Middleware\SubadminMiddleware;
use OCA\Settings\Search\AppSearch;
use OCA\Settings\Search\SectionSearch;
use OCA\Settings\Search\UserSearch;
+use OCA\Settings\SetupChecks\CheckUserCertificates;
+use OCA\Settings\SetupChecks\DefaultPhoneRegionSet;
+use OCA\Settings\SetupChecks\InternetConnectivity;
+use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
+use OCA\Settings\SetupChecks\PhpDefaultCharset;
+use OCA\Settings\SetupChecks\PhpOutdated;
+use OCA\Settings\SetupChecks\PhpOutputBuffering;
+use OCA\Settings\SetupChecks\ReadOnlyConfig;
+use OCA\Settings\SetupChecks\SupportedDatabase;
use OCA\Settings\UserMigration\AccountMigrator;
use OCA\Settings\WellKnown\ChangePasswordHandler;
use OCA\Settings\WellKnown\SecurityTxtHandler;
@@ -137,6 +146,15 @@ class Application extends App implements IBootstrap {
Util::getDefaultEmailAddress('no-reply')
);
});
+ $context->registerSetupCheck(CheckUserCertificates::class);
+ $context->registerSetupCheck(DefaultPhoneRegionSet::class);
+ $context->registerSetupCheck(InternetConnectivity::class);
+ $context->registerSetupCheck(LegacySSEKeyFormat::class);
+ $context->registerSetupCheck(PhpDefaultCharset::class);
+ $context->registerSetupCheck(PhpOutdated::class);
+ $context->registerSetupCheck(PhpOutputBuffering::class);
+ $context->registerSetupCheck(ReadOnlyConfig::class);
+ $context->registerSetupCheck(SupportedDatabase::class);
$context->registerUserMigrator(AccountMigrator::class);
}
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php
index 5dcf6cda29c..b2da455bc11 100644
--- a/apps/settings/lib/Controller/CheckSetupController.php
+++ b/apps/settings/lib/Controller/CheckSetupController.php
@@ -48,7 +48,6 @@ namespace OCA\Settings\Controller;
use bantu\IniGetWrapper\IniGetWrapper;
use DirectoryIterator;
use Doctrine\DBAL\Exception;
-use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\TransactionIsolationLevel;
use GuzzleHttp\Exception\ClientException;
use OC;
@@ -62,13 +61,6 @@ use OC\IntegrityCheck\Checker;
use OC\Lock\NoopLockingProvider;
use OC\Lock\DBLockingProvider;
use OC\MemoryInfo;
-use OCA\Settings\SetupChecks\CheckUserCertificates;
-use OCA\Settings\SetupChecks\NeedsSystemAddressBookSync;
-use OCA\Settings\SetupChecks\LdapInvalidUuids;
-use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
-use OCA\Settings\SetupChecks\PhpDefaultCharset;
-use OCA\Settings\SetupChecks\PhpOutputBuffering;
-use OCA\Settings\SetupChecks\SupportedDatabase;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
@@ -93,6 +85,7 @@ use OCP\Lock\ILockingProvider;
use OCP\Notification\IManager;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\ISecureRandom;
+use OCP\SetupCheck\ISetupCheckManager;
use Psr\Log\LoggerInterface;
#[IgnoreOpenAPI]
@@ -135,6 +128,7 @@ class CheckSetupController extends Controller {
private $appManager;
/** @var IServerContainer */
private $serverContainer;
+ private ISetupCheckManager $setupCheckManager;
public function __construct($AppName,
IRequest $request,
@@ -156,7 +150,8 @@ class CheckSetupController extends Controller {
ITempManager $tempManager,
IManager $manager,
IAppManager $appManager,
- IServerContainer $serverContainer
+ IServerContainer $serverContainer,
+ ISetupCheckManager $setupCheckManager,
) {
parent::__construct($AppName, $request);
$this->config = $config;
@@ -178,62 +173,24 @@ class CheckSetupController extends Controller {
$this->manager = $manager;
$this->appManager = $appManager;
$this->serverContainer = $serverContainer;
+ $this->setupCheckManager = $setupCheckManager;
}
/**
- * Check if is fair use of free push service
- * @return bool
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @return DataResponse
*/
- private function isFairUseOfFreePushService(): bool {
- return $this->manager->isFairUseOfFreePushService();
+ public function setupCheckManager(): DataResponse {
+ return new DataResponse($this->setupCheckManager->runAll());
}
/**
- * Checks if the server can connect to the internet using HTTPS and HTTP
- * @return bool
- */
- private function hasInternetConnectivityProblems(): bool {
- if ($this->config->getSystemValue('has_internet_connection', true) === false) {
- return false;
- }
-
- $siteArray = $this->config->getSystemValue('connectivity_check_domains', [
- 'www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'
- ]);
-
- foreach ($siteArray as $site) {
- if ($this->isSiteReachable($site)) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Checks if the Nextcloud server can connect to a specific URL
- * @param string $site site domain or full URL with http/https protocol
+ * Check if is fair use of free push service
* @return bool
*/
- private function isSiteReachable(string $site): bool {
- try {
- $client = $this->clientService->newClient();
- // if there is no protocol, test http:// AND https://
- if (preg_match('/^https?:\/\//', $site) !== 1) {
- $httpSite = 'http://' . $site . '/';
- $client->get($httpSite);
- $httpsSite = 'https://' . $site . '/';
- $client->get($httpsSite);
- } else {
- $client->get($site);
- }
- } catch (\Exception $e) {
- $this->logger->error('Cannot connect to: ' . $site, [
- 'app' => 'internet_connection_check',
- 'exception' => $e,
- ]);
- return false;
- }
- return true;
+ private function isFairUseOfFreePushService(): bool {
+ return $this->manager->isFairUseOfFreePushService();
}
/**
@@ -326,25 +283,6 @@ class CheckSetupController extends Controller {
}
/**
- * Whether the version is outdated
- *
- * @return bool
- */
- protected function isPhpOutdated(): bool {
- return PHP_VERSION_ID < 80100;
- }
-
- /**
- * Whether the php version is still supported (at time of release)
- * according to: https://www.php.net/supported-versions.php
- *
- * @return array
- */
- private function isPhpSupported(): array {
- return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION];
- }
-
- /**
* Check if the reverse proxy configuration is working as expected
*
* @return bool
@@ -906,14 +844,6 @@ Raw output
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
*/
public function check() {
- $phpDefaultCharset = new PhpDefaultCharset();
- $phpOutputBuffering = new PhpOutputBuffering();
- $legacySSEKeyFormat = new LegacySSEKeyFormat($this->l10n, $this->config, $this->urlGenerator);
- $checkUserCertificates = new CheckUserCertificates($this->l10n, $this->config, $this->urlGenerator);
- $supportedDatabases = new SupportedDatabase($this->l10n, $this->connection);
- $ldapInvalidUuids = new LdapInvalidUuids($this->appManager, $this->l10n, $this->serverContainer);
- $needsSystemAddressBookSync = new NeedsSystemAddressBookSync($this->config, $this->l10n);
-
return new DataResponse(
[
'isGetenvServerWorking' => !empty(getenv('PATH')),
@@ -929,13 +859,11 @@ Raw output
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'isBruteforceThrottled' => $this->throttler->getAttempts($this->request->getRemoteAddress()) !== 0,
'bruteforceRemoteAddress' => $this->request->getRemoteAddress(),
- 'serverHasInternetConnectionProblems' => $this->hasInternetConnectivityProblems(),
'isMemcacheConfigured' => $this->isMemcacheConfigured(),
'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'),
'isRandomnessSecure' => $this->isRandomnessSecure(),
'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'),
'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(),
- 'phpSupported' => $this->isPhpSupported(),
'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(),
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(),
@@ -960,15 +888,8 @@ Raw output
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
'imageMagickLacksSVGSupport' => $this->imageMagickLacksSVGSupport(),
- PhpDefaultCharset::class => ['pass' => $phpDefaultCharset->run(), 'description' => $phpDefaultCharset->description(), 'severity' => $phpDefaultCharset->severity()],
- PhpOutputBuffering::class => ['pass' => $phpOutputBuffering->run(), 'description' => $phpOutputBuffering->description(), 'severity' => $phpOutputBuffering->severity()],
- LegacySSEKeyFormat::class => ['pass' => $legacySSEKeyFormat->run(), 'description' => $legacySSEKeyFormat->description(), 'severity' => $legacySSEKeyFormat->severity(), 'linkToDocumentation' => $legacySSEKeyFormat->linkToDocumentation()],
- CheckUserCertificates::class => ['pass' => $checkUserCertificates->run(), 'description' => $checkUserCertificates->description(), 'severity' => $checkUserCertificates->severity(), 'elements' => $checkUserCertificates->elements()],
- 'isDefaultPhoneRegionSet' => $this->config->getSystemValueString('default_phone_region', '') !== '',
- SupportedDatabase::class => ['pass' => $supportedDatabases->run(), 'description' => $supportedDatabases->description(), 'severity' => $supportedDatabases->severity()],
'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(),
- LdapInvalidUuids::class => ['pass' => $ldapInvalidUuids->run(), 'description' => $ldapInvalidUuids->description(), 'severity' => $ldapInvalidUuids->severity()],
- NeedsSystemAddressBookSync::class => ['pass' => $needsSystemAddressBookSync->run(), 'description' => $needsSystemAddressBookSync->description(), 'severity' => $needsSystemAddressBookSync->severity()],
+ 'generic' => $this->setupCheckManager->runAll(),
]
);
}
diff --git a/apps/settings/lib/SetupChecks/CheckUserCertificates.php b/apps/settings/lib/SetupChecks/CheckUserCertificates.php
index 52fea7b6551..e09ef267e07 100644
--- a/apps/settings/lib/SetupChecks/CheckUserCertificates.php
+++ b/apps/settings/lib/SetupChecks/CheckUserCertificates.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
+ * @copyright Copyright (c) 2022 Carl Schwan <carl@carlschwan.eu>
*
* @author Morris Jobke <hey@morrisjobke.de>
*
@@ -27,50 +28,35 @@ namespace OCA\Settings\SetupChecks;
use OCP\IConfig;
use OCP\IL10N;
-use OCP\IURLGenerator;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
-class CheckUserCertificates {
- /** @var IL10N */
- private $l10n;
- /** @var string */
- private $configValue;
- /** @var IURLGenerator */
- private $urlGenerator;
+class CheckUserCertificates implements ISetupCheck {
+ private string $configValue;
- public function __construct(IL10N $l10n, IConfig $config, IURLGenerator $urlGenerator) {
- $this->l10n = $l10n;
- $configValue = $config->getAppValue('files_external', 'user_certificate_scan', '');
- $this->configValue = $configValue;
- $this->urlGenerator = $urlGenerator;
+ public function __construct(
+ private IL10N $l10n,
+ IConfig $config,
+ ) {
+ $this->configValue = $config->getAppValue('files_external', 'user_certificate_scan', '');
}
- public function description(): string {
- if ($this->configValue === '') {
- return '';
- }
- if ($this->configValue === 'not-run-yet') {
- return $this->l10n->t('A background job is pending that checks for user imported SSL certificates. Please check back later.');
- }
- return $this->l10n->t('There are some user imported SSL certificates present, that are not used anymore with Nextcloud 21. They can be imported on the command line via "occ security:certificates:import" command. Their paths inside the data directory are shown below.');
+ public function getCategory(): string {
+ return 'security';
}
- public function severity(): string {
- return 'warning';
+ public function getName(): string {
+ return $this->l10n->t('Checking for old user imported certificate');
}
- public function run(): bool {
+ public function run(): SetupResult {
// all fine if neither "not-run-yet" nor a result
- return $this->configValue === '';
- }
-
- public function elements(): array {
- if ($this->configValue === '' || $this->configValue === 'not-run-yet') {
- return [];
+ if ($this->configValue === '') {
+ return SetupResult::success();
}
- $data = json_decode($this->configValue);
- if (!is_array($data)) {
- return [];
+ if ($this->configValue === 'not-run-yet') {
+ return SetupResult::info($this->l10n->t('A background job is pending that checks for user imported SSL certificates. Please check back later.'));
}
- return $data;
+ return SetupResult::error($this->l10n->t('There are some user imported SSL certificates present, that are not used anymore with Nextcloud 21. They can be imported on the command line via "occ security:certificates:import" command. Their paths inside the data directory are shown below.'));
}
}
diff --git a/apps/settings/lib/SetupChecks/DefaultPhoneRegionSet.php b/apps/settings/lib/SetupChecks/DefaultPhoneRegionSet.php
new file mode 100644
index 00000000000..8b11ea90fdd
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/DefaultPhoneRegionSet.php
@@ -0,0 +1,58 @@
+<?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\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class DefaultPhoneRegionSet implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ private IConfig $config,
+ ) {
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('Checking for default phone region');
+ }
+
+ public function getCategory(): string {
+ return 'config';
+ }
+
+ public function run(): SetupResult {
+ if ($this->config->getSystemValueString('default_phone_region', '') !== '') {
+ return SetupResult::success($this->config->getSystemValueString('default_phone_region', ''));
+ } else {
+ return SetupResult::info(
+ $this->l10n->t('Your installation has no default phone region set. This is required to validate phone numbers in the profile settings without a country code. To allow numbers without a country code, please add "default_phone_region" with the respective ISO 3166-1 code of the region to your config file.'),
+ 'https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements'
+ );
+ }
+ }
+}
diff --git a/apps/settings/lib/SetupChecks/InternetConnectivity.php b/apps/settings/lib/SetupChecks/InternetConnectivity.php
new file mode 100644
index 00000000000..e27c5e2e981
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/InternetConnectivity.php
@@ -0,0 +1,100 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Http\Client\IClientService;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Checks if the server can connect to the internet using HTTPS and HTTP
+ */
+class InternetConnectivity implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ private IConfig $config,
+ private IClientService $clientService,
+ private LoggerInterface $logger,
+ ) {
+ }
+
+ public function getCategory(): string {
+ return 'network';
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('Internet connectivity');
+ }
+
+ public function run(): SetupResult {
+ if ($this->config->getSystemValue('has_internet_connection', true) === false) {
+ return SetupResult::success($this->l10n->t('Internet connectivity is disabled in configuration file.'));
+ }
+
+ $siteArray = $this->config->getSystemValue('connectivity_check_domains', [
+ 'www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'
+ ]);
+
+ foreach ($siteArray as $site) {
+ if ($this->isSiteReachable($site)) {
+ return SetupResult::success();
+ }
+ }
+ return SetupResult::warning($this->l10n->t('This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.'));
+ }
+
+ /**
+ * Checks if the Nextcloud server can connect to a specific URL
+ * @param string $site site domain or full URL with http/https protocol
+ */
+ private function isSiteReachable(string $site): bool {
+ try {
+ $client = $this->clientService->newClient();
+ // if there is no protocol, test http:// AND https://
+ if (preg_match('/^https?:\/\//', $site) !== 1) {
+ $httpSite = 'http://' . $site . '/';
+ $client->get($httpSite);
+ $httpsSite = 'https://' . $site . '/';
+ $client->get($httpsSite);
+ } else {
+ $client->get($site);
+ }
+ } catch (\Exception $e) {
+ $this->logger->error('Cannot connect to: ' . $site, [
+ 'app' => 'internet_connection_check',
+ 'exception' => $e,
+ ]);
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/apps/settings/lib/SetupChecks/LdapInvalidUuids.php b/apps/settings/lib/SetupChecks/LdapInvalidUuids.php
deleted file mode 100644
index 11b0105cada..00000000000
--- a/apps/settings/lib/SetupChecks/LdapInvalidUuids.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2022 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @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 <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Settings\SetupChecks;
-
-use OCA\User_LDAP\Mapping\GroupMapping;
-use OCA\User_LDAP\Mapping\UserMapping;
-use OCP\App\IAppManager;
-use OCP\IL10N;
-use OCP\IServerContainer;
-
-class LdapInvalidUuids {
-
- /** @var IAppManager */
- private $appManager;
- /** @var IL10N */
- private $l10n;
- /** @var IServerContainer */
- private $server;
-
- public function __construct(IAppManager $appManager, IL10N $l10n, IServerContainer $server) {
- $this->appManager = $appManager;
- $this->l10n = $l10n;
- $this->server = $server;
- }
-
- public function description(): string {
- return $this->l10n->t('Invalid UUIDs of LDAP users or groups have been found. Please review your "Override UUID detection" settings in the Expert part of the LDAP configuration and use "occ ldap:update-uuid" to update them.');
- }
-
- public function severity(): string {
- return 'warning';
- }
-
- public function run(): bool {
- if (!$this->appManager->isEnabledForUser('user_ldap')) {
- return true;
- }
- /** @var UserMapping $userMapping */
- $userMapping = $this->server->get(UserMapping::class);
- /** @var GroupMapping $groupMapping */
- $groupMapping = $this->server->get(GroupMapping::class);
- return count($userMapping->getList(0, 1, true)) === 0
- && count($groupMapping->getList(0, 1, true)) === 0;
- }
-}
diff --git a/apps/settings/lib/SetupChecks/LegacySSEKeyFormat.php b/apps/settings/lib/SetupChecks/LegacySSEKeyFormat.php
index 4814d3fba7c..72300ede2b0 100644
--- a/apps/settings/lib/SetupChecks/LegacySSEKeyFormat.php
+++ b/apps/settings/lib/SetupChecks/LegacySSEKeyFormat.php
@@ -28,34 +28,29 @@ namespace OCA\Settings\SetupChecks;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
-
-class LegacySSEKeyFormat {
- /** @var IL10N */
- private $l10n;
- /** @var IConfig */
- private $config;
- /** @var IURLGenerator */
- private $urlGenerator;
-
- public function __construct(IL10N $l10n, IConfig $config, IURLGenerator $urlGenerator) {
- $this->l10n = $l10n;
- $this->config = $config;
- $this->urlGenerator = $urlGenerator;
- }
-
- public function description(): string {
- return $this->l10n->t('The old server-side-encryption format is enabled. We recommend disabling this.');
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class LegacySSEKeyFormat implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ private IConfig $config,
+ private IURLGenerator $urlGenerator,
+ ) {
}
- public function severity(): string {
- return 'warning';
+ public function getCategory(): string {
+ return 'security';
}
- public function run(): bool {
- return $this->config->getSystemValueBool('encryption.legacy_format_support', false) === false;
+ public function getName(): string {
+ return $this->l10n->t('Checking for old server-side-encryption being disabled');
}
- public function linkToDocumentation(): string {
- return $this->urlGenerator->linkToDocs('admin-sse-legacy-format');
+ public function run(): SetupResult {
+ if ($this->config->getSystemValueBool('encryption.legacy_format_support', false) === false) {
+ return SetupResult::success();
+ }
+ return SetupResult::warning($this->l10n->t('The old server-side-encryption format is enabled. We recommend disabling this.'), $this->urlGenerator->linkToDocs('admin-sse-legacy-format'));
}
}
diff --git a/apps/settings/lib/SetupChecks/NeedsSystemAddressBookSync.php b/apps/settings/lib/SetupChecks/NeedsSystemAddressBookSync.php
deleted file mode 100644
index 3172abe70f7..00000000000
--- a/apps/settings/lib/SetupChecks/NeedsSystemAddressBookSync.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2023 Anna Larch <anna.larch@gmx.net>
- *
- * @author Anna Larch <anna.larch@gmx.net>
- *
- * @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 <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Settings\SetupChecks;
-
-use OCP\IConfig;
-use OCP\IL10N;
-
-class NeedsSystemAddressBookSync {
- public function __construct(private IConfig $config, private IL10N $l10n) {}
-
- public function description(): string {
- return $this->l10n->t('The DAV system address book sync has not run yet as your instance has more than 1000 users or because an error occurred. Please run it manually by calling "occ dav:sync-system-addressbook".');
- }
-
- public function severity(): string {
- return 'warning';
- }
-
- public function run(): bool {
- return $this->config->getAppValue('dav', 'needs_system_address_book_sync', 'no') === 'no';
- }
-}
diff --git a/apps/settings/lib/SetupChecks/PhpDefaultCharset.php b/apps/settings/lib/SetupChecks/PhpDefaultCharset.php
index 0ad5e2f56ea..3f7a8c58e52 100644
--- a/apps/settings/lib/SetupChecks/PhpDefaultCharset.php
+++ b/apps/settings/lib/SetupChecks/PhpDefaultCharset.php
@@ -25,16 +25,29 @@ declare(strict_types=1);
*/
namespace OCA\Settings\SetupChecks;
-class PhpDefaultCharset {
- public function description(): string {
- return 'PHP configuration option default_charset should be UTF-8';
+use OCP\IL10N;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class PhpDefaultCharset implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ ) {
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('Checking for PHP default charset');
}
- public function severity(): string {
- return 'warning';
+ public function getCategory(): string {
+ return 'php';
}
- public function run(): bool {
- return strtoupper(trim(ini_get('default_charset'))) === 'UTF-8';
+ public function run(): SetupResult {
+ if (strtoupper(trim(ini_get('default_charset'))) === 'UTF-8') {
+ return SetupResult::success();
+ } else {
+ return SetupResult::warning($this->l10n->t('PHP configuration option default_charset should be UTF-8'));
+ }
}
}
diff --git a/apps/settings/lib/SetupChecks/PhpOutdated.php b/apps/settings/lib/SetupChecks/PhpOutdated.php
new file mode 100644
index 00000000000..2d161649315
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/PhpOutdated.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @author Carl Schwan <carl@carlschwan.eu>
+ * @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\IL10N;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class PhpOutdated implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ ) {
+ }
+
+ public function getCategory(): string {
+ return 'security';
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('Checking for PHP version');
+ }
+
+ public function run(): SetupResult {
+ if (PHP_VERSION_ID < 80100) {
+ return SetupResult::warning($this->l10n->t('You are currently running PHP %s. PHP 8.0 is now deprecated in Nextcloud 27. Nextcloud 28 may require at least PHP 8.1. Please upgrade to one of the officially supported PHP versions provided by the PHP Group as soon as possible.', [PHP_VERSION]), 'https://secure.php.net/supported-versions.php');
+ }
+ return SetupResult::success($this->l10n->t('You are currently running PHP %s.', [PHP_VERSION]));
+ }
+}
diff --git a/apps/settings/lib/SetupChecks/PhpOutputBuffering.php b/apps/settings/lib/SetupChecks/PhpOutputBuffering.php
index 3bf52695301..58321e9f5dc 100644
--- a/apps/settings/lib/SetupChecks/PhpOutputBuffering.php
+++ b/apps/settings/lib/SetupChecks/PhpOutputBuffering.php
@@ -25,17 +25,30 @@ declare(strict_types=1);
*/
namespace OCA\Settings\SetupChecks;
-class PhpOutputBuffering {
- public function description(): string {
- return 'PHP configuration option output_buffering must be disabled';
+use OCP\IL10N;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class PhpOutputBuffering implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ ) {
+ }
+
+ public function getCategory(): string {
+ return 'php';
}
- public function severity(): string {
- return 'error';
+ public function getName(): string {
+ return $this->l10n->t('Checking for PHP output_buffering option');
}
- public function run(): bool {
+ public function run(): SetupResult {
$value = trim(ini_get('output_buffering'));
- return $value === '' || $value === '0';
+ if ($value === '' || $value === '0') {
+ return SetupResult::success();
+ } else {
+ return SetupResult::error($this->l10n->t('PHP configuration option output_buffering must be disabled'));
+ }
}
}
diff --git a/apps/settings/lib/SetupChecks/ReadOnlyConfig.php b/apps/settings/lib/SetupChecks/ReadOnlyConfig.php
new file mode 100644
index 00000000000..56f86ba9ab4
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/ReadOnlyConfig.php
@@ -0,0 +1,55 @@
+<?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\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class ReadOnlyConfig implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ private IConfig $config,
+ ) {
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('Checking for configuration file access rights');
+ }
+
+ public function getCategory(): string {
+ return 'config';
+ }
+
+ public function run(): SetupResult {
+ if ($this->config->getSystemValueBool('config_is_read_only', false)) {
+ return SetupResult::info($this->l10n->t('The read-only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.'));
+ } else {
+ return SetupResult::success($this->l10n->t('Nextcloud configuration file is writable'));
+ }
+ }
+}
diff --git a/apps/settings/lib/SetupChecks/SupportedDatabase.php b/apps/settings/lib/SetupChecks/SupportedDatabase.php
index c925ad48043..3d10798a7da 100644
--- a/apps/settings/lib/SetupChecks/SupportedDatabase.php
+++ b/apps/settings/lib/SetupChecks/SupportedDatabase.php
@@ -37,27 +37,25 @@ use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use OCP\IDBConnection;
use OCP\IL10N;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
-class SupportedDatabase {
- /** @var IL10N */
- private $l10n;
- /** @var IDBConnection */
- private $connection;
-
- private $checked = false;
- private $description = '';
+class SupportedDatabase implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ private IDBConnection $connection,
+ ) {
+ }
- public function __construct(IL10N $l10n, IDBConnection $connection) {
- $this->l10n = $l10n;
- $this->connection = $connection;
+ public function getCategory(): string {
+ return 'database';
}
- public function check() {
- if ($this->checked === true) {
- return;
- }
- $this->checked = true;
+ public function getName(): string {
+ return $this->l10n->t('Checking for database version');
+ }
+ public function run(): SetupResult {
switch (get_class($this->connection->getDatabasePlatform())) {
case MySQL80Platform::class: # extends MySQL57Platform
case MySQL57Platform::class: # extends MySQLPlatform
@@ -70,13 +68,11 @@ class SupportedDatabase {
if (str_contains($version, 'mariadb')) {
if (version_compare($version, '10.2', '<')) {
- $this->description = $this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 and higher do not support this version and require MariaDB 10.2 or higher.', $row['Value']);
- return;
+ return SetupResult::warning($this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 and higher do not support this version and require MariaDB 10.2 or higher.', $row['Value']));
}
} else {
if (version_compare($version, '8', '<')) {
- $this->description = $this->l10n->t('MySQL version "%s" is used. Nextcloud 21 and higher do not support this version and require MySQL 8.0 or MariaDB 10.2 or higher.', $row['Value']);
- return;
+ return SetupResult::warning($this->l10n->t('MySQL version "%s" is used. Nextcloud 21 and higher do not support this version and require MySQL 8.0 or MariaDB 10.2 or higher.', $row['Value']));
}
}
break;
@@ -88,26 +84,13 @@ class SupportedDatabase {
$result->execute();
$row = $result->fetch();
if (version_compare($row['server_version'], '9.6', '<')) {
- $this->description = $this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 and higher do not support this version and require PostgreSQL 9.6 or higher.', $row['server_version']);
- return;
+ return SetupResult::warning($this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 and higher do not support this version and require PostgreSQL 9.6 or higher.', $row['server_version']));
}
break;
case OraclePlatform::class:
break;
}
- }
-
- public function description(): string {
- $this->check();
- return $this->description;
- }
-
- public function severity(): string {
- return 'info';
- }
-
- public function run(): bool {
- $this->check();
- return $this->description === '';
+ // TODO still show db and version on success?
+ return SetupResult::success();
}
}
diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php
index 1168f04fbd4..449f181e8c1 100644
--- a/apps/settings/tests/Controller/CheckSetupControllerTest.php
+++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php
@@ -60,6 +60,7 @@ use OCP\IURLGenerator;
use OCP\Lock\ILockingProvider;
use OCP\Notification\IManager;
use OCP\Security\Bruteforce\IThrottler;
+use OCP\SetupCheck\ISetupCheckManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
@@ -113,6 +114,8 @@ class CheckSetupControllerTest extends TestCase {
private $appManager;
/** @var IServerContainer|MockObject */
private $serverContainer;
+ /** @var ISetupCheckManager|MockObject */
+ private $setupCheckManager;
/**
* Holds a list of directories created during tests.
@@ -159,6 +162,7 @@ class CheckSetupControllerTest extends TestCase {
$this->notificationManager = $this->getMockBuilder(IManager::class)->getMock();
$this->appManager = $this->createMock(IAppManager::class);
$this->serverContainer = $this->createMock(IServerContainer::class);
+ $this->setupCheckManager = $this->createMock(ISetupCheckManager::class);
$this->checkSetupController = $this->getMockBuilder(CheckSetupController::class)
->setConstructorArgs([
'settings',
@@ -182,6 +186,7 @@ class CheckSetupControllerTest extends TestCase {
$this->notificationManager,
$this->appManager,
$this->serverContainer,
+ $this->setupCheckManager,
])
->setMethods([
'isReadOnlyConfig',
@@ -224,73 +229,6 @@ class CheckSetupControllerTest extends TestCase {
$this->dirsToRemove = [];
}
- public function testIsInternetConnectionWorkingDisabledViaConfig() {
- $this->config->expects($this->once())
- ->method('getSystemValue')
- ->with('has_internet_connection', true)
- ->willReturn(false);
-
- $this->assertFalse(
- self::invokePrivate(
- $this->checkSetupController,
- 'hasInternetConnectivityProblems'
- )
- );
- }
-
- public function testIsInternetConnectionWorkingCorrectly() {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->withConsecutive(
- ['has_internet_connection', true],
- ['connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']],
- )->willReturnArgument(1);
-
- $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
- ->disableOriginalConstructor()->getMock();
- $client->expects($this->any())
- ->method('get');
-
- $this->clientService->expects($this->once())
- ->method('newClient')
- ->willReturn($client);
-
-
- $this->assertFalse(
- self::invokePrivate(
- $this->checkSetupController,
- 'hasInternetConnectivityProblems'
- )
- );
- }
-
- public function testIsInternetConnectionFail() {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->withConsecutive(
- ['has_internet_connection', true],
- ['connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']],
- )->willReturnArgument(1);
-
- $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
- ->disableOriginalConstructor()->getMock();
- $client->expects($this->any())
- ->method('get')
- ->will($this->throwException(new \Exception()));
-
- $this->clientService->expects($this->exactly(4))
- ->method('newClient')
- ->willReturn($client);
-
- $this->assertTrue(
- self::invokePrivate(
- $this->checkSetupController,
- 'hasInternetConnectivityProblems'
- )
- );
- }
-
-
public function testIsMemcacheConfiguredFalse() {
$this->config->expects($this->once())
->method('getSystemValue')
@@ -319,36 +257,6 @@ class CheckSetupControllerTest extends TestCase {
);
}
- public function testIsPhpSupportedFalse() {
- $this->checkSetupController
- ->expects($this->once())
- ->method('isPhpOutdated')
- ->willReturn(true);
-
- $this->assertEquals(
- ['eol' => true, 'version' => PHP_VERSION],
- self::invokePrivate($this->checkSetupController, 'isPhpSupported')
- );
- }
-
- public function testIsPhpSupportedTrue() {
- $this->checkSetupController
- ->expects($this->exactly(2))
- ->method('isPhpOutdated')
- ->willReturn(false);
-
- $this->assertEquals(
- ['eol' => false, 'version' => PHP_VERSION],
- self::invokePrivate($this->checkSetupController, 'isPhpSupported')
- );
-
-
- $this->assertEquals(
- ['eol' => false, 'version' => PHP_VERSION],
- self::invokePrivate($this->checkSetupController, 'isPhpSupported')
- );
- }
-
/**
* @dataProvider dataForwardedForHeadersWorking
*
@@ -454,23 +362,8 @@ class CheckSetupControllerTest extends TestCase {
['X-Forwarded-Host', '']
]);
- $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
- ->disableOriginalConstructor()->getMock();
- $client->expects($this->exactly(4))
- ->method('get')
- ->withConsecutive(
- ['http://www.nextcloud.com/', []],
- ['http://www.startpage.com/', []],
- ['http://www.eff.org/', []],
- ['http://www.edri.org/', []]
- )->will($this->throwException(new \Exception()));
- $this->clientService->expects($this->exactly(4))
- ->method('newClient')
- ->willReturn($client);
- $this->checkSetupController
- ->expects($this->once())
- ->method('isPhpOutdated')
- ->willReturn(true);
+ $this->clientService->expects($this->never())
+ ->method('newClient');
$this->checkSetupController
->expects($this->once())
->method('getOpcacheSetupRecommendations')
@@ -621,16 +514,11 @@ class CheckSetupControllerTest extends TestCase {
'backgroundJobsUrl' => 'https://example.org',
],
'cronErrors' => [],
- 'serverHasInternetConnectionProblems' => true,
'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' => '',
- 'phpSupported' => [
- 'eol' => true,
- 'version' => PHP_VERSION
- ],
'forwardedForHeadersWorking' => false,
'reverseProxyDocs' => 'reverse-proxy-doc-link',
'isCorrectMemcachedPHPModuleInstalled' => true,
@@ -654,19 +542,12 @@ class CheckSetupControllerTest extends TestCase {
'isMysqlUsedWithoutUTF8MB4' => false,
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true,
'reverseProxyGeneratedURL' => 'https://server/index.php',
- 'OCA\Settings\SetupChecks\PhpDefaultCharset' => ['pass' => true, 'description' => 'PHP configuration option default_charset should be UTF-8', 'severity' => 'warning'],
- 'OCA\Settings\SetupChecks\PhpOutputBuffering' => ['pass' => true, 'description' => 'PHP configuration option output_buffering must be disabled', 'severity' => 'error'],
- 'OCA\Settings\SetupChecks\LegacySSEKeyFormat' => ['pass' => true, 'description' => 'The old server-side-encryption format is enabled. We recommend disabling this.', 'severity' => 'warning', 'linkToDocumentation' => ''],
- 'OCA\Settings\SetupChecks\CheckUserCertificates' => ['pass' => false, 'description' => 'There are some user imported SSL certificates present, that are not used anymore with Nextcloud 21. They can be imported on the command line via "occ security:certificates:import" command. Their paths inside the data directory are shown below.', 'severity' => 'warning', 'elements' => ['a', 'b']],
'imageMagickLacksSVGSupport' => false,
- 'isDefaultPhoneRegionSet' => false,
- 'OCA\Settings\SetupChecks\SupportedDatabase' => ['pass' => true, 'description' => '', 'severity' => 'info'],
'isFairUseOfFreePushService' => false,
'temporaryDirectoryWritable' => false,
- \OCA\Settings\SetupChecks\LdapInvalidUuids::class => ['pass' => true, 'description' => 'Invalid UUIDs of LDAP users or groups have been found. Please review your "Override UUID detection" settings in the Expert part of the LDAP configuration and use "occ ldap:update-uuid" to update them.', 'severity' => 'warning'],
- \OCA\Settings\SetupChecks\NeedsSystemAddressBookSync::class => ['pass' => true, 'description' => 'The DAV system address book sync has not run yet as your instance has more than 1000 users or because an error occurred. Please run it manually by calling "occ dav:sync-system-addressbook".', 'severity' => 'warning'],
'isBruteforceThrottled' => false,
'bruteforceRemoteAddress' => '',
+ 'generic' => [],
]
);
$this->assertEquals($expected, $this->checkSetupController->check());
@@ -695,7 +576,8 @@ class CheckSetupControllerTest extends TestCase {
$this->tempManager,
$this->notificationManager,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->setupCheckManager,
])
->setMethods(null)->getMock();
@@ -1423,7 +1305,8 @@ Array
$this->tempManager,
$this->notificationManager,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->setupCheckManager,
);
$this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isMysqlUsedWithoutUTF8MB4'));
@@ -1478,7 +1361,8 @@ Array
$this->tempManager,
$this->notificationManager,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->setupCheckManager,
);
$this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed'));
diff --git a/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php b/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php
index eac671a0e13..8e52a85c538 100644
--- a/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php
+++ b/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php
@@ -26,19 +26,37 @@ declare(strict_types=1);
namespace OCA\Settings\Tests;
use OCA\Settings\SetupChecks\PhpDefaultCharset;
+use OCP\IL10N;
+use OCP\SetupCheck\SetupResult;
use Test\TestCase;
+use PHPUnit\Framework\MockObject\MockObject;
class PhpDefaultCharsetTest extends TestCase {
+ /** @var IL10N|MockObject */
+ private $l10n;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->getMockBuilder(IL10N::class)
+ ->disableOriginalConstructor()->getMock();
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ }
+
public function testPass(): void {
- $check = new PhpDefaultCharset();
- $this->assertTrue($check->run());
+ $check = new PhpDefaultCharset($this->l10n);
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
}
public function testFail(): void {
ini_set('default_charset', 'ISO-8859-15');
- $check = new PhpDefaultCharset();
- $this->assertFalse($check->run());
+ $check = new PhpDefaultCharset($this->l10n);
+ $this->assertEquals(SetupResult::WARNING, $check->run()->getSeverity());
ini_restore('default_charset');
}
diff --git a/apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php b/apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php
index 9e0301dcc12..a835708243d 100644
--- a/apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php
+++ b/apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php
@@ -26,16 +26,34 @@ declare(strict_types=1);
namespace OCA\Settings\Tests;
use OCA\Settings\SetupChecks\PhpOutputBuffering;
+use OCP\IL10N;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class PhpOutputBufferingTest extends TestCase {
+ /** @var IL10N|MockObject */
+ private $l10n;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->getMockBuilder(IL10N::class)
+ ->disableOriginalConstructor()->getMock();
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ }
+
/*
* output_buffer is PHP_INI_PERDIR and cannot changed at runtime.
* Run this test with -d output_buffering=1 to validate the fail case.
*/
public function testPass(): void {
- $check = new PhpOutputBuffering();
- $this->assertTrue($check->run());
+ $check = new PhpOutputBuffering($this->l10n);
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
}
}
diff --git a/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php b/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php
index 35c27769e78..5521bec34b5 100644
--- a/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php
+++ b/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php
@@ -27,6 +27,7 @@ namespace OCA\Settings\Tests;
use OCA\Settings\SetupChecks\SupportedDatabase;
use OCP\IL10N;
+use OCP\SetupCheck\SetupResult;
use Test\TestCase;
/**
@@ -36,6 +37,6 @@ class SupportedDatabaseTest extends TestCase {
public function testPass(): void {
$l10n = $this->getMockBuilder(IL10N::class)->getMock();
$check = new SupportedDatabase($l10n, \OC::$server->getDatabaseConnection());
- $this->assertTrue($check->run());
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
}
}