]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat: Make `CheckServerResponseTrait` public and provide as `OCP\SetupCheck\CheckServ... feat/make-setup-check-trait-public 47947/head
authorFerdinand Thiessen <opensource@fthiessen.de>
Fri, 13 Sep 2024 12:18:25 +0000 (14:18 +0200)
committerJoas Schilling <coding@schilljs.com>
Mon, 16 Sep 2024 12:58:21 +0000 (14:58 +0200)
This trait is used by other apps for creating setup checks,
so we should provide it instead apps using private API.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
18 files changed:
apps/dav/lib/SetupChecks/WebdavEndpoint.php
apps/settings/composer/composer/autoload_classmap.php
apps/settings/composer/composer/autoload_static.php
apps/settings/lib/SetupChecks/CheckServerResponseTrait.php [deleted file]
apps/settings/lib/SetupChecks/DataDirectoryProtected.php
apps/settings/lib/SetupChecks/JavaScriptModules.php
apps/settings/lib/SetupChecks/JavaScriptSourceMaps.php
apps/settings/lib/SetupChecks/OcxProviders.php
apps/settings/lib/SetupChecks/SecurityHeaders.php
apps/settings/lib/SetupChecks/WellKnownUrls.php
apps/settings/lib/SetupChecks/Woff2Loading.php
apps/settings/tests/SetupChecks/CheckServerResponseTraitImplementation.php [deleted file]
apps/settings/tests/SetupChecks/CheckServerResponseTraitTest.php [deleted file]
lib/composer/composer/autoload_classmap.php
lib/composer/composer/autoload_static.php
lib/public/SetupCheck/CheckServerResponseTrait.php [new file with mode: 0644]
tests/lib/SetupCheck/CheckServerResponseTraitImplementation.php [new file with mode: 0644]
tests/lib/SetupCheck/CheckServerResponseTraitTest.php [new file with mode: 0644]

index f5a387836fb773b060d2640b2fbbd013c3d786f3..c2574202fcd026ba5e7ea676fb2837a61264c533 100644 (file)
@@ -9,11 +9,11 @@ declare(strict_types=1);
 
 namespace OCA\DAV\SetupChecks;
 
-use OCA\Settings\SetupChecks\CheckServerResponseTrait;
 use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\SetupCheck\CheckServerResponseTrait;
 use OCP\SetupCheck\ISetupCheck;
 use OCP\SetupCheck\SetupResult;
 use Psr\Log\LoggerInterface;
index 7a3618ecb51342dd9894e222d21d2c442d0eb307..1b3c4c25552af14b7ba55fc7c0f17da1c235ba68 100644 (file)
@@ -82,7 +82,6 @@ return array(
     'OCA\\Settings\\SetupChecks\\AllowedAdminRanges' => $baseDir . '/../lib/SetupChecks/AllowedAdminRanges.php',
     'OCA\\Settings\\SetupChecks\\AppDirsWithDifferentOwner' => $baseDir . '/../lib/SetupChecks/AppDirsWithDifferentOwner.php',
     'OCA\\Settings\\SetupChecks\\BruteForceThrottler' => $baseDir . '/../lib/SetupChecks/BruteForceThrottler.php',
-    'OCA\\Settings\\SetupChecks\\CheckServerResponseTrait' => $baseDir . '/../lib/SetupChecks/CheckServerResponseTrait.php',
     'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => $baseDir . '/../lib/SetupChecks/CheckUserCertificates.php',
     'OCA\\Settings\\SetupChecks\\CodeIntegrity' => $baseDir . '/../lib/SetupChecks/CodeIntegrity.php',
     'OCA\\Settings\\SetupChecks\\CronErrors' => $baseDir . '/../lib/SetupChecks/CronErrors.php',
index 18882ed9fc233cd13bd5a13a5a46d02b59a0a52e..5de0bb31fd6b4d9d35a309951017fcf195af7a6d 100644 (file)
@@ -97,7 +97,6 @@ class ComposerStaticInitSettings
         'OCA\\Settings\\SetupChecks\\AllowedAdminRanges' => __DIR__ . '/..' . '/../lib/SetupChecks/AllowedAdminRanges.php',
         'OCA\\Settings\\SetupChecks\\AppDirsWithDifferentOwner' => __DIR__ . '/..' . '/../lib/SetupChecks/AppDirsWithDifferentOwner.php',
         'OCA\\Settings\\SetupChecks\\BruteForceThrottler' => __DIR__ . '/..' . '/../lib/SetupChecks/BruteForceThrottler.php',
-        'OCA\\Settings\\SetupChecks\\CheckServerResponseTrait' => __DIR__ . '/..' . '/../lib/SetupChecks/CheckServerResponseTrait.php',
         'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => __DIR__ . '/..' . '/../lib/SetupChecks/CheckUserCertificates.php',
         'OCA\\Settings\\SetupChecks\\CodeIntegrity' => __DIR__ . '/..' . '/../lib/SetupChecks/CodeIntegrity.php',
         'OCA\\Settings\\SetupChecks\\CronErrors' => __DIR__ . '/..' . '/../lib/SetupChecks/CronErrors.php',
diff --git a/apps/settings/lib/SetupChecks/CheckServerResponseTrait.php b/apps/settings/lib/SetupChecks/CheckServerResponseTrait.php
deleted file mode 100644 (file)
index 3080829..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-namespace OCA\Settings\SetupChecks;
-
-use Generator;
-use OCP\Http\Client\IClientService;
-use OCP\Http\Client\IResponse;
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IURLGenerator;
-use Psr\Log\LoggerInterface;
-
-/**
- * Common trait for setup checks that need to use requests to the same server and check the response
- */
-trait CheckServerResponseTrait {
-       protected IConfig $config;
-       protected IURLGenerator $urlGenerator;
-       protected IClientService $clientService;
-       protected IL10N $l10n;
-       protected LoggerInterface $logger;
-
-       /**
-        * Common helper string in case a check could not fetch any results
-        */
-       protected function serverConfigHelp(): string {
-               return $this->l10n->t('To allow this check to run you have to make sure that your Web server can connect to itself. Therefore it must be able to resolve and connect to at least one of its `trusted_domains` or the `overwrite.cli.url`. This failure may be the result of a server-side DNS mismatch or outbound firewall rule.');
-       }
-
-       /**
-        * Get all possible URLs that need to be checked for a local request test.
-        * This takes all `trusted_domains` and the CLI overwrite URL into account.
-        *
-        * @param string $url The absolute path (absolute URL without host but with web-root) to test starting with a /
-        * @param bool $isRootRequest Set to remove the web-root from URL and host (e.g. when requesting a path in the domain root like '/.well-known')
-        * @return list<string> List of possible absolute URLs
-        */
-       protected function getTestUrls(string $url, bool $isRootRequest = false): array {
-               $url = '/' . ltrim($url, '/');
-
-               $webroot = rtrim($this->urlGenerator->getWebroot(), '/');
-               if ($isRootRequest === false && $webroot !== '' && str_starts_with($url, $webroot)) {
-                       // The URL contains the web-root but also the base url does so,
-                       // so we need to remove the web-root from the URL.
-                       $url = substr($url, strlen($webroot));
-               }
-
-               // Base URLs to test
-               $baseUrls = [];
-
-               // Try overwrite.cli.url first, it’s supposed to be how the server contacts itself
-               $cliUrl = $this->config->getSystemValueString('overwrite.cli.url', '');
-               if ($cliUrl !== '') {
-                       // The CLI URL already contains the web-root, so we need to normalize it if requested
-                       $baseUrls[] = $this->normalizeUrl(
-                               $cliUrl,
-                               $isRootRequest
-                       );
-               }
-
-               // Try URL generator second
-               // The base URL also contains the webroot so also normalize it
-               $baseUrls[] = $this->normalizeUrl(
-                       $this->urlGenerator->getBaseUrl(),
-                       $isRootRequest
-               );
-
-               /* Last resort: trusted domains */
-               $trustedDomains = $this->config->getSystemValue('trusted_domains', []);
-               foreach ($trustedDomains as $host) {
-                       if (str_contains($host, '*')) {
-                               /* Ignore domains with a wildcard */
-                               continue;
-                       }
-                       $baseUrls[] = $this->normalizeUrl("https://$host$webroot", $isRootRequest);
-                       $baseUrls[] = $this->normalizeUrl("http://$host$webroot", $isRootRequest);
-               }
-
-               return array_map(fn (string $host) => $host . $url, array_values(array_unique($baseUrls)));
-       }
-
-       /**
-        * Strip a trailing slash and remove the webroot if requested.
-        * @param string $url The URL to normalize. Should be an absolute URL containing scheme, host and optionally web-root.
-        * @param bool $removeWebroot If set the web-root is removed from the URL and an absolute URL with only the scheme and host (optional port) is returned
-        */
-       protected function normalizeUrl(string $url, bool $removeWebroot): string {
-               if ($removeWebroot) {
-                       $segments = parse_url($url);
-                       $port = isset($segments['port']) ? (':' . $segments['port']) : '';
-                       return $segments['scheme'] . '://' . $segments['host'] . $port;
-               }
-               return rtrim($url, '/');
-       }
-
-       /**
-        * Run a HTTP request to check header
-        * @param string $method The HTTP method to use
-        * @param string $url The absolute path (URL with webroot but without host) to check, can be the output of `IURLGenerator`
-        * @param bool $isRootRequest If set the webroot is removed from URLs to make the request target the host's root. Example usage are the /.well-known URLs in the root path.
-        * @param array{ignoreSSL?: bool, httpErrors?: bool, options?: array} $options HTTP client related options, like
-        *                                                                             [
-        *                                                                             // Ignore invalid SSL certificates (e.g. self signed)
-        *                                                                             'ignoreSSL' => true,
-        *                                                                             // Ignore requests with HTTP errors (will not yield if request has a 4xx or 5xx response)
-        *                                                                             'httpErrors' => true,
-        *                                                                             // Additional options for the HTTP client (see `IClient`)
-        *                                                                             'options' => [],
-        *                                                                             ]
-        *
-        * @return Generator<int, IResponse>
-        */
-       protected function runRequest(string $method, string $url, array $options = [], bool $isRootRequest = false): Generator {
-               $options = array_merge(['ignoreSSL' => true, 'httpErrors' => true], $options);
-
-               $client = $this->clientService->newClient();
-               $requestOptions = $this->getRequestOptions($options['ignoreSSL'], $options['httpErrors']);
-               $requestOptions = array_merge($requestOptions, $options['options'] ?? []);
-
-               foreach ($this->getTestUrls($url, $isRootRequest) as $testURL) {
-                       try {
-                               yield $client->request($method, $testURL, $requestOptions);
-                       } catch (\Throwable $e) {
-                               $this->logger->debug('Can not connect to local server for running setup checks', ['exception' => $e, 'url' => $testURL]);
-                       }
-               }
-       }
-
-       /**
-        * Run a HEAD request to check header
-        * @param string $url The relative URL to check (e.g. output of IURLGenerator)
-        * @param bool $ignoreSSL Ignore SSL certificates
-        * @param bool $httpErrors Ignore requests with HTTP errors (will not yield if request has a 4xx or 5xx response)
-        * @return Generator<int, IResponse>
-        */
-       protected function runHEAD(string $url, bool $ignoreSSL = true, bool $httpErrors = true): Generator {
-               return $this->runRequest('HEAD', $url, ['ignoreSSL' => $ignoreSSL, 'httpErrors' => $httpErrors]);
-       }
-
-       protected function getRequestOptions(bool $ignoreSSL, bool $httpErrors): array {
-               $requestOptions = [
-                       'connect_timeout' => 10,
-                       'http_errors' => $httpErrors,
-                       'nextcloud' => [
-                               'allow_local_address' => true,
-                       ],
-               ];
-               if ($ignoreSSL) {
-                       $requestOptions['verify'] = false;
-               }
-               return $requestOptions;
-       }
-}
index 051494adb6258785a7cb67f7e298cab56b2b7e51..4280457ced03ad7de38b3bf61d51982dd69ce566 100644 (file)
@@ -12,6 +12,7 @@ use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\SetupCheck\CheckServerResponseTrait;
 use OCP\SetupCheck\ISetupCheck;
 use OCP\SetupCheck\SetupResult;
 use Psr\Log\LoggerInterface;
index ae19eacec7b3f564433a5456e4a40af8b36a073d..e09dc459dc8854d1565073e7ee6a23606f308468 100644 (file)
@@ -12,6 +12,7 @@ use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\SetupCheck\CheckServerResponseTrait;
 use OCP\SetupCheck\ISetupCheck;
 use OCP\SetupCheck\SetupResult;
 use Psr\Log\LoggerInterface;
@@ -43,7 +44,7 @@ class JavaScriptModules implements ISetupCheck {
                $testFile = $this->urlGenerator->linkTo('settings', 'js/esm-test.mjs');
 
                $noResponse = true;
-               foreach ($this->runHEAD($testFile) as $response) {
+               foreach ($this->runRequest('HEAD', $testFile) as $response) {
                        $noResponse = false;
                        if (preg_match('/(text|application)\/javascript/i', $response->getHeader('Content-Type'))) {
                                return SetupResult::success();
index 85cbe8723395cb62e9f372d13ecbd8f95425b57d..dcfc40192b93ae5a5f5d51fce5cc699ecf37bab0 100644 (file)
@@ -12,6 +12,7 @@ use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\SetupCheck\CheckServerResponseTrait;
 use OCP\SetupCheck\ISetupCheck;
 use OCP\SetupCheck\SetupResult;
 use Psr\Log\LoggerInterface;
@@ -42,7 +43,7 @@ class JavaScriptSourceMaps implements ISetupCheck {
        public function run(): SetupResult {
                $testFile = $this->urlGenerator->linkTo('settings', 'js/map-test.js.map');
 
-               foreach ($this->runHEAD($testFile) as $response) {
+               foreach ($this->runRequest('HEAD', $testFile) as $response) {
                        return SetupResult::success();
                }
 
index 84da99dbfb0976bc73be7bad6160bc6a4306bd39..191341b0ee4314c16647308282c5858b820a4a6b 100644 (file)
@@ -12,6 +12,7 @@ use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\SetupCheck\CheckServerResponseTrait;
 use OCP\SetupCheck\ISetupCheck;
 use OCP\SetupCheck\SetupResult;
 use Psr\Log\LoggerInterface;
index a6dbc631b5cde05cd0a27c886e786454c7923780..b85ab9b4018042189a14db1233570b3c72bc3a88 100644 (file)
@@ -13,6 +13,7 @@ use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\SetupCheck\CheckServerResponseTrait;
 use OCP\SetupCheck\ISetupCheck;
 use OCP\SetupCheck\SetupResult;
 use Psr\Log\LoggerInterface;
@@ -71,8 +72,8 @@ class SecurityHeaders implements ISetupCheck {
                                        }
                                }
 
-                               $xssfields = array_map('trim', explode(';', $response->getHeader('X-XSS-Protection')));
-                               if (!in_array('1', $xssfields) || !in_array('mode=block', $xssfields)) {
+                               $xssFields = array_map('trim', explode(';', $response->getHeader('X-XSS-Protection')));
+                               if (!in_array('1', $xssFields) || !in_array('mode=block', $xssFields)) {
                                        $msg .= $this->l10n->t('- The `%1$s` HTTP header does not contain `%2$s`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', ['X-XSS-Protection', '1; mode=block'])."\n";
                                }
 
index 623b9fae90c6e9242c113e6d0c9d625501290ae4..9fdaca996b8675a6d34265e673c8a04e543eccf4 100644 (file)
@@ -13,6 +13,7 @@ use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\SetupCheck\CheckServerResponseTrait;
 use OCP\SetupCheck\ISetupCheck;
 use OCP\SetupCheck\SetupResult;
 use Psr\Log\LoggerInterface;
index 769653c46180dc62673eadb684efdfbd030eab3b..27aff4ea9993acbd0e121b47ca91fe2ca762aceb 100644 (file)
@@ -12,6 +12,7 @@ use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\SetupCheck\CheckServerResponseTrait;
 use OCP\SetupCheck\ISetupCheck;
 use OCP\SetupCheck\SetupResult;
 use Psr\Log\LoggerInterface;
@@ -49,7 +50,7 @@ class Woff2Loading implements ISetupCheck {
 
        protected function checkFont(string $fileExtension, string $url): SetupResult {
                $noResponse = true;
-               $responses = $this->runHEAD($url);
+               $responses = $this->runRequest('HEAD', $url);
                foreach ($responses as $response) {
                        $noResponse = false;
                        if ($response->getStatusCode() === 200) {
diff --git a/apps/settings/tests/SetupChecks/CheckServerResponseTraitImplementation.php b/apps/settings/tests/SetupChecks/CheckServerResponseTraitImplementation.php
deleted file mode 100644 (file)
index 6c8b658..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-namespace OCA\Settings\Tests\SetupChecks;
-
-use OCA\Settings\SetupChecks\CheckServerResponseTrait;
-use OCP\Http\Client\IClientService;
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IURLGenerator;
-use Psr\Log\LoggerInterface;
-
-/**
- * Dummy implementation for CheckServerResponseTraitTest
- */
-class CheckServerResponseTraitImplementation {
-
-       use CheckServerResponseTrait {
-               CheckServerResponseTrait::getRequestOptions as public;
-               CheckServerResponseTrait::runHEAD as public;
-               CheckServerResponseTrait::runRequest as public;
-               CheckServerResponseTrait::normalizeUrl as public;
-               CheckServerResponseTrait::getTestUrls as public;
-       }
-
-       public function __construct(
-               protected IL10N $l10n,
-               protected IConfig $config,
-               protected IURLGenerator $urlGenerator,
-               protected IClientService $clientService,
-               protected LoggerInterface $logger,
-       ) {
-       }
-
-}
diff --git a/apps/settings/tests/SetupChecks/CheckServerResponseTraitTest.php b/apps/settings/tests/SetupChecks/CheckServerResponseTraitTest.php
deleted file mode 100644 (file)
index e51546c..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-namespace OCA\Settings\Tests\SetupChecks;
-
-use OCP\Http\Client\IClientService;
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IURLGenerator;
-use PHPUnit\Framework\MockObject\MockObject;
-use Psr\Log\LoggerInterface;
-use Test\TestCase;
-
-class CheckServerResponseTraitTest extends TestCase {
-
-       protected const BASE_URL = 'https://nextcloud.local';
-       
-       private IL10N&MockObject $l10n;
-       private IConfig&MockObject $config;
-       private IURLGenerator&MockObject $urlGenerator;
-       private IClientService&MockObject $clientService;
-       private LoggerInterface&MockObject $logger;
-
-       private CheckServerResponseTraitImplementation $trait;
-
-       protected function setUp(): void {
-               parent::setUp();
-
-               $this->l10n = $this->createMock(IL10N::class);
-               $this->l10n->method('t')
-                       ->willReturnArgument(0);
-               $this->config = $this->createMock(IConfig::class);
-               $this->urlGenerator = $this->createMock(IURLGenerator::class);
-               $this->clientService = $this->createMock(IClientService::class);
-               $this->logger = $this->createMock(LoggerInterface::class);
-               
-               $this->trait = new CheckServerResponseTraitImplementation(
-                       $this->l10n,
-                       $this->config,
-                       $this->urlGenerator,
-                       $this->clientService,
-                       $this->logger,
-               );
-       }
-
-       /**
-        * @dataProvider dataNormalizeUrl
-        */
-       public function testNormalizeUrl(string $url, bool $isRootRequest, string $expected): void {
-               $this->assertEquals($expected, $this->trait->normalizeUrl($url, $isRootRequest));
-       }
-
-       public static function dataNormalizeUrl(): array {
-               return [
-                       // untouched web-root
-                       'valid and nothing to change' => ['http://example.com/root', false, 'http://example.com/root'],
-                       'valid with port and nothing to change' => ['http://example.com:8081/root', false, 'http://example.com:8081/root'],
-                       'trailing slash' => ['http://example.com/root/', false, 'http://example.com/root'],
-                       'deep web root' => ['http://example.com/deep/webroot', false, 'http://example.com/deep/webroot'],
-                       // removal of the web-root
-                       'remove web root' => ['http://example.com/root/', true, 'http://example.com'],
-                       'remove web root but empty' => ['http://example.com', true, 'http://example.com'],
-                       'remove deep web root' => ['http://example.com/deep/webroot', true, 'http://example.com'],
-                       'remove web root with port' => ['http://example.com:8081/root', true, 'http://example.com:8081'],
-                       'remove web root with port but empty' => ['http://example.com:8081', true, 'http://example.com:8081'],
-                       'remove web root from IP' => ['https://127.0.0.1/root', true, 'https://127.0.0.1'],
-                       'remove web root from IP with port' => ['https://127.0.0.1:8080/root', true, 'https://127.0.0.1:8080'],
-                       'remove web root from IPv6' => ['https://[ff02::1]/root', true, 'https://[ff02::1]'],
-                       'remove web root from IPv6 with port' => ['https://[ff02::1]:8080/root', true, 'https://[ff02::1]:8080'],
-               ];
-       }
-
-       /**
-        * @dataProvider dataGetTestUrls
-        */
-       public function testGetTestUrls(
-               string $url,
-               bool $isRootRequest,
-               string $cliUrl,
-               string $webRoot,
-               array $trustedDomains,
-               array $expected,
-       ): void {
-               $this->config->expects(self::atLeastOnce())
-                       ->method('getSystemValueString')
-                       ->with('overwrite.cli.url', '')
-                       ->willReturn($cliUrl);
-
-               $this->config->expects(self::atLeastOnce())
-                       ->method('getSystemValue')
-                       ->with('trusted_domains', [])
-                       ->willReturn($trustedDomains);
-
-               $this->urlGenerator->expects(self::atLeastOnce())
-                       ->method('getWebroot')
-                       ->willReturn($webRoot);
-
-               $this->urlGenerator->expects(self::atLeastOnce())
-                       ->method('getBaseUrl')
-                       ->willReturn(self::BASE_URL . $webRoot);
-               
-               $result = $this->trait->getTestUrls($url, $isRootRequest);
-               $this->assertEquals($expected, $result);
-       }
-
-       /**
-        * @return array<string, list{string, bool, string, string, list<string>, list<string>}>
-        */
-       public static function dataGetTestUrls(): array {
-               return [
-                       'same cli and base URL' => [
-                               '/apps/files/js/example.js', false, 'https://nextcloud.local', '', ['nextcloud.local'], [
-                                       // from cli url
-                                       'https://nextcloud.local/apps/files/js/example.js',
-                                       // http variant from trusted domains
-                                       'http://nextcloud.local/apps/files/js/example.js',
-                               ]
-                       ],
-                       'different cli and base URL' => [
-                               '/apps/files/js/example.js', false, 'https://example.com', '', ['nextcloud.local'], [
-                                       // from cli url
-                                       'https://example.com/apps/files/js/example.js',
-                                       // from base url
-                                       'https://nextcloud.local/apps/files/js/example.js',
-                                       // http variant from trusted domains
-                                       'http://nextcloud.local/apps/files/js/example.js',
-                               ]
-                       ],
-                       'different cli and base URL and trusted domains' => [
-                               '/apps/files/js/example.js', false, 'https://example.com', '', ['nextcloud.local', 'example.com', '127.0.0.1'], [
-                                       // from cli url
-                                       'https://example.com/apps/files/js/example.js',
-                                       // from base url
-                                       'https://nextcloud.local/apps/files/js/example.js',
-                                       // http variant from trusted domains
-                                       'http://nextcloud.local/apps/files/js/example.js',
-                                       'http://example.com/apps/files/js/example.js',
-                                       // trusted domains
-                                       'https://127.0.0.1/apps/files/js/example.js',
-                                       'http://127.0.0.1/apps/files/js/example.js',
-                               ]
-                       ],
-                       'wildcard trusted domains' => [
-                               '/apps/files/js/example.js', false, '', '', ['nextcloud.local', '*.example.com'], [
-                                       // from base url
-                                       'https://nextcloud.local/apps/files/js/example.js',
-                                       // http variant from trusted domains
-                                       'http://nextcloud.local/apps/files/js/example.js',
-                                       // trusted domains with wild card are skipped
-                               ]
-                       ],
-                       'missing leading slash' => [
-                               'apps/files/js/example.js', false, 'https://nextcloud.local', '', ['nextcloud.local'], [
-                                       // from cli url
-                                       'https://nextcloud.local/apps/files/js/example.js',
-                                       // http variant from trusted domains
-                                       'http://nextcloud.local/apps/files/js/example.js',
-                               ]
-                       ],
-                       'keep web-root' => [
-                               '/apps/files/js/example.js', false, 'https://example.com', '/nextcloud', ['nextcloud.local', 'example.com', '192.168.100.1'], [
-                                       // from cli url (note that the CLI url has NO web root)
-                                       'https://example.com/apps/files/js/example.js',
-                                       // from base url
-                                       'https://nextcloud.local/nextcloud/apps/files/js/example.js',
-                                       // http variant from trusted domains
-                                       'http://nextcloud.local/nextcloud/apps/files/js/example.js',
-                                       // trusted domains with web-root
-                                       'https://example.com/nextcloud/apps/files/js/example.js',
-                                       'http://example.com/nextcloud/apps/files/js/example.js',
-                                       'https://192.168.100.1/nextcloud/apps/files/js/example.js',
-                                       'http://192.168.100.1/nextcloud/apps/files/js/example.js',
-                               ]
-                       ],
-                       // example if the URL is generated by the URL generator
-                       'keep web-root and web root in url' => [
-                               '/nextcloud/apps/files/js/example.js', false, 'https://example.com', '/nextcloud', ['nextcloud.local', 'example.com', '192.168.100.1'], [
-                                       // from cli url (note that the CLI url has NO web root)
-                                       'https://example.com/apps/files/js/example.js',
-                                       // from base url
-                                       'https://nextcloud.local/nextcloud/apps/files/js/example.js',
-                                       // http variant from trusted domains
-                                       'http://nextcloud.local/nextcloud/apps/files/js/example.js',
-                                       // trusted domains with web-root
-                                       'https://example.com/nextcloud/apps/files/js/example.js',
-                                       'http://example.com/nextcloud/apps/files/js/example.js',
-                                       'https://192.168.100.1/nextcloud/apps/files/js/example.js',
-                                       'http://192.168.100.1/nextcloud/apps/files/js/example.js',
-                               ]
-                       ],
-                       'remove web-root' => [
-                               '/.well-known/caldav', true, 'https://example.com', '/nextcloud', ['nextcloud.local', 'example.com', '192.168.100.1'], [
-                                       // from cli url (note that the CLI url has NO web root)
-                                       'https://example.com/.well-known/caldav',
-                                       // from base url
-                                       'https://nextcloud.local/.well-known/caldav',
-                                       // http variant from trusted domains
-                                       'http://nextcloud.local/.well-known/caldav',
-                                       'http://example.com/.well-known/caldav',
-                                       // trusted domains with web-root
-                                       'https://192.168.100.1/.well-known/caldav',
-                                       'http://192.168.100.1/.well-known/caldav',
-                               ]
-                       ],
-               ];
-       }
-
-}
index 37013ecc1aecd2a15e28ddb29ad5d7d99c085e8c..5510143197ac85f6f9c319ddc1c0f27eab7a0daf 100644 (file)
@@ -700,6 +700,7 @@ return array(
     'OCP\\Settings\\IManager' => $baseDir . '/lib/public/Settings/IManager.php',
     'OCP\\Settings\\ISettings' => $baseDir . '/lib/public/Settings/ISettings.php',
     'OCP\\Settings\\ISubAdminSettings' => $baseDir . '/lib/public/Settings/ISubAdminSettings.php',
+    'OCP\\SetupCheck\\CheckServerResponseTrait' => $baseDir . '/lib/public/SetupCheck/CheckServerResponseTrait.php',
     'OCP\\SetupCheck\\ISetupCheck' => $baseDir . '/lib/public/SetupCheck/ISetupCheck.php',
     'OCP\\SetupCheck\\ISetupCheckManager' => $baseDir . '/lib/public/SetupCheck/ISetupCheckManager.php',
     'OCP\\SetupCheck\\SetupResult' => $baseDir . '/lib/public/SetupCheck/SetupResult.php',
index 293e79f80c64d802b55ea34fcb67852b11a56cfb..7b8584b5438263beea9e637ec578a31fec76cbf9 100644 (file)
@@ -733,6 +733,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
         'OCP\\Settings\\IManager' => __DIR__ . '/../../..' . '/lib/public/Settings/IManager.php',
         'OCP\\Settings\\ISettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISettings.php',
         'OCP\\Settings\\ISubAdminSettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISubAdminSettings.php',
+        'OCP\\SetupCheck\\CheckServerResponseTrait' => __DIR__ . '/../../..' . '/lib/public/SetupCheck/CheckServerResponseTrait.php',
         'OCP\\SetupCheck\\ISetupCheck' => __DIR__ . '/../../..' . '/lib/public/SetupCheck/ISetupCheck.php',
         'OCP\\SetupCheck\\ISetupCheckManager' => __DIR__ . '/../../..' . '/lib/public/SetupCheck/ISetupCheckManager.php',
         'OCP\\SetupCheck\\SetupResult' => __DIR__ . '/../../..' . '/lib/public/SetupCheck/SetupResult.php',
diff --git a/lib/public/SetupCheck/CheckServerResponseTrait.php b/lib/public/SetupCheck/CheckServerResponseTrait.php
new file mode 100644 (file)
index 0000000..29a2215
--- /dev/null
@@ -0,0 +1,162 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\SetupCheck;
+
+use Generator;
+use OCP\Http\Client\IClientService;
+use OCP\Http\Client\IResponse;
+use OCP\IConfig;
+use OCP\IURLGenerator;
+use OCP\L10N\IFactory;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Common trait for setup checks that need to use requests to the same server and check the response
+ * @since 31.0.0
+ */
+trait CheckServerResponseTrait {
+       protected IConfig $config;
+       protected IURLGenerator $urlGenerator;
+       protected IClientService $clientService;
+       protected LoggerInterface $logger;
+
+       /**
+        * Common helper string in case a check could not fetch any results
+        * @since 31.0.0
+        */
+       protected function serverConfigHelp(): string {
+               $l10n = \OCP\Server::get(IFactory::class)->get('lib');
+               return $l10n->t('To allow this check to run you have to make sure that your Web server can connect to itself. Therefore it must be able to resolve and connect to at least one of its `trusted_domains` or the `overwrite.cli.url`. This failure may be the result of a server-side DNS mismatch or outbound firewall rule.');
+       }
+
+       /**
+        * Get all possible URLs that need to be checked for a local request test.
+        * This takes all `trusted_domains` and the CLI overwrite URL into account.
+        *
+        * @param string $url The absolute path (absolute URL without host but with web-root) to test starting with a /
+        * @param bool $isRootRequest Set to remove the web-root from URL and host (e.g. when requesting a path in the domain root like '/.well-known')
+        * @return list<string> List of possible absolute URLs
+        * @since 31.0.0
+        */
+       protected function getTestUrls(string $url, bool $isRootRequest = false): array {
+               $url = '/' . ltrim($url, '/');
+
+               $webroot = rtrim($this->urlGenerator->getWebroot(), '/');
+               if ($isRootRequest === false && $webroot !== '' && str_starts_with($url, $webroot)) {
+                       // The URL contains the web-root but also the base url does so,
+                       // so we need to remove the web-root from the URL.
+                       $url = substr($url, strlen($webroot));
+               }
+
+               // Base URLs to test
+               $baseUrls = [];
+
+               // Try overwrite.cli.url first, it’s supposed to be how the server contacts itself
+               $cliUrl = $this->config->getSystemValueString('overwrite.cli.url', '');
+               if ($cliUrl !== '') {
+                       // The CLI URL already contains the web-root, so we need to normalize it if requested
+                       $baseUrls[] = $this->normalizeUrl(
+                               $cliUrl,
+                               $isRootRequest
+                       );
+               }
+
+               // Try URL generator second
+               // The base URL also contains the webroot so also normalize it
+               $baseUrls[] = $this->normalizeUrl(
+                       $this->urlGenerator->getBaseUrl(),
+                       $isRootRequest
+               );
+
+               /* Last resort: trusted domains */
+               $trustedDomains = $this->config->getSystemValue('trusted_domains', []);
+               foreach ($trustedDomains as $host) {
+                       if (str_contains($host, '*')) {
+                               /* Ignore domains with a wildcard */
+                               continue;
+                       }
+                       $baseUrls[] = $this->normalizeUrl("https://$host$webroot", $isRootRequest);
+                       $baseUrls[] = $this->normalizeUrl("http://$host$webroot", $isRootRequest);
+               }
+
+               return array_map(fn (string $host) => $host . $url, array_values(array_unique($baseUrls)));
+       }
+
+       /**
+        * Run a HTTP request to check header
+        * @param string $method The HTTP method to use
+        * @param string $url The absolute path (URL with webroot but without host) to check, can be the output of `IURLGenerator`
+        * @param bool $isRootRequest If set the webroot is removed from URLs to make the request target the host's root. Example usage are the /.well-known URLs in the root path.
+        * @param array{ignoreSSL?: bool, httpErrors?: bool, options?: array} $options HTTP client related options, like
+        *                                                                             [
+        *                                                                             // Ignore invalid SSL certificates (e.g. self signed)
+        *                                                                             'ignoreSSL' => true,
+        *                                                                             // Ignore requests with HTTP errors (will not yield if request has a 4xx or 5xx response)
+        *                                                                             'httpErrors' => true,
+        *                                                                             // Additional options for the HTTP client (see `IClient`)
+        *                                                                             'options' => [],
+        *                                                                             ]
+        *
+        * @return Generator<int, IResponse>
+        * @since 31.0.0
+        */
+       protected function runRequest(string $method, string $url, array $options = [], bool $isRootRequest = false): Generator {
+               $options = array_merge(['ignoreSSL' => true, 'httpErrors' => true], $options);
+
+               $client = $this->clientService->newClient();
+               $requestOptions = $this->getRequestOptions($options['ignoreSSL'], $options['httpErrors']);
+               $requestOptions = array_merge($requestOptions, $options['options'] ?? []);
+
+               foreach ($this->getTestUrls($url, $isRootRequest) as $testURL) {
+                       try {
+                               yield $client->request($method, $testURL, $requestOptions);
+                       } catch (\Throwable $e) {
+                               $this->logger->debug('Can not connect to local server for running setup checks', ['exception' => $e, 'url' => $testURL]);
+                       }
+               }
+       }
+
+       /**
+        * Get HTTP client options
+        * @param bool $ignoreSSL If set SSL errors are ignored (e.g. self-signed certificates)
+        * @since 31.0.0
+        */
+       private function getRequestOptions(bool $ignoreSSL, bool $httpErrors): array {
+               $requestOptions = [
+                       'connect_timeout' => 10,
+                       'http_errors' => $httpErrors,
+                       'nextcloud' => [
+                               'allow_local_address' => true,
+                       ],
+               ];
+               if ($ignoreSSL) {
+                       $requestOptions['verify'] = false;
+               }
+               return $requestOptions;
+       }
+
+       /**
+        * Strip a trailing slash and remove the webroot if requested.
+        * @param string $url The URL to normalize. Should be an absolute URL containing scheme, host and optionally web-root.
+        * @param bool $removeWebroot If set the web-root is removed from the URL and an absolute URL with only the scheme and host (optional port) is returned
+        * @since 31.0.0
+        */
+       private function normalizeUrl(string $url, bool $removeWebroot): string {
+               if ($removeWebroot) {
+                       $segments = parse_url($url);
+                       if (!isset($segments['scheme']) || !isset($segments['host'])) {
+                               throw new \InvalidArgumentException('URL is missing scheme or host');
+                       }
+
+                       $port = isset($segments['port']) ? (':' . $segments['port']) : '';
+                       return $segments['scheme'] . '://' . $segments['host'] . $port;
+               }
+               return rtrim($url, '/');
+       }
+}
diff --git a/tests/lib/SetupCheck/CheckServerResponseTraitImplementation.php b/tests/lib/SetupCheck/CheckServerResponseTraitImplementation.php
new file mode 100644 (file)
index 0000000..1119c5e
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace Test\SetupCheck;
+
+use OCP\Http\Client\IClientService;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\CheckServerResponseTrait;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Dummy implementation for CheckServerResponseTraitTest
+ */
+class CheckServerResponseTraitImplementation {
+
+       use CheckServerResponseTrait {
+               CheckServerResponseTrait::getRequestOptions as public;
+               CheckServerResponseTrait::runRequest as public;
+               CheckServerResponseTrait::normalizeUrl as public;
+               CheckServerResponseTrait::getTestUrls as public;
+       }
+
+       public function __construct(
+               protected IL10N $l10n,
+               protected IConfig $config,
+               protected IURLGenerator $urlGenerator,
+               protected IClientService $clientService,
+               protected LoggerInterface $logger,
+       ) {
+       }
+
+}
diff --git a/tests/lib/SetupCheck/CheckServerResponseTraitTest.php b/tests/lib/SetupCheck/CheckServerResponseTraitTest.php
new file mode 100644 (file)
index 0000000..32fbce6
--- /dev/null
@@ -0,0 +1,213 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace Test\SetupCheck;
+
+use OCP\Http\Client\IClientService;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class CheckServerResponseTraitTest extends TestCase {
+
+       protected const BASE_URL = 'https://nextcloud.local';
+       
+       private IL10N&MockObject $l10n;
+       private IConfig&MockObject $config;
+       private IURLGenerator&MockObject $urlGenerator;
+       private IClientService&MockObject $clientService;
+       private LoggerInterface&MockObject $logger;
+
+       private CheckServerResponseTraitImplementation $trait;
+
+       protected function setUp(): void {
+               parent::setUp();
+
+               $this->l10n = $this->createMock(IL10N::class);
+               $this->l10n->method('t')
+                       ->willReturnArgument(0);
+               $this->config = $this->createMock(IConfig::class);
+               $this->urlGenerator = $this->createMock(IURLGenerator::class);
+               $this->clientService = $this->createMock(IClientService::class);
+               $this->logger = $this->createMock(LoggerInterface::class);
+               
+               $this->trait = new CheckServerResponseTraitImplementation(
+                       $this->l10n,
+                       $this->config,
+                       $this->urlGenerator,
+                       $this->clientService,
+                       $this->logger,
+               );
+       }
+
+       /**
+        * @dataProvider dataNormalizeUrl
+        */
+       public function testNormalizeUrl(string $url, bool $isRootRequest, string $expected): void {
+               $this->assertEquals($expected, $this->trait->normalizeUrl($url, $isRootRequest));
+       }
+
+       public static function dataNormalizeUrl(): array {
+               return [
+                       // untouched web-root
+                       'valid and nothing to change' => ['http://example.com/root', false, 'http://example.com/root'],
+                       'valid with port and nothing to change' => ['http://example.com:8081/root', false, 'http://example.com:8081/root'],
+                       'trailing slash' => ['http://example.com/root/', false, 'http://example.com/root'],
+                       'deep web root' => ['http://example.com/deep/webroot', false, 'http://example.com/deep/webroot'],
+                       // removal of the web-root
+                       'remove web root' => ['http://example.com/root/', true, 'http://example.com'],
+                       'remove web root but empty' => ['http://example.com', true, 'http://example.com'],
+                       'remove deep web root' => ['http://example.com/deep/webroot', true, 'http://example.com'],
+                       'remove web root with port' => ['http://example.com:8081/root', true, 'http://example.com:8081'],
+                       'remove web root with port but empty' => ['http://example.com:8081', true, 'http://example.com:8081'],
+                       'remove web root from IP' => ['https://127.0.0.1/root', true, 'https://127.0.0.1'],
+                       'remove web root from IP with port' => ['https://127.0.0.1:8080/root', true, 'https://127.0.0.1:8080'],
+                       'remove web root from IPv6' => ['https://[ff02::1]/root', true, 'https://[ff02::1]'],
+                       'remove web root from IPv6 with port' => ['https://[ff02::1]:8080/root', true, 'https://[ff02::1]:8080'],
+               ];
+       }
+
+       /**
+        * @dataProvider dataGetTestUrls
+        */
+       public function testGetTestUrls(
+               string $url,
+               bool $isRootRequest,
+               string $cliUrl,
+               string $webRoot,
+               array $trustedDomains,
+               array $expected,
+       ): void {
+               $this->config->expects(self::atLeastOnce())
+                       ->method('getSystemValueString')
+                       ->with('overwrite.cli.url', '')
+                       ->willReturn($cliUrl);
+
+               $this->config->expects(self::atLeastOnce())
+                       ->method('getSystemValue')
+                       ->with('trusted_domains', [])
+                       ->willReturn($trustedDomains);
+
+               $this->urlGenerator->expects(self::atLeastOnce())
+                       ->method('getWebroot')
+                       ->willReturn($webRoot);
+
+               $this->urlGenerator->expects(self::atLeastOnce())
+                       ->method('getBaseUrl')
+                       ->willReturn(self::BASE_URL . $webRoot);
+               
+               $result = $this->trait->getTestUrls($url, $isRootRequest);
+               $this->assertEquals($expected, $result);
+       }
+
+       /**
+        * @return array<string, list{string, bool, string, string, list<string>, list<string>}>
+        */
+       public static function dataGetTestUrls(): array {
+               return [
+                       'same cli and base URL' => [
+                               '/apps/files/js/example.js', false, 'https://nextcloud.local', '', ['nextcloud.local'], [
+                                       // from cli url
+                                       'https://nextcloud.local/apps/files/js/example.js',
+                                       // http variant from trusted domains
+                                       'http://nextcloud.local/apps/files/js/example.js',
+                               ]
+                       ],
+                       'different cli and base URL' => [
+                               '/apps/files/js/example.js', false, 'https://example.com', '', ['nextcloud.local'], [
+                                       // from cli url
+                                       'https://example.com/apps/files/js/example.js',
+                                       // from base url
+                                       'https://nextcloud.local/apps/files/js/example.js',
+                                       // http variant from trusted domains
+                                       'http://nextcloud.local/apps/files/js/example.js',
+                               ]
+                       ],
+                       'different cli and base URL and trusted domains' => [
+                               '/apps/files/js/example.js', false, 'https://example.com', '', ['nextcloud.local', 'example.com', '127.0.0.1'], [
+                                       // from cli url
+                                       'https://example.com/apps/files/js/example.js',
+                                       // from base url
+                                       'https://nextcloud.local/apps/files/js/example.js',
+                                       // http variant from trusted domains
+                                       'http://nextcloud.local/apps/files/js/example.js',
+                                       'http://example.com/apps/files/js/example.js',
+                                       // trusted domains
+                                       'https://127.0.0.1/apps/files/js/example.js',
+                                       'http://127.0.0.1/apps/files/js/example.js',
+                               ]
+                       ],
+                       'wildcard trusted domains' => [
+                               '/apps/files/js/example.js', false, '', '', ['nextcloud.local', '*.example.com'], [
+                                       // from base url
+                                       'https://nextcloud.local/apps/files/js/example.js',
+                                       // http variant from trusted domains
+                                       'http://nextcloud.local/apps/files/js/example.js',
+                                       // trusted domains with wild card are skipped
+                               ]
+                       ],
+                       'missing leading slash' => [
+                               'apps/files/js/example.js', false, 'https://nextcloud.local', '', ['nextcloud.local'], [
+                                       // from cli url
+                                       'https://nextcloud.local/apps/files/js/example.js',
+                                       // http variant from trusted domains
+                                       'http://nextcloud.local/apps/files/js/example.js',
+                               ]
+                       ],
+                       'keep web-root' => [
+                               '/apps/files/js/example.js', false, 'https://example.com', '/nextcloud', ['nextcloud.local', 'example.com', '192.168.100.1'], [
+                                       // from cli url (note that the CLI url has NO web root)
+                                       'https://example.com/apps/files/js/example.js',
+                                       // from base url
+                                       'https://nextcloud.local/nextcloud/apps/files/js/example.js',
+                                       // http variant from trusted domains
+                                       'http://nextcloud.local/nextcloud/apps/files/js/example.js',
+                                       // trusted domains with web-root
+                                       'https://example.com/nextcloud/apps/files/js/example.js',
+                                       'http://example.com/nextcloud/apps/files/js/example.js',
+                                       'https://192.168.100.1/nextcloud/apps/files/js/example.js',
+                                       'http://192.168.100.1/nextcloud/apps/files/js/example.js',
+                               ]
+                       ],
+                       // example if the URL is generated by the URL generator
+                       'keep web-root and web root in url' => [
+                               '/nextcloud/apps/files/js/example.js', false, 'https://example.com', '/nextcloud', ['nextcloud.local', 'example.com', '192.168.100.1'], [
+                                       // from cli url (note that the CLI url has NO web root)
+                                       'https://example.com/apps/files/js/example.js',
+                                       // from base url
+                                       'https://nextcloud.local/nextcloud/apps/files/js/example.js',
+                                       // http variant from trusted domains
+                                       'http://nextcloud.local/nextcloud/apps/files/js/example.js',
+                                       // trusted domains with web-root
+                                       'https://example.com/nextcloud/apps/files/js/example.js',
+                                       'http://example.com/nextcloud/apps/files/js/example.js',
+                                       'https://192.168.100.1/nextcloud/apps/files/js/example.js',
+                                       'http://192.168.100.1/nextcloud/apps/files/js/example.js',
+                               ]
+                       ],
+                       'remove web-root' => [
+                               '/.well-known/caldav', true, 'https://example.com', '/nextcloud', ['nextcloud.local', 'example.com', '192.168.100.1'], [
+                                       // from cli url (note that the CLI url has NO web root)
+                                       'https://example.com/.well-known/caldav',
+                                       // from base url
+                                       'https://nextcloud.local/.well-known/caldav',
+                                       // http variant from trusted domains
+                                       'http://nextcloud.local/.well-known/caldav',
+                                       'http://example.com/.well-known/caldav',
+                                       // trusted domains with web-root
+                                       'https://192.168.100.1/.well-known/caldav',
+                                       'http://192.168.100.1/.well-known/caldav',
+                               ]
+                       ],
+               ];
+       }
+
+}