aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/tests')
-rw-r--r--apps/settings/tests/Activity/SecurityFilterTest.php64
-rw-r--r--apps/settings/tests/Activity/SecurityProviderTest.php109
-rw-r--r--apps/settings/tests/Activity/SecuritySettingTest.php55
-rw-r--r--apps/settings/tests/AppInfo/ApplicationTest.php63
-rw-r--r--apps/settings/tests/Controller/AdminSettingsControllerTest.php133
-rw-r--r--apps/settings/tests/Controller/AppSettingsControllerTest.php223
-rw-r--r--apps/settings/tests/Controller/AuthSettingsControllerTest.php440
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php581
-rw-r--r--apps/settings/tests/Controller/DelegationControllerTest.php54
-rw-r--r--apps/settings/tests/Controller/MailSettingsControllerTest.php167
-rw-r--r--apps/settings/tests/Controller/TwoFactorSettingsControllerTest.php62
-rw-r--r--apps/settings/tests/Controller/UsersControllerTest.php996
-rw-r--r--apps/settings/tests/Mailer/NewUserMailHelperTest.php907
-rw-r--r--apps/settings/tests/Middleware/SubadminMiddlewareTest.php126
-rw-r--r--apps/settings/tests/Settings/Admin/MailTest.php95
-rw-r--r--apps/settings/tests/Settings/Admin/SecurityTest.php113
-rw-r--r--apps/settings/tests/Settings/Admin/ServerTest.php106
-rw-r--r--apps/settings/tests/Settings/Admin/SharingTest.php264
-rw-r--r--apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php110
-rw-r--r--apps/settings/tests/Settings/Personal/Security/PasswordTest.php52
-rw-r--r--apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php102
-rw-r--r--apps/settings/tests/SetupChecks/CodeIntegrityTest.php134
-rw-r--r--apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php117
-rw-r--r--apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php119
-rw-r--r--apps/settings/tests/SetupChecks/LoggingLevelTest.php76
-rw-r--r--apps/settings/tests/SetupChecks/OcxProvicersTest.php151
-rw-r--r--apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php45
-rw-r--r--apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php41
-rw-r--r--apps/settings/tests/SetupChecks/SecurityHeadersTest.php196
-rw-r--r--apps/settings/tests/SetupChecks/SupportedDatabaseTest.php51
-rw-r--r--apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php73
-rw-r--r--apps/settings/tests/SetupChecks/WellKnownUrlsTest.php215
-rw-r--r--apps/settings/tests/UserMigration/AccountMigratorTest.php165
-rw-r--r--apps/settings/tests/UserMigration/assets/account-complex-config.json1
-rw-r--r--apps/settings/tests/UserMigration/assets/account-complex.jpgbin0 -> 1040846 bytes
-rw-r--r--apps/settings/tests/UserMigration/assets/account-complex.json1
-rw-r--r--apps/settings/tests/UserMigration/assets/account-config.json1
-rw-r--r--apps/settings/tests/UserMigration/assets/account.json1
-rw-r--r--apps/settings/tests/UserMigration/assets/account.pngbin0 -> 451063 bytes
39 files changed, 6209 insertions, 0 deletions
diff --git a/apps/settings/tests/Activity/SecurityFilterTest.php b/apps/settings/tests/Activity/SecurityFilterTest.php
new file mode 100644
index 00000000000..b07c1e825b4
--- /dev/null
+++ b/apps/settings/tests/Activity/SecurityFilterTest.php
@@ -0,0 +1,64 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests;
+
+use OCA\Settings\Activity\SecurityFilter;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class SecurityFilterTest extends TestCase {
+ private IURLGenerator&MockObject $urlGenerator;
+ private IL10N&MockObject $l10n;
+ private SecurityFilter $filter;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->l10n = $this->createMock(IL10N::class);
+
+ $this->filter = new SecurityFilter($this->urlGenerator, $this->l10n);
+ }
+
+ public function testAllowedApps(): void {
+ $this->assertEquals([], $this->filter->allowedApps());
+ }
+
+ public function testFilterTypes(): void {
+ $this->assertEquals(['security'], $this->filter->filterTypes(['comments', 'security']));
+ }
+
+ public function testGetIcon(): void {
+ $this->urlGenerator->expects($this->once())
+ ->method('imagePath')
+ ->with('core', 'actions/password.svg')
+ ->willReturn('path/to/icon.svg');
+ $this->urlGenerator->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('path/to/icon.svg')
+ ->willReturn('abs/path/to/icon.svg');
+ $this->assertEquals('abs/path/to/icon.svg', $this->filter->getIcon());
+ }
+
+ public function testGetIdentifier(): void {
+ $this->assertEquals('security', $this->filter->getIdentifier());
+ }
+
+ public function testGetName(): void {
+ $this->l10n->expects($this->once())
+ ->method('t')
+ ->with('Security')
+ ->willReturn('translated');
+ $this->assertEquals('translated', $this->filter->getName());
+ }
+
+ public function testGetPriority(): void {
+ $this->assertEquals(30, $this->filter->getPriority());
+ }
+}
diff --git a/apps/settings/tests/Activity/SecurityProviderTest.php b/apps/settings/tests/Activity/SecurityProviderTest.php
new file mode 100644
index 00000000000..ed9de362a87
--- /dev/null
+++ b/apps/settings/tests/Activity/SecurityProviderTest.php
@@ -0,0 +1,109 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests;
+
+use OCA\Settings\Activity\SecurityProvider;
+use OCP\Activity\Exceptions\UnknownActivityException;
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\L10N\IFactory;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class SecurityProviderTest extends TestCase {
+ private IFactory&MockObject $l10nFactory;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IManager&MockObject $activityManager;
+ private SecurityProvider $provider;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10nFactory = $this->createMock(IFactory::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->activityManager = $this->createMock(IManager::class);
+
+ $this->provider = new SecurityProvider($this->l10nFactory, $this->urlGenerator, $this->activityManager);
+ }
+
+ public function testParseUnrelated(): void {
+ $lang = 'ru';
+ $event = $this->createMock(IEvent::class);
+ $event->expects($this->once())
+ ->method('getType')
+ ->willReturn('comments');
+ $this->expectException(UnknownActivityException::class);
+
+ $this->provider->parse($lang, $event);
+ }
+
+ public static function subjectData(): array {
+ return [
+ ['twofactor_success'],
+ ['twofactor_failed'],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('subjectData')]
+ public function testParse(string $subject): void {
+ $lang = 'ru';
+ $event = $this->createMock(IEvent::class);
+ $l = $this->createMock(IL10N::class);
+
+ $event->expects($this->once())
+ ->method('getType')
+ ->willReturn('security');
+ $this->l10nFactory->expects($this->once())
+ ->method('get')
+ ->with('settings', $lang)
+ ->willReturn($l);
+ $this->urlGenerator->expects($this->once())
+ ->method('imagePath')
+ ->with('core', 'actions/password.svg')
+ ->willReturn('path/to/image');
+ $this->urlGenerator->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('path/to/image')
+ ->willReturn('absolute/path/to/image');
+ $event->expects($this->once())
+ ->method('setIcon')
+ ->with('absolute/path/to/image');
+ $event->expects($this->once())
+ ->method('getSubject')
+ ->willReturn($subject);
+ $event->method('getSubjectParameters')
+ ->willReturn([
+ 'provider' => 'myProvider',
+ ]);
+ $event->expects($this->once())
+ ->method('setParsedSubject');
+
+ $this->provider->parse($lang, $event);
+ }
+
+ public function testParseInvalidSubject(): void {
+ $lang = 'ru';
+ $l = $this->createMock(IL10N::class);
+ $event = $this->createMock(IEvent::class);
+
+ $event->expects($this->once())
+ ->method('getType')
+ ->willReturn('security');
+ $this->l10nFactory->expects($this->once())
+ ->method('get')
+ ->with('settings', $lang)
+ ->willReturn($l);
+ $event->expects($this->once())
+ ->method('getSubject')
+ ->willReturn('unrelated');
+
+ $this->expectException(UnknownActivityException::class);
+ $this->provider->parse($lang, $event);
+ }
+}
diff --git a/apps/settings/tests/Activity/SecuritySettingTest.php b/apps/settings/tests/Activity/SecuritySettingTest.php
new file mode 100644
index 00000000000..ca11e38caa8
--- /dev/null
+++ b/apps/settings/tests/Activity/SecuritySettingTest.php
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests;
+
+use OCA\Settings\Activity\SecuritySetting;
+use OCP\IL10N;
+use Test\TestCase;
+
+class SecuritySettingTest extends TestCase {
+ private $l10n;
+
+ /** @var */
+ private SecuritySetting $setting;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+
+ $this->setting = new SecuritySetting($this->l10n);
+ }
+
+ public function testCanChangeMail(): void {
+ $this->assertFalse($this->setting->canChangeMail());
+ }
+
+ public function testCanChangeStream(): void {
+ $this->assertFalse($this->setting->canChangeStream());
+ }
+
+ public function testGetIdentifier(): void {
+ $this->assertEquals('security', $this->setting->getIdentifier());
+ }
+
+ public function testGetName(): void {
+ $this->l10n->expects($this->once())
+ ->method('t')
+ ->with('Security')
+ ->willReturn('Sicherheit');
+ $this->assertEquals('Sicherheit', $this->setting->getName());
+ }
+
+ public function testGetPriority(): void {
+ $this->assertEquals(30, $this->setting->getPriority());
+ }
+
+ public function testIsDefaultEnabled(): void {
+ $this->assertTrue($this->setting->isDefaultEnabledMail());
+ $this->assertTrue($this->setting->isDefaultEnabledStream());
+ }
+}
diff --git a/apps/settings/tests/AppInfo/ApplicationTest.php b/apps/settings/tests/AppInfo/ApplicationTest.php
new file mode 100644
index 00000000000..3e895d87b06
--- /dev/null
+++ b/apps/settings/tests/AppInfo/ApplicationTest.php
@@ -0,0 +1,63 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\AppInfo;
+
+use OCA\Settings\AppInfo\Application;
+use OCA\Settings\Controller\AdminSettingsController;
+use OCA\Settings\Controller\AppSettingsController;
+use OCA\Settings\Controller\AuthSettingsController;
+use OCA\Settings\Controller\CheckSetupController;
+use OCA\Settings\Controller\LogSettingsController;
+use OCA\Settings\Controller\MailSettingsController;
+use OCA\Settings\Controller\UsersController;
+use OCA\Settings\Middleware\SubadminMiddleware;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\IAppContainer;
+use OCP\AppFramework\Middleware;
+use Test\TestCase;
+
+/**
+ * Class ApplicationTest
+ *
+ * @package Tests\Settings
+ * @group DB
+ */
+class ApplicationTest extends TestCase {
+ protected Application $app;
+ protected IAppContainer $container;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ }
+
+ public function testContainerAppName(): void {
+ $this->app = new Application();
+ $this->assertEquals('settings', $this->container->get('appName'));
+ }
+
+ public static function dataContainerQuery(): array {
+ return [
+ [AdminSettingsController::class, Controller::class],
+ [AppSettingsController::class, Controller::class],
+ [AuthSettingsController::class, Controller::class],
+ [CheckSetupController::class, Controller::class],
+ [LogSettingsController::class, Controller::class],
+ [MailSettingsController::class, Controller::class],
+ [UsersController::class, Controller::class],
+
+ [SubadminMiddleware::class, Middleware::class],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataContainerQuery')]
+ public function testContainerQuery(string $service, string $expected): void {
+ $this->assertTrue($this->container->query($service) instanceof $expected);
+ }
+}
diff --git a/apps/settings/tests/Controller/AdminSettingsControllerTest.php b/apps/settings/tests/Controller/AdminSettingsControllerTest.php
new file mode 100644
index 00000000000..fbdc506457b
--- /dev/null
+++ b/apps/settings/tests/Controller/AdminSettingsControllerTest.php
@@ -0,0 +1,133 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Controller;
+
+use OCA\Settings\Controller\AdminSettingsController;
+use OCA\Settings\Settings\Personal\ServerDevNotice;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
+use OCP\Group\ISubAdmin;
+use OCP\IGroupManager;
+use OCP\INavigationManager;
+use OCP\IRequest;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\IUserSession;
+use OCP\Server;
+use OCP\Settings\IDeclarativeManager;
+use OCP\Settings\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+/**
+ * Class AdminSettingsControllerTest
+ *
+ * @group DB
+ *
+ * @package Tests\Settings\Controller
+ */
+class AdminSettingsControllerTest extends TestCase {
+
+ private IRequest&MockObject $request;
+ private INavigationManager&MockObject $navigationManager;
+ private IManager&MockObject $settingsManager;
+ private IUserSession&MockObject $userSession;
+ private IGroupManager&MockObject $groupManager;
+ private ISubAdmin&MockObject $subAdmin;
+ private IDeclarativeManager&MockObject $declarativeSettingsManager;
+ private IInitialState&MockObject $initialState;
+
+ private string $adminUid = 'lololo';
+ private AdminSettingsController $adminSettingsController;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ $this->navigationManager = $this->createMock(INavigationManager::class);
+ $this->settingsManager = $this->createMock(IManager::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
+ $this->subAdmin = $this->createMock(ISubAdmin::class);
+ $this->declarativeSettingsManager = $this->createMock(IDeclarativeManager::class);
+ $this->initialState = $this->createMock(IInitialState::class);
+
+ $this->adminSettingsController = new AdminSettingsController(
+ 'settings',
+ $this->request,
+ $this->navigationManager,
+ $this->settingsManager,
+ $this->userSession,
+ $this->groupManager,
+ $this->subAdmin,
+ $this->declarativeSettingsManager,
+ $this->initialState,
+ );
+
+ $user = Server::get(IUserManager::class)->createUser($this->adminUid, 'mylongrandompassword');
+ \OC_User::setUserId($user->getUID());
+ Server::get(IGroupManager::class)->createGroup('admin')->addUser($user);
+ }
+
+ protected function tearDown(): void {
+ Server::get(IUserManager::class)
+ ->get($this->adminUid)
+ ->delete();
+ \OC_User::setUserId(null);
+ Server::get(IUserSession::class)->setUser(null);
+
+ parent::tearDown();
+ }
+
+ public function testIndex(): void {
+ $user = $this->createMock(IUser::class);
+ $this->userSession
+ ->method('getUser')
+ ->willReturn($user);
+ $user->method('getUID')->willReturn('user123');
+ $this->groupManager
+ ->method('isAdmin')
+ ->with('user123')
+ ->willReturn(true);
+ $this->subAdmin
+ ->method('isSubAdmin')
+ ->with($user)
+ ->willReturn(false);
+
+ $form = new TemplateResponse('settings', 'settings/empty');
+ $setting = $this->createMock(ServerDevNotice::class);
+ $setting->expects(self::any())
+ ->method('getForm')
+ ->willReturn($form);
+ $this->settingsManager
+ ->expects($this->once())
+ ->method('getAdminSections')
+ ->willReturn([]);
+ $this->settingsManager
+ ->expects($this->once())
+ ->method('getPersonalSections')
+ ->willReturn([]);
+ $this->settingsManager
+ ->expects($this->once())
+ ->method('getAllowedAdminSettings')
+ ->with('test')
+ ->willReturn([5 => [$setting]]);
+ $this->declarativeSettingsManager
+ ->expects($this->any())
+ ->method('getFormIDs')
+ ->with($user, 'admin', 'test')
+ ->willReturn([]);
+
+ $idx = $this->adminSettingsController->index('test');
+
+ $expected = new TemplateResponse('settings', 'settings/frame', [
+ 'forms' => ['personal' => [], 'admin' => []],
+ 'content' => ''
+ ]);
+ $this->assertEquals($expected, $idx);
+ }
+}
diff --git a/apps/settings/tests/Controller/AppSettingsControllerTest.php b/apps/settings/tests/Controller/AppSettingsControllerTest.php
new file mode 100644
index 00000000000..392bb7b561d
--- /dev/null
+++ b/apps/settings/tests/Controller/AppSettingsControllerTest.php
@@ -0,0 +1,223 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCA\Settings\Tests\Controller;
+
+use OC\App\AppManager;
+use OC\App\AppStore\Bundles\BundleFetcher;
+use OC\App\AppStore\Fetcher\AppDiscoverFetcher;
+use OC\App\AppStore\Fetcher\AppFetcher;
+use OC\App\AppStore\Fetcher\CategoryFetcher;
+use OC\Installer;
+use OCA\Settings\Controller\AppSettingsController;
+use OCP\AppFramework\Http\ContentSecurityPolicy;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
+use OCP\Files\AppData\IAppDataFactory;
+use OCP\Http\Client\IClientService;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\INavigationManager;
+use OCP\IRequest;
+use OCP\IURLGenerator;
+use OCP\L10N\IFactory;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+/**
+ * Class AppSettingsControllerTest
+ *
+ * @package Tests\Settings\Controller
+ *
+ * @group DB
+ */
+class AppSettingsControllerTest extends TestCase {
+ private IRequest&MockObject $request;
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private INavigationManager&MockObject $navigationManager;
+ private AppManager&MockObject $appManager;
+ private CategoryFetcher&MockObject $categoryFetcher;
+ private AppFetcher&MockObject $appFetcher;
+ private IFactory&MockObject $l10nFactory;
+ private BundleFetcher&MockObject $bundleFetcher;
+ private Installer&MockObject $installer;
+ private IURLGenerator&MockObject $urlGenerator;
+ private LoggerInterface&MockObject $logger;
+ private IInitialState&MockObject $initialState;
+ private IAppDataFactory&MockObject $appDataFactory;
+ private AppDiscoverFetcher&MockObject $discoverFetcher;
+ private IClientService&MockObject $clientService;
+ private AppSettingsController $appSettingsController;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ $this->appDataFactory = $this->createMock(IAppDataFactory::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnArgument(0);
+ $this->config = $this->createMock(IConfig::class);
+ $this->navigationManager = $this->createMock(INavigationManager::class);
+ $this->appManager = $this->createMock(AppManager::class);
+ $this->categoryFetcher = $this->createMock(CategoryFetcher::class);
+ $this->appFetcher = $this->createMock(AppFetcher::class);
+ $this->l10nFactory = $this->createMock(IFactory::class);
+ $this->bundleFetcher = $this->createMock(BundleFetcher::class);
+ $this->installer = $this->createMock(Installer::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->initialState = $this->createMock(IInitialState::class);
+ $this->discoverFetcher = $this->createMock(AppDiscoverFetcher::class);
+ $this->clientService = $this->createMock(IClientService::class);
+
+ $this->appSettingsController = new AppSettingsController(
+ 'settings',
+ $this->request,
+ $this->appDataFactory,
+ $this->l10n,
+ $this->config,
+ $this->navigationManager,
+ $this->appManager,
+ $this->categoryFetcher,
+ $this->appFetcher,
+ $this->l10nFactory,
+ $this->bundleFetcher,
+ $this->installer,
+ $this->urlGenerator,
+ $this->logger,
+ $this->initialState,
+ $this->discoverFetcher,
+ $this->clientService,
+ );
+ }
+
+ public function testListCategories(): void {
+ $this->installer->expects($this->any())
+ ->method('isUpdateAvailable')
+ ->willReturn(false);
+ $expected = new JSONResponse([
+ [
+ 'id' => 'auth',
+ 'displayName' => 'Authentication & authorization',
+ ],
+ [
+ 'id' => 'customization',
+ 'displayName' => 'Customization',
+ ],
+ [
+ 'id' => 'files',
+ 'displayName' => 'Files',
+ ],
+ [
+ 'id' => 'integration',
+ 'displayName' => 'Integration',
+ ],
+ [
+ 'id' => 'monitoring',
+ 'displayName' => 'Monitoring',
+ ],
+ [
+ 'id' => 'multimedia',
+ 'displayName' => 'Multimedia',
+ ],
+ [
+ 'id' => 'office',
+ 'displayName' => 'Office & text',
+ ],
+ [
+ 'id' => 'organization',
+ 'displayName' => 'Organization',
+ ],
+ [
+ 'id' => 'social',
+ 'displayName' => 'Social & communication',
+ ],
+ [
+ 'id' => 'tools',
+ 'displayName' => 'Tools',
+ ],
+ ]);
+
+ $this->categoryFetcher
+ ->expects($this->once())
+ ->method('get')
+ ->willReturn(json_decode('[{"id":"auth","translations":{"cs":{"name":"Autentizace & autorizace","description":"Aplikace poskytující služby dodatečného ověření nebo přihlášení"},"hu":{"name":"Azonosítás és hitelesítés","description":"Apps that provide additional authentication or authorization services"},"de":{"name":"Authentifizierung & Authorisierung","description":"Apps die zusätzliche Autentifizierungs- oder Autorisierungsdienste bereitstellen"},"nl":{"name":"Authenticatie & authorisatie","description":"Apps die aanvullende authenticatie- en autorisatiediensten bieden"},"nb":{"name":"Pålogging og tilgangsstyring","description":"Apper for å tilby ekstra pålogging eller tilgangsstyring"},"it":{"name":"Autenticazione e autorizzazione","description":"Apps that provide additional authentication or authorization services"},"fr":{"name":"Authentification et autorisations","description":"Applications qui fournissent des services d\'authentification ou d\'autorisations additionnels."},"ru":{"name":"Аутентификация и авторизация","description":"Apps that provide additional authentication or authorization services"},"en":{"name":"Authentication & authorization","description":"Apps that provide additional authentication or authorization services"}}},{"id":"customization","translations":{"cs":{"name":"Přizpůsobení","description":"Motivy a aplikace měnící rozvržení a uživatelské rozhraní"},"it":{"name":"Personalizzazione","description":"Applicazioni di temi, modifiche della disposizione e UX"},"de":{"name":"Anpassung","description":"Apps zur Änderung von Themen, Layout und Benutzererfahrung"},"hu":{"name":"Személyre szabás","description":"Témák, elrendezések felhasználói felület módosító alkalmazások"},"nl":{"name":"Maatwerk","description":"Thema\'s, layout en UX aanpassingsapps"},"nb":{"name":"Tilpasning","description":"Apper for å endre Tema, utseende og brukeropplevelse"},"fr":{"name":"Personalisation","description":"Thèmes, apparence et applications modifiant l\'expérience utilisateur"},"ru":{"name":"Настройка","description":"Themes, layout and UX change apps"},"en":{"name":"Customization","description":"Themes, layout and UX change apps"}}},{"id":"files","translations":{"cs":{"name":"Soubory","description":"Aplikace rozšiřující správu souborů nebo aplikaci Soubory"},"it":{"name":"File","description":"Applicazioni di gestione dei file ed estensione dell\'applicazione FIle"},"de":{"name":"Dateien","description":"Dateimanagement sowie Erweiterungs-Apps für die Dateien-App"},"hu":{"name":"Fájlok","description":"Fájl kezelő és kiegészítő alkalmazások"},"nl":{"name":"Bestanden","description":"Bestandebeheer en uitbreidingen van bestand apps"},"nb":{"name":"Filer","description":"Apper for filhåndtering og filer"},"fr":{"name":"Fichiers","description":"Applications de gestion de fichiers et extensions à l\'application Fichiers"},"ru":{"name":"Файлы","description":"Расширение: файлы и управление файлами"},"en":{"name":"Files","description":"File management and Files app extension apps"}}},{"id":"integration","translations":{"it":{"name":"Integrazione","description":"Applicazioni che collegano Nextcloud con altri servizi e piattaforme"},"hu":{"name":"Integráció","description":"Apps that connect Nextcloud with other services and platforms"},"nl":{"name":"Integratie","description":"Apps die Nextcloud verbinden met andere services en platformen"},"nb":{"name":"Integrasjon","description":"Apper som kobler Nextcloud med andre tjenester og plattformer"},"de":{"name":"Integration","description":"Apps die Nextcloud mit anderen Diensten und Plattformen verbinden"},"cs":{"name":"Propojení","description":"Aplikace propojující NextCloud s dalšími službami a platformami"},"fr":{"name":"Intégration","description":"Applications qui connectent Nextcloud avec d\'autres services et plateformes"},"ru":{"name":"Интеграция","description":"Приложения, соединяющие Nextcloud с другими службами и платформами"},"en":{"name":"Integration","description":"Apps that connect Nextcloud with other services and platforms"}}},{"id":"monitoring","translations":{"nb":{"name":"Overvåking","description":"Apper for statistikk, systemdiagnose og aktivitet"},"it":{"name":"Monitoraggio","description":"Applicazioni di statistiche, diagnostica di sistema e attività"},"de":{"name":"Überwachung","description":"Datenstatistiken-, Systemdiagnose- und Aktivitäten-Apps"},"hu":{"name":"Megfigyelés","description":"Data statistics, system diagnostics and activity apps"},"nl":{"name":"Monitoren","description":"Gegevensstatistiek, systeem diagnose en activiteit apps"},"cs":{"name":"Kontrola","description":"Datové statistiky, diagnózy systému a aktivity aplikací"},"fr":{"name":"Surveillance","description":"Applications de statistiques sur les données, de diagnostics systèmes et d\'activité."},"ru":{"name":"Мониторинг","description":"Статистика данных, диагностика системы и активность приложений"},"en":{"name":"Monitoring","description":"Data statistics, system diagnostics and activity apps"}}},{"id":"multimedia","translations":{"nb":{"name":"Multimedia","description":"Apper for lyd, film og bilde"},"it":{"name":"Multimedia","description":"Applicazioni per audio, video e immagini"},"de":{"name":"Multimedia","description":"Audio-, Video- und Bilder-Apps"},"hu":{"name":"Multimédia","description":"Hang, videó és kép alkalmazások"},"nl":{"name":"Multimedia","description":"Audio, video en afbeelding apps"},"en":{"name":"Multimedia","description":"Audio, video and picture apps"},"cs":{"name":"Multimédia","description":"Aplikace audia, videa a obrázků"},"fr":{"name":"Multimédia","description":"Applications audio, vidéo et image"},"ru":{"name":"Мультимедиа","description":"Приложение аудио, видео и изображения"}}},{"id":"office","translations":{"nb":{"name":"Kontorstøtte og tekst","description":"Apper for Kontorstøtte og tekstbehandling"},"it":{"name":"Ufficio e testo","description":"Applicazione per ufficio ed elaborazione di testi"},"de":{"name":"Büro & Text","description":"Büro- und Textverarbeitungs-Apps"},"hu":{"name":"Iroda és szöveg","description":"Irodai és szöveg feldolgozó alkalmazások"},"nl":{"name":"Office & tekst","description":"Office en tekstverwerkingsapps"},"cs":{"name":"Kancelář a text","description":"Aplikace pro kancelář a zpracování textu"},"fr":{"name":"Bureautique & texte","description":"Applications de bureautique et de traitement de texte"},"en":{"name":"Office & text","description":"Office and text processing apps"}}},{"id":"organization","translations":{"nb":{"name":"Organisering","description":"Apper for tidsstyring, oppgaveliste og kalender"},"it":{"name":"Organizzazione","description":"Applicazioni di gestione del tempo, elenco delle cose da fare e calendario"},"hu":{"name":"Szervezet","description":"Időbeosztás, teendő lista és naptár alkalmazások"},"nl":{"name":"Organisatie","description":"Tijdmanagement, takenlijsten en agenda apps"},"cs":{"name":"Organizace","description":"Aplikace pro správu času, plánování a kalendáře"},"de":{"name":"Organisation","description":"Time management, Todo list and calendar apps"},"fr":{"name":"Organisation","description":"Applications de gestion du temps, de listes de tâches et d\'agendas"},"ru":{"name":"Организация","description":"Приложения по управлению временем, список задач и календарь"},"en":{"name":"Organization","description":"Time management, Todo list and calendar apps"}}},{"id":"social","translations":{"nb":{"name":"Sosialt og kommunikasjon","description":"Apper for meldinger, kontakthåndtering og sosiale medier"},"it":{"name":"Sociale e comunicazione","description":"Applicazioni di messaggistica, gestione dei contatti e reti sociali"},"de":{"name":"Kommunikation","description":"Nachrichten-, Kontaktverwaltungs- und Social-Media-Apps"},"hu":{"name":"Közösségi és kommunikáció","description":"Üzenetküldő, kapcsolat kezelő és közösségi média alkalmazások"},"nl":{"name":"Sociaal & communicatie","description":"Messaging, contactbeheer en social media apps"},"cs":{"name":"Sociální sítě a komunikace","description":"Aplikace pro zasílání zpráv, správu kontaktů a sociální sítě"},"fr":{"name":"Social & communication","description":"Applications de messagerie, de gestion de contacts et de réseaux sociaux"},"ru":{"name":"Социальное и связь","description":"Общение, управление контактами и социальное медиа-приложение"},"en":{"name":"Social & communication","description":"Messaging, contact management and social media apps"}}},{"id":"tools","translations":{"nb":{"name":"Verktøy","description":"Alt annet"},"it":{"name":"Strumenti","description":"Tutto il resto"},"hu":{"name":"Eszközök","description":"Minden más"},"nl":{"name":"Tools","description":"De rest"},"de":{"name":"Werkzeuge","description":"Alles Andere"},"en":{"name":"Tools","description":"Everything else"},"cs":{"name":"Nástroje","description":"Vše ostatní"},"fr":{"name":"Outils","description":"Tout le reste"},"ru":{"name":"Приложения","description":"Что-то еще"}}}]', true));
+
+ $this->assertEquals($expected, $this->appSettingsController->listCategories());
+ }
+
+ public function testViewApps(): void {
+ $this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
+ $this->installer->expects($this->any())
+ ->method('isUpdateAvailable')
+ ->willReturn(false);
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('appstoreenabled', true)
+ ->willReturn(true);
+ $this->navigationManager
+ ->expects($this->once())
+ ->method('setActiveEntry')
+ ->with('core_apps');
+
+ $this->initialState
+ ->expects($this->exactly(4))
+ ->method('provideInitialState');
+
+ $policy = new ContentSecurityPolicy();
+ $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
+
+ $expected = new TemplateResponse('settings',
+ 'settings/empty',
+ [
+ 'pageTitle' => 'Settings'
+ ],
+ 'user');
+ $expected->setContentSecurityPolicy($policy);
+
+ $this->assertEquals($expected, $this->appSettingsController->viewApps());
+ }
+
+ public function testViewAppsAppstoreNotEnabled(): void {
+ $this->installer->expects($this->any())
+ ->method('isUpdateAvailable')
+ ->willReturn(false);
+ $this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('appstoreenabled', true)
+ ->willReturn(false);
+ $this->navigationManager
+ ->expects($this->once())
+ ->method('setActiveEntry')
+ ->with('core_apps');
+
+ $this->initialState
+ ->expects($this->exactly(4))
+ ->method('provideInitialState');
+
+ $policy = new ContentSecurityPolicy();
+ $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
+
+ $expected = new TemplateResponse('settings',
+ 'settings/empty',
+ [
+ 'pageTitle' => 'Settings'
+ ],
+ 'user');
+ $expected->setContentSecurityPolicy($policy);
+
+ $this->assertEquals($expected, $this->appSettingsController->viewApps());
+ }
+}
diff --git a/apps/settings/tests/Controller/AuthSettingsControllerTest.php b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
new file mode 100644
index 00000000000..d195dbf83d3
--- /dev/null
+++ b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
@@ -0,0 +1,440 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace Test\Settings\Controller;
+
+use OC\AppFramework\Http;
+use OC\Authentication\Exceptions\ExpiredTokenException;
+use OC\Authentication\Exceptions\InvalidTokenException;
+use OC\Authentication\Token\IProvider;
+use OC\Authentication\Token\IToken;
+use OC\Authentication\Token\IWipeableToken;
+use OC\Authentication\Token\PublicKeyToken;
+use OC\Authentication\Token\RemoteWipe;
+use OCA\Settings\Controller\AuthSettingsController;
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\IRequest;
+use OCP\ISession;
+use OCP\IUserSession;
+use OCP\Security\ISecureRandom;
+use OCP\Session\Exceptions\SessionNotAvailableException;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class AuthSettingsControllerTest extends TestCase {
+ private IRequest&MockObject $request;
+ private IProvider&MockObject $tokenProvider;
+ private ISession&MockObject $session;
+ private IUserSession&MockObject $userSession;
+ private ISecureRandom&MockObject $secureRandom;
+ private IManager&MockObject $activityManager;
+ private RemoteWipe&MockObject $remoteWipe;
+ private string $uid = 'jane';
+ private AuthSettingsController $controller;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ $this->tokenProvider = $this->createMock(IProvider::class);
+ $this->session = $this->createMock(ISession::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->secureRandom = $this->createMock(ISecureRandom::class);
+ $this->activityManager = $this->createMock(IManager::class);
+ $this->remoteWipe = $this->createMock(RemoteWipe::class);
+ /** @var LoggerInterface&MockObject $logger */
+ $logger = $this->createMock(LoggerInterface::class);
+
+ $this->controller = new AuthSettingsController(
+ 'core',
+ $this->request,
+ $this->tokenProvider,
+ $this->session,
+ $this->secureRandom,
+ $this->uid,
+ $this->userSession,
+ $this->activityManager,
+ $this->remoteWipe,
+ $logger
+ );
+ }
+
+ public function testCreate(): void {
+ $name = 'Nexus 4';
+ $sessionToken = $this->createMock(IToken::class);
+ $deviceToken = $this->createMock(IToken::class);
+ $password = '123456';
+
+ $this->session->expects($this->once())
+ ->method('getId')
+ ->willReturn('sessionid');
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('sessionid')
+ ->willReturn($sessionToken);
+ $this->tokenProvider->expects($this->once())
+ ->method('getPassword')
+ ->with($sessionToken, 'sessionid')
+ ->willReturn($password);
+ $sessionToken->expects($this->once())
+ ->method('getLoginName')
+ ->willReturn('User13');
+
+ $this->secureRandom->expects($this->exactly(5))
+ ->method('generate')
+ ->with(5, ISecureRandom::CHAR_HUMAN_READABLE)
+ ->willReturn('XXXXX');
+ $newToken = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX';
+
+ $this->tokenProvider->expects($this->once())
+ ->method('generateToken')
+ ->with($newToken, $this->uid, 'User13', $password, $name, IToken::PERMANENT_TOKEN)
+ ->willReturn($deviceToken);
+
+ $deviceToken->expects($this->once())
+ ->method('jsonSerialize')
+ ->willReturn(['dummy' => 'dummy', 'canDelete' => true]);
+
+ $this->mockActivityManager();
+
+ $expected = [
+ 'token' => $newToken,
+ 'deviceToken' => ['dummy' => 'dummy', 'canDelete' => true, 'canRename' => true],
+ 'loginName' => 'User13',
+ ];
+
+ $response = $this->controller->create($name);
+ $this->assertInstanceOf(JSONResponse::class, $response);
+ $this->assertEquals($expected, $response->getData());
+ }
+
+ public function testCreateSessionNotAvailable(): void {
+ $name = 'personal phone';
+
+ $this->session->expects($this->once())
+ ->method('getId')
+ ->willThrowException(new SessionNotAvailableException());
+
+ $expected = new JSONResponse();
+ $expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
+
+ $this->assertEquals($expected, $this->controller->create($name));
+ }
+
+ public function testCreateInvalidToken(): void {
+ $name = 'Company IPhone';
+
+ $this->session->expects($this->once())
+ ->method('getId')
+ ->willReturn('sessionid');
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('sessionid')
+ ->willThrowException(new InvalidTokenException());
+
+ $expected = new JSONResponse();
+ $expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
+
+ $this->assertEquals($expected, $this->controller->create($name));
+ }
+
+ public function testDestroy(): void {
+ $tokenId = 124;
+ $token = $this->createMock(PublicKeyToken::class);
+
+ $this->mockGetTokenById($tokenId, $token);
+ $this->mockActivityManager();
+
+ $token->expects($this->exactly(2))
+ ->method('getId')
+ ->willReturn($tokenId);
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn('jane');
+
+ $this->tokenProvider->expects($this->once())
+ ->method('invalidateTokenById')
+ ->with($this->uid, $tokenId);
+
+ $this->assertEquals([], $this->controller->destroy($tokenId));
+ }
+
+ public function testDestroyExpired(): void {
+ $tokenId = 124;
+ $token = $this->createMock(PublicKeyToken::class);
+
+ $token->expects($this->exactly(2))
+ ->method('getId')
+ ->willReturn($tokenId);
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn($this->uid);
+
+ $this->tokenProvider->expects($this->once())
+ ->method('getTokenById')
+ ->with($this->equalTo($tokenId))
+ ->willThrowException(new ExpiredTokenException($token));
+
+ $this->tokenProvider->expects($this->once())
+ ->method('invalidateTokenById')
+ ->with($this->uid, $tokenId);
+
+ $this->assertSame([], $this->controller->destroy($tokenId));
+ }
+
+ public function testDestroyWrongUser(): void {
+ $tokenId = 124;
+ $token = $this->createMock(PublicKeyToken::class);
+
+ $this->mockGetTokenById($tokenId, $token);
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn('foobar');
+
+ $response = $this->controller->destroy($tokenId);
+ $this->assertSame([], $response->getData());
+ $this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
+ }
+
+ public static function dataRenameToken(): array {
+ return [
+ 'App password => Other token name' => ['App password', 'Other token name'],
+ 'Other token name => App password' => ['Other token name', 'App password'],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRenameToken')]
+ public function testUpdateRename(string $name, string $newName): void {
+ $tokenId = 42;
+ $token = $this->createMock(PublicKeyToken::class);
+
+ $this->mockGetTokenById($tokenId, $token);
+ $this->mockActivityManager();
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn('jane');
+
+ $token->expects($this->once())
+ ->method('getName')
+ ->willReturn($name);
+
+ $token->expects($this->once())
+ ->method('getScopeAsArray')
+ ->willReturn([IToken::SCOPE_FILESYSTEM => true]);
+
+ $token->expects($this->once())
+ ->method('setName')
+ ->with($this->equalTo($newName));
+
+ $this->tokenProvider->expects($this->once())
+ ->method('updateToken')
+ ->with($this->equalTo($token));
+
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], $newName));
+ }
+
+ public static function dataUpdateFilesystemScope(): array {
+ return [
+ 'Grant filesystem access' => [false, true],
+ 'Revoke filesystem access' => [true, false],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateFilesystemScope')]
+ public function testUpdateFilesystemScope(bool $filesystem, bool $newFilesystem): void {
+ $tokenId = 42;
+ $token = $this->createMock(PublicKeyToken::class);
+
+ $this->mockGetTokenById($tokenId, $token);
+ $this->mockActivityManager();
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn('jane');
+
+ $token->expects($this->once())
+ ->method('getName')
+ ->willReturn('App password');
+
+ $token->expects($this->once())
+ ->method('getScopeAsArray')
+ ->willReturn([IToken::SCOPE_FILESYSTEM => $filesystem]);
+
+ $token->expects($this->once())
+ ->method('setScope')
+ ->with($this->equalTo([IToken::SCOPE_FILESYSTEM => $newFilesystem]));
+
+ $this->tokenProvider->expects($this->once())
+ ->method('updateToken')
+ ->with($this->equalTo($token));
+
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => $newFilesystem], 'App password'));
+ }
+
+ public function testUpdateNoChange(): void {
+ $tokenId = 42;
+ $token = $this->createMock(PublicKeyToken::class);
+
+ $this->mockGetTokenById($tokenId, $token);
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn('jane');
+
+ $token->expects($this->once())
+ ->method('getName')
+ ->willReturn('App password');
+
+ $token->expects($this->once())
+ ->method('getScopeAsArray')
+ ->willReturn([IToken::SCOPE_FILESYSTEM => true]);
+
+ $token->expects($this->never())
+ ->method('setName');
+
+ $token->expects($this->never())
+ ->method('setScope');
+
+ $this->tokenProvider->expects($this->once())
+ ->method('updateToken')
+ ->with($this->equalTo($token));
+
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password'));
+ }
+
+ public function testUpdateExpired(): void {
+ $tokenId = 42;
+ $token = $this->createMock(PublicKeyToken::class);
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn($this->uid);
+
+ $this->tokenProvider->expects($this->once())
+ ->method('getTokenById')
+ ->with($this->equalTo($tokenId))
+ ->willThrowException(new ExpiredTokenException($token));
+
+ $this->tokenProvider->expects($this->once())
+ ->method('updateToken')
+ ->with($this->equalTo($token));
+
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password'));
+ }
+
+ public function testUpdateTokenWrongUser(): void {
+ $tokenId = 42;
+ $token = $this->createMock(PublicKeyToken::class);
+
+ $this->mockGetTokenById($tokenId, $token);
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn('foobar');
+
+ $token->expects($this->never())
+ ->method('setScope');
+ $this->tokenProvider->expects($this->never())
+ ->method('updateToken');
+
+ $response = $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password');
+ $this->assertSame([], $response->getData());
+ $this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
+ }
+
+ public function testUpdateTokenNonExisting(): void {
+ $this->tokenProvider->expects($this->once())
+ ->method('getTokenById')
+ ->with($this->equalTo(42))
+ ->willThrowException(new InvalidTokenException('Token does not exist'));
+
+ $this->tokenProvider->expects($this->never())
+ ->method('updateToken');
+
+ $response = $this->controller->update(42, [IToken::SCOPE_FILESYSTEM => true], 'App password');
+ $this->assertSame([], $response->getData());
+ $this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
+ }
+
+ private function mockActivityManager(): void {
+ $this->activityManager->expects($this->once())
+ ->method('generateEvent')
+ ->willReturn($this->createMock(IEvent::class));
+ $this->activityManager->expects($this->once())
+ ->method('publish');
+ }
+
+ /**
+ * @param int $tokenId
+ * @param $token
+ */
+ private function mockGetTokenById(int $tokenId, $token): void {
+ $this->tokenProvider->expects($this->once())
+ ->method('getTokenById')
+ ->with($this->equalTo($tokenId))
+ ->willReturn($token);
+ }
+
+ public function testRemoteWipeNotSuccessful(): void {
+ $token = $this->createMock(IToken::class);
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn($this->uid);
+ $this->mockGetTokenById(123, $token);
+
+ $this->remoteWipe->expects($this->once())
+ ->method('markTokenForWipe')
+ ->with($token)
+ ->willReturn(false);
+
+ $response = $this->controller->wipe(123);
+
+ $expected = new JSONResponse([], Http::STATUS_BAD_REQUEST);
+ $this->assertEquals($expected, $response);
+ }
+
+ public function testRemoteWipeWrongUser(): void {
+ $token = $this->createMock(IToken::class);
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn('definetly-not-' . $this->uid);
+ $this->mockGetTokenById(123, $token);
+
+ $this->remoteWipe->expects($this->never())
+ ->method('markTokenForWipe');
+
+ $response = $this->controller->wipe(123);
+
+ $expected = new JSONResponse([], Http::STATUS_NOT_FOUND);
+ $this->assertEquals($expected, $response);
+ }
+
+ public function testRemoteWipeSuccessful(): void {
+ $token = $this->createMock(IWipeableToken::class);
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn($this->uid);
+ $this->mockGetTokenById(123, $token);
+
+ $this->remoteWipe->expects($this->once())
+ ->method('markTokenForWipe')
+ ->with($token)
+ ->willReturn(true);
+
+ $response = $this->controller->wipe(123);
+
+ $expected = new JSONResponse([]);
+ $this->assertEquals($expected, $response);
+ }
+}
diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php
new file mode 100644
index 00000000000..a8e89260573
--- /dev/null
+++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php
@@ -0,0 +1,581 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCA\Settings\Tests\Controller;
+
+use OC\IntegrityCheck\Checker;
+use OCA\Settings\Controller\CheckSetupController;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataDisplayResponse;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Http\RedirectResponse;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\ISetupCheckManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+/**
+ * Class CheckSetupControllerTest
+ *
+ * @backupStaticAttributes
+ * @package Tests\Settings\Controller
+ */
+class CheckSetupControllerTest extends TestCase {
+ private IRequest&MockObject $request;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IL10N&MockObject $l10n;
+ private LoggerInterface&MockObject $logger;
+ private Checker&MockObject $checker;
+ private ISetupCheckManager&MockObject $setupCheckManager;
+ private CheckSetupController $checkSetupController;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ $this->checker = $this->createMock(Checker::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->setupCheckManager = $this->createMock(ISetupCheckManager::class);
+ $this->checkSetupController = new CheckSetupController(
+ 'settings',
+ $this->request,
+ $this->config,
+ $this->urlGenerator,
+ $this->l10n,
+ $this->checker,
+ $this->logger,
+ $this->setupCheckManager,
+ );
+ }
+
+ public function testCheck(): void {
+ $this->config->expects($this->any())
+ ->method('getAppValue')
+ ->willReturnMap([
+ ['files_external', 'user_certificate_scan', '', '["a", "b"]'],
+ ['dav', 'needs_system_address_book_sync', 'no', 'no'],
+ ]);
+ $this->config->expects($this->any())
+ ->method('getSystemValue')
+ ->willReturnMap([
+ ['connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'], ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']],
+ ['memcache.local', null, 'SomeProvider'],
+ ['has_internet_connection', true, true],
+ ['appstoreenabled', true, false],
+ ]);
+
+ $this->request->expects($this->never())
+ ->method('getHeader');
+
+ $this->urlGenerator->method('linkToDocs')
+ ->willReturnCallback(function (string $key): string {
+ if ($key === 'admin-performance') {
+ return 'http://docs.example.org/server/go.php?to=admin-performance';
+ }
+ if ($key === 'admin-security') {
+ return 'https://docs.example.org/server/8.1/admin_manual/configuration_server/hardening.html';
+ }
+ if ($key === 'admin-reverse-proxy') {
+ return 'reverse-proxy-doc-link';
+ }
+ if ($key === 'admin-code-integrity') {
+ return 'http://docs.example.org/server/go.php?to=admin-code-integrity';
+ }
+ if ($key === 'admin-db-conversion') {
+ return 'http://docs.example.org/server/go.php?to=admin-db-conversion';
+ }
+ return '';
+ });
+
+ $this->urlGenerator->method('getAbsoluteURL')
+ ->willReturnCallback(function (string $url): string {
+ if ($url === 'index.php/settings/admin') {
+ return 'https://server/index.php/settings/admin';
+ }
+ if ($url === 'index.php') {
+ return 'https://server/index.php';
+ }
+ return '';
+ });
+
+ $expected = new DataResponse(
+ [
+ 'generic' => [],
+ ]
+ );
+ $this->assertEquals($expected, $this->checkSetupController->check());
+ }
+
+ public function testRescanFailedIntegrityCheck(): void {
+ $this->checker
+ ->expects($this->once())
+ ->method('runInstanceVerification');
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('linkToRoute')
+ ->with('settings.AdminSettings.index')
+ ->willReturn('/admin');
+
+ $expected = new RedirectResponse('/admin');
+ $this->assertEquals($expected, $this->checkSetupController->rescanFailedIntegrityCheck());
+ }
+
+ public function testGetFailedIntegrityCheckDisabled(): void {
+ $this->checker
+ ->expects($this->once())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(false);
+
+ $expected = new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
+ $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
+ }
+
+
+ public function testGetFailedIntegrityCheckFilesWithNoErrorsFound(): void {
+ $this->checker
+ ->expects($this->once())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker
+ ->expects($this->once())
+ ->method('getResults')
+ ->willReturn([]);
+
+ $expected = new DataDisplayResponse(
+ 'No errors have been found.',
+ Http::STATUS_OK,
+ [
+ 'Content-Type' => 'text/plain',
+ ]
+ );
+ $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
+ }
+
+ public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound(): void {
+ $this->checker
+ ->expects($this->once())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker
+ ->expects($this->once())
+ ->method('getResults')
+ ->willReturn([ 'core' => [ 'EXTRA_FILE' => ['/testfile' => []], 'INVALID_HASH' => [ '/.idea/workspace.xml' => [ 'expected' => 'f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216', 'current' => 'ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094', ], '/lib/private/integritycheck/checker.php' => [ 'expected' => 'c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea', 'current' => '88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585', ], '/settings/controller/checksetupcontroller.php' => [ 'expected' => '3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4', 'current' => '09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a', ], ], ], 'bookmarks' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'dav' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'encryption' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'federation' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_antivirus' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_drop' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_pdfviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_sharing' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_trashbin' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_versions' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_videoviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'firstrunwizard' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'gitsmart' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'logreader' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature could not get verified.', ], ], 'password_policy' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'provisioning_api' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'sketch' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'threatblock' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'two_factor_auth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_ldap' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_shibboleth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], ]);
+
+ $expected = new DataDisplayResponse(
+ 'Technical information
+=====================
+The following list covers which files have failed the integrity check. Please read
+the previous linked documentation to learn more about the errors and how to fix
+them.
+
+Results
+=======
+- core
+ - EXTRA_FILE
+ - /testfile
+ - INVALID_HASH
+ - /.idea/workspace.xml
+ - /lib/private/integritycheck/checker.php
+ - /settings/controller/checksetupcontroller.php
+- bookmarks
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- dav
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- encryption
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- external
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- federation
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- files
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- files_antivirus
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- files_drop
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- files_external
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- files_pdfviewer
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- files_sharing
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- files_trashbin
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- files_versions
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- files_videoviewer
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- firstrunwizard
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- gitsmart
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- logreader
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature could not get verified.
+- password_policy
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- provisioning_api
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- sketch
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- threatblock
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- two_factor_auth
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- user_ldap
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+- user_shibboleth
+ - EXCEPTION
+ - OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ - Signature data not found.
+
+Raw output
+==========
+Array
+(
+ [core] => Array
+ (
+ [EXTRA_FILE] => Array
+ (
+ [/testfile] => Array
+ (
+ )
+
+ )
+
+ [INVALID_HASH] => Array
+ (
+ [/.idea/workspace.xml] => Array
+ (
+ [expected] => f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216
+ [current] => ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094
+ )
+
+ [/lib/private/integritycheck/checker.php] => Array
+ (
+ [expected] => c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea
+ [current] => 88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585
+ )
+
+ [/settings/controller/checksetupcontroller.php] => Array
+ (
+ [expected] => 3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4
+ [current] => 09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a
+ )
+
+ )
+
+ )
+
+ [bookmarks] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [dav] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [encryption] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [external] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [federation] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [files] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [files_antivirus] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [files_drop] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [files_external] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [files_pdfviewer] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [files_sharing] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [files_trashbin] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [files_versions] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [files_videoviewer] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [firstrunwizard] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [gitsmart] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [logreader] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature could not get verified.
+ )
+
+ )
+
+ [password_policy] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [provisioning_api] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [sketch] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [threatblock] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [two_factor_auth] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [user_ldap] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+ [user_shibboleth] => Array
+ (
+ [EXCEPTION] => Array
+ (
+ [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
+ [message] => Signature data not found.
+ )
+
+ )
+
+)
+',
+ Http::STATUS_OK,
+ [
+ 'Content-Type' => 'text/plain',
+ ]
+ );
+ $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
+ }
+}
diff --git a/apps/settings/tests/Controller/DelegationControllerTest.php b/apps/settings/tests/Controller/DelegationControllerTest.php
new file mode 100644
index 00000000000..c4cbe67466b
--- /dev/null
+++ b/apps/settings/tests/Controller/DelegationControllerTest.php
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Controller\Admin;
+
+use OC\Settings\AuthorizedGroup;
+use OCA\Settings\Controller\AuthorizedGroupController;
+use OCA\Settings\Service\AuthorizedGroupService;
+use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class DelegationControllerTest extends TestCase {
+ private AuthorizedGroupService&MockObject $service;
+ private IRequest&MockObject $request;
+ private AuthorizedGroupController $controller;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->request = $this->createMock(IRequest::class);
+ $this->service = $this->createMock(AuthorizedGroupService::class);
+ $this->controller = new AuthorizedGroupController(
+ 'settings', $this->request, $this->service
+ );
+ }
+
+ public function testSaveSettings(): void {
+ $setting = 'MySecretSetting';
+ $oldGroups = [];
+ $oldGroups[] = AuthorizedGroup::fromParams(['groupId' => 'hello', 'class' => $setting]);
+ $goodbye = AuthorizedGroup::fromParams(['groupId' => 'goodbye', 'class' => $setting, 'id' => 42]);
+ $oldGroups[] = $goodbye;
+ $this->service->expects($this->once())
+ ->method('findExistingGroupsForClass')
+ ->with('MySecretSetting')
+ ->willReturn($oldGroups);
+
+ $this->service->expects($this->once())
+ ->method('delete')
+ ->with(42);
+
+ $this->service->expects($this->once())
+ ->method('create')
+ ->with('world', 'MySecretSetting')
+ ->willReturn(AuthorizedGroup::fromParams(['groupId' => 'world', 'class' => $setting]));
+
+ $result = $this->controller->saveSettings([['gid' => 'hello'], ['gid' => 'world']], 'MySecretSetting');
+
+ $this->assertEquals(['valid' => true], $result->getData());
+ }
+}
diff --git a/apps/settings/tests/Controller/MailSettingsControllerTest.php b/apps/settings/tests/Controller/MailSettingsControllerTest.php
new file mode 100644
index 00000000000..1bc05ca4718
--- /dev/null
+++ b/apps/settings/tests/Controller/MailSettingsControllerTest.php
@@ -0,0 +1,167 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Controller;
+
+use OC\Mail\Message;
+use OC\User\User;
+use OCA\Settings\Controller\MailSettingsController;
+use OCP\AppFramework\Http;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCP\IURLGenerator;
+use OCP\IUserSession;
+use OCP\Mail\IEMailTemplate;
+use OCP\Mail\IMailer;
+use PHPUnit\Framework\MockObject\MockObject;
+
+/**
+ * @package Tests\Settings\Controller
+ */
+class MailSettingsControllerTest extends \Test\TestCase {
+ private IConfig&MockObject $config;
+ private IUserSession&MockObject $userSession;
+ private IMailer&MockObject $mailer;
+ private IL10N&MockObject $l;
+ private IURLGenerator&MockObject $urlGenerator;
+ private MailSettingsController $mailController;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l = $this->createMock(IL10N::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->mailer = $this->createMock(IMailer::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ /** @var IRequest&MockObject $request */
+ $request = $this->createMock(IRequest::class);
+ $this->mailController = new MailSettingsController(
+ 'settings',
+ $request,
+ $this->l,
+ $this->config,
+ $this->userSession,
+ $this->urlGenerator,
+ $this->mailer,
+ );
+ }
+
+ public function testSetMailSettings(): void {
+ $calls = [
+ [[
+ 'mail_domain' => 'nextcloud.com',
+ 'mail_from_address' => 'demo@nextcloud.com',
+ 'mail_smtpmode' => 'smtp',
+ 'mail_smtpsecure' => 'ssl',
+ 'mail_smtphost' => 'mx.nextcloud.org',
+ 'mail_smtpauth' => 1,
+ 'mail_smtpport' => '25',
+ 'mail_sendmailmode' => 'smtp',
+ ]],
+ [[
+ 'mail_domain' => 'nextcloud.com',
+ 'mail_from_address' => 'demo@nextcloud.com',
+ 'mail_smtpmode' => 'smtp',
+ 'mail_smtpsecure' => 'ssl',
+ 'mail_smtphost' => 'mx.nextcloud.org',
+ 'mail_smtpauth' => null,
+ 'mail_smtpport' => '25',
+ 'mail_smtpname' => null,
+ 'mail_smtppassword' => null,
+ 'mail_sendmailmode' => 'smtp',
+ ]],
+ ];
+ $this->config->expects($this->exactly(2))
+ ->method('setSystemValues')
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
+
+ // With authentication
+ $response = $this->mailController->setMailSettings(
+ 'nextcloud.com',
+ 'demo@nextcloud.com',
+ 'smtp',
+ 'ssl',
+ 'mx.nextcloud.org',
+ '1',
+ '25',
+ 'smtp'
+ );
+ $this->assertSame(Http::STATUS_OK, $response->getStatus());
+
+ // Without authentication (testing the deletion of the stored password)
+ $response = $this->mailController->setMailSettings(
+ 'nextcloud.com',
+ 'demo@nextcloud.com',
+ 'smtp',
+ 'ssl',
+ 'mx.nextcloud.org',
+ '0',
+ '25',
+ 'smtp'
+ );
+ $this->assertSame(Http::STATUS_OK, $response->getStatus());
+ }
+
+ public function testStoreCredentials(): void {
+ $this->config
+ ->expects($this->once())
+ ->method('setSystemValues')
+ ->with([
+ 'mail_smtpname' => 'UsernameToStore',
+ 'mail_smtppassword' => 'PasswordToStore',
+ ]);
+
+ $response = $this->mailController->storeCredentials('UsernameToStore', 'PasswordToStore');
+ $this->assertSame(Http::STATUS_OK, $response->getStatus());
+ }
+
+ public function testSendTestMail(): void {
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getUID')
+ ->willReturn('Werner');
+ $user->expects($this->any())
+ ->method('getDisplayName')
+ ->willReturn('Werner Brösel');
+
+ $this->l->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($text, $parameters = []) {
+ return vsprintf($text, $parameters);
+ });
+ $this->userSession
+ ->expects($this->any())
+ ->method('getUser')
+ ->willReturn($user);
+
+ // Ensure that it fails when no mail address has been specified
+ $response = $this->mailController->sendTestMail();
+ $this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());
+ $this->assertSame('You need to set your account email before being able to send test emails. Go to for that.', $response->getData());
+
+ // If no exception is thrown it should work
+ $this->config
+ ->expects($this->any())
+ ->method('getUserValue')
+ ->willReturn('mail@example.invalid');
+ $this->mailer->expects($this->once())
+ ->method('createMessage')
+ ->willReturn($this->createMock(Message::class));
+ $emailTemplate = $this->createMock(IEMailTemplate::class);
+ $this->mailer
+ ->expects($this->once())
+ ->method('createEMailTemplate')
+ ->willReturn($emailTemplate);
+ $response = $this->mailController->sendTestMail();
+ $this->assertSame(Http::STATUS_OK, $response->getStatus());
+ }
+}
diff --git a/apps/settings/tests/Controller/TwoFactorSettingsControllerTest.php b/apps/settings/tests/Controller/TwoFactorSettingsControllerTest.php
new file mode 100644
index 00000000000..9f8d53d4f9f
--- /dev/null
+++ b/apps/settings/tests/Controller/TwoFactorSettingsControllerTest.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Controller;
+
+use OC\Authentication\TwoFactorAuth\EnforcementState;
+use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
+use OCA\Settings\Controller\TwoFactorSettingsController;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class TwoFactorSettingsControllerTest extends TestCase {
+ private IRequest&MockObject $request;
+ private MandatoryTwoFactor&MockObject $mandatoryTwoFactor;
+ private TwoFactorSettingsController $controller;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
+
+ $this->controller = new TwoFactorSettingsController(
+ 'settings',
+ $this->request,
+ $this->mandatoryTwoFactor
+ );
+ }
+
+ public function testIndex(): void {
+ $state = new EnforcementState(true);
+ $this->mandatoryTwoFactor->expects($this->once())
+ ->method('getState')
+ ->willReturn($state);
+ $expected = new JSONResponse($state);
+
+ $resp = $this->controller->index();
+
+ $this->assertEquals($expected, $resp);
+ }
+
+ public function testUpdate(): void {
+ $state = new EnforcementState(true);
+ $this->mandatoryTwoFactor->expects($this->once())
+ ->method('setState')
+ ->with($this->equalTo(new EnforcementState(true)));
+ $this->mandatoryTwoFactor->expects($this->once())
+ ->method('getState')
+ ->willReturn($state);
+ $expected = new JSONResponse($state);
+
+ $resp = $this->controller->update(true);
+
+ $this->assertEquals($expected, $resp);
+ }
+}
diff --git a/apps/settings/tests/Controller/UsersControllerTest.php b/apps/settings/tests/Controller/UsersControllerTest.php
new file mode 100644
index 00000000000..1012557bfc4
--- /dev/null
+++ b/apps/settings/tests/Controller/UsersControllerTest.php
@@ -0,0 +1,996 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2014-2015 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Controller;
+
+use OC\Accounts\AccountManager;
+use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
+use OC\ForbiddenException;
+use OC\Group\Manager;
+use OC\KnownUser\KnownUserService;
+use OC\User\Manager as UserManager;
+use OCA\Settings\Controller\UsersController;
+use OCP\Accounts\IAccount;
+use OCP\Accounts\IAccountManager;
+use OCP\Accounts\IAccountProperty;
+use OCP\Accounts\PropertyDoesNotExistException;
+use OCP\App\IAppManager;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Services\IInitialState;
+use OCP\BackgroundJob\IJobList;
+use OCP\Encryption\IEncryptionModule;
+use OCP\Encryption\IManager;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IConfig;
+use OCP\IGroupManager;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCP\IUser;
+use OCP\IUserSession;
+use OCP\L10N\IFactory;
+use OCP\Mail\IMailer;
+use PHPUnit\Framework\MockObject\MockObject;
+
+/**
+ * @group DB
+ *
+ * @package Tests\Settings\Controller
+ */
+class UsersControllerTest extends \Test\TestCase {
+ private IGroupManager&MockObject $groupManager;
+ private UserManager&MockObject $userManager;
+ private IUserSession&MockObject $userSession;
+ private IConfig&MockObject $config;
+ private IMailer&MockObject $mailer;
+ private IFactory&MockObject $l10nFactory;
+ private IAppManager&MockObject $appManager;
+ private IL10N&MockObject $l;
+ private AccountManager&MockObject $accountManager;
+ private IJobList&MockObject $jobList;
+ private \OC\Security\IdentityProof\Manager&MockObject $securityManager;
+ private IManager&MockObject $encryptionManager;
+ private KnownUserService&MockObject $knownUserService;
+ private IEncryptionModule&MockObject $encryptionModule;
+ private IEventDispatcher&MockObject $dispatcher;
+ private IInitialState&MockObject $initialState;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->userManager = $this->createMock(UserManager::class);
+ $this->groupManager = $this->createMock(Manager::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->l = $this->createMock(IL10N::class);
+ $this->mailer = $this->createMock(IMailer::class);
+ $this->l10nFactory = $this->createMock(IFactory::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->accountManager = $this->createMock(AccountManager::class);
+ $this->securityManager = $this->createMock(\OC\Security\IdentityProof\Manager::class);
+ $this->jobList = $this->createMock(IJobList::class);
+ $this->encryptionManager = $this->createMock(IManager::class);
+ $this->knownUserService = $this->createMock(KnownUserService::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
+ $this->initialState = $this->createMock(IInitialState::class);
+
+ $this->l->method('t')
+ ->willReturnCallback(function ($text, $parameters = []) {
+ return vsprintf($text, $parameters);
+ });
+
+ $this->encryptionModule = $this->createMock(IEncryptionModule::class);
+ $this->encryptionManager->expects($this->any())->method('getEncryptionModules')
+ ->willReturn(['encryptionModule' => ['callback' => function () {
+ return $this->encryptionModule;
+ }]]);
+ }
+
+ /**
+ * @param bool $isAdmin
+ * @return UsersController|MockObject
+ */
+ protected function getController(bool $isAdmin = false, array $mockedMethods = []) {
+ $this->groupManager->expects($this->any())
+ ->method('isAdmin')
+ ->willReturn($isAdmin);
+
+ if (empty($mockedMethods)) {
+ return new UsersController(
+ 'settings',
+ $this->createMock(IRequest::class),
+ $this->userManager,
+ $this->groupManager,
+ $this->userSession,
+ $this->config,
+ $this->l,
+ $this->mailer,
+ $this->l10nFactory,
+ $this->appManager,
+ $this->accountManager,
+ $this->securityManager,
+ $this->jobList,
+ $this->encryptionManager,
+ $this->knownUserService,
+ $this->dispatcher,
+ $this->initialState,
+ );
+ } else {
+ return $this->getMockBuilder(UsersController::class)
+ ->setConstructorArgs(
+ [
+ 'settings',
+ $this->createMock(IRequest::class),
+ $this->userManager,
+ $this->groupManager,
+ $this->userSession,
+ $this->config,
+ $this->l,
+ $this->mailer,
+ $this->l10nFactory,
+ $this->appManager,
+ $this->accountManager,
+ $this->securityManager,
+ $this->jobList,
+ $this->encryptionManager,
+ $this->knownUserService,
+ $this->dispatcher,
+ $this->initialState,
+ ]
+ )
+ ->onlyMethods($mockedMethods)
+ ->getMock();
+ }
+ }
+
+ protected function buildPropertyMock(string $name, string $value, string $scope, string $verified = IAccountManager::VERIFIED): MockObject {
+ $property = $this->createMock(IAccountProperty::class);
+ $property->expects($this->any())
+ ->method('getName')
+ ->willReturn($name);
+ $property->expects($this->any())
+ ->method('getValue')
+ ->willReturn($value);
+ $property->expects($this->any())
+ ->method('getScope')
+ ->willReturn($scope);
+ $property->expects($this->any())
+ ->method('getVerified')
+ ->willReturn($verified);
+
+ return $property;
+ }
+
+ protected function getDefaultAccountMock(): MockObject {
+ $propertyMocks = [
+ IAccountManager::PROPERTY_DISPLAYNAME => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_DISPLAYNAME,
+ 'Default display name',
+ IAccountManager::SCOPE_FEDERATED,
+ ),
+ IAccountManager::PROPERTY_ADDRESS => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_ADDRESS,
+ 'Default address',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ IAccountManager::PROPERTY_WEBSITE => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_WEBSITE,
+ 'Default website',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ IAccountManager::PROPERTY_EMAIL => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_EMAIL,
+ 'Default email',
+ IAccountManager::SCOPE_FEDERATED,
+ ),
+ IAccountManager::PROPERTY_AVATAR => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_AVATAR,
+ '',
+ IAccountManager::SCOPE_FEDERATED,
+ ),
+ IAccountManager::PROPERTY_PHONE => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_PHONE,
+ 'Default phone',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ IAccountManager::PROPERTY_TWITTER => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_TWITTER,
+ 'Default twitter',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ IAccountManager::PROPERTY_BLUESKY => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_BLUESKY,
+ 'Default bluesky',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ IAccountManager::PROPERTY_FEDIVERSE => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_FEDIVERSE,
+ 'Default fediverse',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ IAccountManager::PROPERTY_BIRTHDATE => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_BIRTHDATE,
+ 'Default birthdate',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ IAccountManager::PROPERTY_PRONOUNS => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_PRONOUNS,
+ 'Default pronouns',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ ];
+
+ $account = $this->createMock(IAccount::class);
+ $account->expects($this->any())
+ ->method('getProperty')
+ ->willReturnCallback(function (string $propertyName) use ($propertyMocks) {
+ if (isset($propertyMocks[$propertyName])) {
+ return $propertyMocks[$propertyName];
+ }
+ throw new PropertyDoesNotExistException($propertyName);
+ });
+ $account->expects($this->any())
+ ->method('getProperties')
+ ->willReturn($propertyMocks);
+
+ return $account;
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSetUserSettings')]
+ public function testSetUserSettings(string $email, bool $validEmail, int $expectedStatus): void {
+ $controller = $this->getController(false, ['saveUserSettings']);
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')->willReturn('johndoe');
+
+ $this->userSession->method('getUser')->willReturn($user);
+
+ if (!empty($email) && $validEmail) {
+ $this->mailer->expects($this->once())->method('validateMailAddress')
+ ->willReturn($validEmail);
+ }
+
+ $saveData = (!empty($email) && $validEmail) || empty($email);
+
+ if ($saveData) {
+ $this->accountManager->expects($this->once())
+ ->method('getAccount')
+ ->with($user)
+ ->willReturn($this->getDefaultAccountMock());
+
+ $controller->expects($this->once())
+ ->method('saveUserSettings');
+ } else {
+ $controller->expects($this->never())->method('saveUserSettings');
+ }
+
+ $result = $controller->setUserSettings(
+ AccountManager::SCOPE_FEDERATED,
+ 'displayName',
+ AccountManager::SCOPE_FEDERATED,
+ '47658468',
+ AccountManager::SCOPE_FEDERATED,
+ $email,
+ AccountManager::SCOPE_FEDERATED,
+ 'nextcloud.com',
+ AccountManager::SCOPE_FEDERATED,
+ 'street and city',
+ AccountManager::SCOPE_FEDERATED,
+ '@nextclouders',
+ AccountManager::SCOPE_FEDERATED,
+ '@nextclouders',
+ AccountManager::SCOPE_FEDERATED,
+ '2020-01-01',
+ AccountManager::SCOPE_FEDERATED,
+ 'they/them',
+ AccountManager::SCOPE_FEDERATED,
+ );
+
+ $this->assertSame($expectedStatus, $result->getStatus());
+ }
+
+ public static function dataTestSetUserSettings(): array {
+ return [
+ ['', true, Http::STATUS_OK],
+ ['', false, Http::STATUS_OK],
+ ['example.com', false, Http::STATUS_UNPROCESSABLE_ENTITY],
+ ['john@example.com', true, Http::STATUS_OK],
+ ];
+ }
+
+ public function testSetUserSettingsWhenUserDisplayNameChangeNotAllowed(): void {
+ $controller = $this->getController(false, ['saveUserSettings']);
+
+ $avatarScope = IAccountManager::SCOPE_PUBLISHED;
+ $displayName = 'Display name';
+ $displayNameScope = IAccountManager::SCOPE_PUBLISHED;
+ $phone = '47658468';
+ $phoneScope = IAccountManager::SCOPE_PUBLISHED;
+ $email = 'john@example.com';
+ $emailScope = IAccountManager::SCOPE_PUBLISHED;
+ $website = 'nextcloud.com';
+ $websiteScope = IAccountManager::SCOPE_PUBLISHED;
+ $address = 'street and city';
+ $addressScope = IAccountManager::SCOPE_PUBLISHED;
+ $twitter = '@nextclouders';
+ $twitterScope = IAccountManager::SCOPE_PUBLISHED;
+ $fediverse = '@nextclouders@floss.social';
+ $fediverseScope = IAccountManager::SCOPE_PUBLISHED;
+ $birtdate = '2020-01-01';
+ $birthdateScope = IAccountManager::SCOPE_PUBLISHED;
+ $pronouns = 'she/her';
+ $pronounsScope = IAccountManager::SCOPE_PUBLISHED;
+
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')->willReturn('johndoe');
+
+ $this->userSession->method('getUser')->willReturn($user);
+
+ /** @var MockObject|IAccount $userAccount */
+ $userAccount = $this->getDefaultAccountMock();
+ $this->accountManager->expects($this->once())
+ ->method('getAccount')
+ ->with($user)
+ ->willReturn($userAccount);
+
+ /** @var MockObject|IAccountProperty $avatarProperty */
+ $avatarProperty = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR);
+ $avatarProperty->expects($this->atLeastOnce())
+ ->method('setScope')
+ ->with($avatarScope)
+ ->willReturnSelf();
+
+ /** @var MockObject|IAccountProperty $avatarProperty */
+ $avatarProperty = $userAccount->getProperty(IAccountManager::PROPERTY_ADDRESS);
+ $avatarProperty->expects($this->atLeastOnce())
+ ->method('setScope')
+ ->with($addressScope)
+ ->willReturnSelf();
+ $avatarProperty->expects($this->atLeastOnce())
+ ->method('setValue')
+ ->with($address)
+ ->willReturnSelf();
+
+ /** @var MockObject|IAccountProperty $emailProperty */
+ $emailProperty = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL);
+ $emailProperty->expects($this->never())
+ ->method('setValue');
+ $emailProperty->expects($this->never())
+ ->method('setScope');
+
+ /** @var MockObject|IAccountProperty $emailProperty */
+ $emailProperty = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME);
+ $emailProperty->expects($this->never())
+ ->method('setValue');
+ $emailProperty->expects($this->never())
+ ->method('setScope');
+
+ $this->config->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('allow_user_to_change_display_name')
+ ->willReturn(false);
+
+ $this->appManager->expects($this->any())
+ ->method('isEnabledForUser')
+ ->with('federatedfilesharing')
+ ->willReturn(true);
+
+ $this->mailer->expects($this->once())->method('validateMailAddress')
+ ->willReturn(true);
+
+ $controller->expects($this->once())
+ ->method('saveUserSettings');
+
+ $controller->setUserSettings(
+ $avatarScope,
+ $displayName,
+ $displayNameScope,
+ $phone,
+ $phoneScope,
+ $email,
+ $emailScope,
+ $website,
+ $websiteScope,
+ $address,
+ $addressScope,
+ $twitter,
+ $twitterScope,
+ $fediverse,
+ $fediverseScope,
+ $birtdate,
+ $birthdateScope,
+ $pronouns,
+ $pronounsScope,
+ );
+ }
+
+ public function testSetUserSettingsWhenFederatedFilesharingNotEnabled(): void {
+ $controller = $this->getController(false, ['saveUserSettings']);
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')->willReturn('johndoe');
+
+ $this->userSession->method('getUser')->willReturn($user);
+
+ $defaultProperties = []; //$this->getDefaultAccountMock();
+
+ $userAccount = $this->getDefaultAccountMock();
+ $this->accountManager->expects($this->once())
+ ->method('getAccount')
+ ->with($user)
+ ->willReturn($userAccount);
+
+ $this->appManager->expects($this->any())
+ ->method('isEnabledForUser')
+ ->with('federatedfilesharing')
+ ->willReturn(false);
+
+ $avatarScope = IAccountManager::SCOPE_PUBLISHED;
+ $displayName = 'Display name';
+ $displayNameScope = IAccountManager::SCOPE_PUBLISHED;
+ $phone = '47658468';
+ $phoneScope = IAccountManager::SCOPE_PUBLISHED;
+ $email = 'john@example.com';
+ $emailScope = IAccountManager::SCOPE_PUBLISHED;
+ $website = 'nextcloud.com';
+ $websiteScope = IAccountManager::SCOPE_PUBLISHED;
+ $address = 'street and city';
+ $addressScope = IAccountManager::SCOPE_PUBLISHED;
+ $twitter = '@nextclouders';
+ $twitterScope = IAccountManager::SCOPE_PUBLISHED;
+ $bluesky = 'nextclouders.net';
+ $blueskyScope = IAccountManager::SCOPE_PUBLISHED;
+ $fediverse = '@nextclouders@floss.social';
+ $fediverseScope = IAccountManager::SCOPE_PUBLISHED;
+ $birthdate = '2020-01-01';
+ $birthdateScope = IAccountManager::SCOPE_PUBLISHED;
+ $pronouns = 'she/her';
+ $pronounsScope = IAccountManager::SCOPE_PUBLISHED;
+
+ // All settings are changed (in the past phone, website, address and
+ // twitter were not changed).
+ $expectedProperties = $defaultProperties;
+ $expectedProperties[IAccountManager::PROPERTY_AVATAR]['scope'] = $avatarScope;
+ $expectedProperties[IAccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName;
+ $expectedProperties[IAccountManager::PROPERTY_DISPLAYNAME]['scope'] = $displayNameScope;
+ $expectedProperties[IAccountManager::PROPERTY_EMAIL]['value'] = $email;
+ $expectedProperties[IAccountManager::PROPERTY_EMAIL]['scope'] = $emailScope;
+ $expectedProperties[IAccountManager::PROPERTY_PHONE]['value'] = $phone;
+ $expectedProperties[IAccountManager::PROPERTY_PHONE]['scope'] = $phoneScope;
+ $expectedProperties[IAccountManager::PROPERTY_WEBSITE]['value'] = $website;
+ $expectedProperties[IAccountManager::PROPERTY_WEBSITE]['scope'] = $websiteScope;
+ $expectedProperties[IAccountManager::PROPERTY_ADDRESS]['value'] = $address;
+ $expectedProperties[IAccountManager::PROPERTY_ADDRESS]['scope'] = $addressScope;
+ $expectedProperties[IAccountManager::PROPERTY_TWITTER]['value'] = $twitter;
+ $expectedProperties[IAccountManager::PROPERTY_TWITTER]['scope'] = $twitterScope;
+ $expectedProperties[IAccountManager::PROPERTY_BLUESKY]['value'] = $bluesky;
+ $expectedProperties[IAccountManager::PROPERTY_BLUESKY]['scope'] = $blueskyScope;
+ $expectedProperties[IAccountManager::PROPERTY_FEDIVERSE]['value'] = $fediverse;
+ $expectedProperties[IAccountManager::PROPERTY_FEDIVERSE]['scope'] = $fediverseScope;
+ $expectedProperties[IAccountManager::PROPERTY_BIRTHDATE]['value'] = $birthdate;
+ $expectedProperties[IAccountManager::PROPERTY_BIRTHDATE]['scope'] = $birthdateScope;
+ $expectedProperties[IAccountManager::PROPERTY_PRONOUNS]['value'] = $pronouns;
+ $expectedProperties[IAccountManager::PROPERTY_PRONOUNS]['scope'] = $pronounsScope;
+
+ $this->mailer->expects($this->once())->method('validateMailAddress')
+ ->willReturn(true);
+
+ $controller->expects($this->once())
+ ->method('saveUserSettings')
+ ->with($userAccount);
+
+ $controller->setUserSettings(
+ $avatarScope,
+ $displayName,
+ $displayNameScope,
+ $phone,
+ $phoneScope,
+ $email,
+ $emailScope,
+ $website,
+ $websiteScope,
+ $address,
+ $addressScope,
+ $twitter,
+ $twitterScope,
+ $bluesky,
+ $blueskyScope,
+ $fediverse,
+ $fediverseScope,
+ $birthdate,
+ $birthdateScope,
+ $pronouns,
+ $pronounsScope,
+ );
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSetUserSettingsSubset')]
+ public function testSetUserSettingsSubset(string $property, string $propertyValue): void {
+ $controller = $this->getController(false, ['saveUserSettings']);
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')->willReturn('johndoe');
+
+ $this->userSession->method('getUser')->willReturn($user);
+
+ /** @var IAccount&MockObject $userAccount */
+ $userAccount = $this->getDefaultAccountMock();
+
+ $this->accountManager->expects($this->once())
+ ->method('getAccount')
+ ->with($user)
+ ->willReturn($userAccount);
+
+ $avatarScope = ($property === 'avatarScope') ? $propertyValue : null;
+ $displayName = ($property === 'displayName') ? $propertyValue : null;
+ $displayNameScope = ($property === 'displayNameScope') ? $propertyValue : null;
+ $phone = ($property === 'phone') ? $propertyValue : null;
+ $phoneScope = ($property === 'phoneScope') ? $propertyValue : null;
+ $email = ($property === 'email') ? $propertyValue : null;
+ $emailScope = ($property === 'emailScope') ? $propertyValue : null;
+ $website = ($property === 'website') ? $propertyValue : null;
+ $websiteScope = ($property === 'websiteScope') ? $propertyValue : null;
+ $address = ($property === 'address') ? $propertyValue : null;
+ $addressScope = ($property === 'addressScope') ? $propertyValue : null;
+ $twitter = ($property === 'twitter') ? $propertyValue : null;
+ $twitterScope = ($property === 'twitterScope') ? $propertyValue : null;
+ $bluesky = ($property === 'bluesky') ? $propertyValue : null;
+ $blueskyScope = ($property === 'blueskyScope') ? $propertyValue : null;
+ $fediverse = ($property === 'fediverse') ? $propertyValue : null;
+ $fediverseScope = ($property === 'fediverseScope') ? $propertyValue : null;
+ $birthdate = ($property === 'birthdate') ? $propertyValue : null;
+ $birthdateScope = ($property === 'birthdateScope') ? $propertyValue : null;
+ $pronouns = ($property === 'pronouns') ? $propertyValue : null;
+ $pronounsScope = ($property === 'pronounsScope') ? $propertyValue : null;
+
+ /** @var IAccountProperty[]&MockObject[] $expectedProperties */
+ $expectedProperties = $userAccount->getProperties();
+ $isScope = strrpos($property, 'Scope') === strlen($property) - strlen('5');
+ switch ($property) {
+ case 'avatarScope':
+ $propertyId = IAccountManager::PROPERTY_AVATAR;
+ break;
+ case 'displayName':
+ case 'displayNameScope':
+ $propertyId = IAccountManager::PROPERTY_DISPLAYNAME;
+ break;
+ case 'phone':
+ case 'phoneScope':
+ $propertyId = IAccountManager::PROPERTY_PHONE;
+ break;
+ case 'email':
+ case 'emailScope':
+ $propertyId = IAccountManager::PROPERTY_EMAIL;
+ break;
+ case 'website':
+ case 'websiteScope':
+ $propertyId = IAccountManager::PROPERTY_WEBSITE;
+ break;
+ case 'address':
+ case 'addressScope':
+ $propertyId = IAccountManager::PROPERTY_ADDRESS;
+ break;
+ case 'twitter':
+ case 'twitterScope':
+ $propertyId = IAccountManager::PROPERTY_TWITTER;
+ break;
+ case 'bluesky':
+ case 'blueskyScope':
+ $propertyId = IAccountManager::PROPERTY_BLUESKY;
+ break;
+ case 'fediverse':
+ case 'fediverseScope':
+ $propertyId = IAccountManager::PROPERTY_FEDIVERSE;
+ break;
+ case 'birthdate':
+ case 'birthdateScope':
+ $propertyId = IAccountManager::PROPERTY_BIRTHDATE;
+ break;
+ case 'pronouns':
+ case 'pronounsScope':
+ $propertyId = IAccountManager::PROPERTY_PRONOUNS;
+ break;
+ default:
+ $propertyId = '404';
+ }
+ $expectedProperties[$propertyId]->expects($this->any())
+ ->method($isScope ? 'getScope' : 'getValue')
+ ->willReturn($propertyValue);
+
+ if (!empty($email)) {
+ $this->mailer->expects($this->once())->method('validateMailAddress')
+ ->willReturn(true);
+ }
+
+ $controller->expects($this->once())
+ ->method('saveUserSettings')
+ ->with($userAccount);
+
+ $controller->setUserSettings(
+ $avatarScope,
+ $displayName,
+ $displayNameScope,
+ $phone,
+ $phoneScope,
+ $email,
+ $emailScope,
+ $website,
+ $websiteScope,
+ $address,
+ $addressScope,
+ $twitter,
+ $twitterScope,
+ $bluesky,
+ $blueskyScope,
+ $fediverse,
+ $fediverseScope,
+ $birthdate,
+ $birthdateScope,
+ $pronouns,
+ $pronounsScope,
+ );
+ }
+
+ public static function dataTestSetUserSettingsSubset(): array {
+ return [
+ ['avatarScope', IAccountManager::SCOPE_PUBLISHED],
+ ['displayName', 'Display name'],
+ ['displayNameScope', IAccountManager::SCOPE_PUBLISHED],
+ ['phone', '47658468'],
+ ['phoneScope', IAccountManager::SCOPE_PUBLISHED],
+ ['email', 'john@example.com'],
+ ['emailScope', IAccountManager::SCOPE_PUBLISHED],
+ ['website', 'nextcloud.com'],
+ ['websiteScope', IAccountManager::SCOPE_PUBLISHED],
+ ['address', 'street and city'],
+ ['addressScope', IAccountManager::SCOPE_PUBLISHED],
+ ['twitter', '@nextclouders'],
+ ['twitterScope', IAccountManager::SCOPE_PUBLISHED],
+ ['bluesky', 'nextclouders.net'],
+ ['blueskyScope', IAccountManager::SCOPE_PUBLISHED],
+ ['fediverse', '@nextclouders@floss.social'],
+ ['fediverseScope', IAccountManager::SCOPE_PUBLISHED],
+ ['birthdate', '2020-01-01'],
+ ['birthdateScope', IAccountManager::SCOPE_PUBLISHED],
+ ['pronouns', 'he/him'],
+ ['pronounsScope', IAccountManager::SCOPE_PUBLISHED],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettings')]
+ public function testSaveUserSettings(array $data, ?string $oldEmailAddress, ?string $oldDisplayName): void {
+ $controller = $this->getController();
+ $user = $this->createMock(IUser::class);
+
+ $user->method('getDisplayName')->willReturn($oldDisplayName);
+ $user->method('getSystemEMailAddress')->willReturn($oldEmailAddress);
+ $user->method('canChangeDisplayName')->willReturn(true);
+
+ if (strtolower($data[IAccountManager::PROPERTY_EMAIL]['value']) === strtolower($oldEmailAddress ?? '')) {
+ $user->expects($this->never())->method('setSystemEMailAddress');
+ } else {
+ $user->expects($this->once())->method('setSystemEMailAddress')
+ ->with($data[IAccountManager::PROPERTY_EMAIL]['value']);
+ }
+
+ if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ?? '') {
+ $user->expects($this->never())->method('setDisplayName');
+ } else {
+ $user->expects($this->once())->method('setDisplayName')
+ ->with($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'])
+ ->willReturn(true);
+ }
+
+ $properties = [];
+ foreach ($data as $propertyName => $propertyData) {
+ $properties[$propertyName] = $this->createMock(IAccountProperty::class);
+ $properties[$propertyName]->expects($this->any())
+ ->method('getValue')
+ ->willReturn($propertyData['value']);
+ }
+
+ $account = $this->createMock(IAccount::class);
+ $account->expects($this->any())
+ ->method('getUser')
+ ->willReturn($user);
+ $account->expects($this->any())
+ ->method('getProperty')
+ ->willReturnCallback(function (string $propertyName) use ($properties) {
+ return $properties[$propertyName];
+ });
+
+ $this->accountManager->expects($this->any())
+ ->method('getAccount')
+ ->willReturn($account);
+
+ $this->accountManager->expects($this->once())
+ ->method('updateAccount')
+ ->with($account);
+
+ $this->invokePrivate($controller, 'saveUserSettings', [$account]);
+ }
+
+ public static function dataTestSaveUserSettings(): array {
+ return [
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'john@example.com',
+ 'john doe'
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'johnNew@example.com',
+ 'john New doe'
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'johnNew@example.com',
+ 'john doe'
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'john@example.com',
+ 'john New doe'
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => ''],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ null,
+ 'john New doe'
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'john@example.com',
+ null
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'JOHN@example.com',
+ null
+ ],
+
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettingsException')]
+ public function testSaveUserSettingsException(
+ array $data,
+ string $oldEmailAddress,
+ string $oldDisplayName,
+ bool $setDisplayNameResult,
+ bool $canChangeEmail,
+ ): void {
+ $this->expectException(ForbiddenException::class);
+
+ $controller = $this->getController();
+ $user = $this->createMock(IUser::class);
+
+ $user->method('getDisplayName')->willReturn($oldDisplayName);
+ $user->method('getEMailAddress')->willReturn($oldEmailAddress);
+
+ /** @var MockObject|IAccount $userAccount */
+ $userAccount = $this->createMock(IAccount::class);
+ $userAccount->expects($this->any())
+ ->method('getUser')
+ ->willReturn($user);
+ $propertyMocks = [];
+ foreach ($data as $propertyName => $propertyData) {
+ /** @var MockObject|IAccountProperty $property */
+ $propertyMocks[$propertyName] = $this->buildPropertyMock($propertyName, $propertyData['value'], '');
+ }
+ $userAccount->expects($this->any())
+ ->method('getProperty')
+ ->willReturnCallback(function (string $propertyName) use ($propertyMocks) {
+ return $propertyMocks[$propertyName];
+ });
+
+ if ($data[IAccountManager::PROPERTY_EMAIL]['value'] !== $oldEmailAddress) {
+ $user->method('canChangeDisplayName')
+ ->willReturn($canChangeEmail);
+ }
+
+ if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] !== $oldDisplayName) {
+ $user->method('setDisplayName')
+ ->with($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'])
+ ->willReturn($setDisplayNameResult);
+ }
+
+ $this->invokePrivate($controller, 'saveUserSettings', [$userAccount]);
+ }
+
+
+ public static function dataTestSaveUserSettingsException(): array {
+ return [
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'johnNew@example.com',
+ 'john New doe',
+ true,
+ false
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'johnNew@example.com',
+ 'john New doe',
+ false,
+ true
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'johnNew@example.com',
+ 'john New doe',
+ false,
+ false
+ ],
+
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetVerificationCode')]
+ public function testGetVerificationCode(string $account, string $type, array $dataBefore, array $expectedData, bool $onlyVerificationCode): void {
+ $message = 'Use my Federated Cloud ID to share with me: user@nextcloud.com';
+ $signature = 'theSignature';
+
+ $code = $message . ' ' . $signature;
+ if ($type === IAccountManager::PROPERTY_TWITTER || $type === IAccountManager::PROPERTY_FEDIVERSE) {
+ $code = $message . ' ' . md5($signature);
+ }
+
+ $controller = $this->getController(false, ['signMessage', 'getCurrentTime']);
+
+ $user = $this->createMock(IUser::class);
+
+ $property = $this->buildPropertyMock($type, $dataBefore[$type]['value'], '', IAccountManager::NOT_VERIFIED);
+ $property->expects($this->atLeastOnce())
+ ->method('setVerified')
+ ->with(IAccountManager::VERIFICATION_IN_PROGRESS)
+ ->willReturnSelf();
+ $property->expects($this->atLeastOnce())
+ ->method('setVerificationData')
+ ->with($signature)
+ ->willReturnSelf();
+
+ $userAccount = $this->createMock(IAccount::class);
+ $userAccount->expects($this->any())
+ ->method('getUser')
+ ->willReturn($user);
+ $userAccount->expects($this->any())
+ ->method('getProperty')
+ ->willReturn($property);
+
+ $this->userSession->expects($this->once())->method('getUser')->willReturn($user);
+ $this->accountManager->expects($this->once())->method('getAccount')->with($user)->willReturn($userAccount);
+ $user->expects($this->any())->method('getCloudId')->willReturn('user@nextcloud.com');
+ $user->expects($this->any())->method('getUID')->willReturn('uid');
+ $controller->expects($this->once())->method('signMessage')->with($user, $message)->willReturn($signature);
+ $controller->expects($this->any())->method('getCurrentTime')->willReturn(1234567);
+
+ if ($onlyVerificationCode === false) {
+ $this->accountManager->expects($this->once())->method('updateAccount')->with($userAccount)->willReturnArgument(1);
+ $this->jobList->expects($this->once())->method('add')
+ ->with('OCA\Settings\BackgroundJobs\VerifyUserData',
+ [
+ 'verificationCode' => $code,
+ 'data' => $dataBefore[$type]['value'],
+ 'type' => $type,
+ 'uid' => 'uid',
+ 'try' => 0,
+ 'lastRun' => 1234567
+ ]);
+ }
+
+ $result = $controller->getVerificationCode($account, $onlyVerificationCode);
+
+ $data = $result->getData();
+ $this->assertSame(Http::STATUS_OK, $result->getStatus());
+ $this->assertSame($code, $data['code']);
+ }
+
+ public static function dataTestGetVerificationCode(): array {
+ $accountDataBefore = [
+ IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::NOT_VERIFIED],
+ IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::NOT_VERIFIED, 'signature' => 'theSignature'],
+ ];
+
+ $accountDataAfterWebsite = [
+ IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'],
+ IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::NOT_VERIFIED, 'signature' => 'theSignature'],
+ ];
+
+ $accountDataAfterTwitter = [
+ IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::NOT_VERIFIED],
+ IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'],
+ ];
+
+ return [
+ ['verify-twitter', IAccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, false],
+ ['verify-website', IAccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, false],
+ ['verify-twitter', IAccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, true],
+ ['verify-website', IAccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, true],
+ ];
+ }
+
+ /**
+ * test get verification code in case no valid user was given
+ */
+ public function testGetVerificationCodeInvalidUser(): void {
+ $controller = $this->getController();
+ $this->userSession->expects($this->once())->method('getUser')->willReturn(null);
+ $result = $controller->getVerificationCode('account', false);
+
+ $this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus());
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCanAdminChangeUserPasswords')]
+ public function testCanAdminChangeUserPasswords(
+ bool $encryptionEnabled,
+ bool $encryptionModuleLoaded,
+ bool $masterKeyEnabled,
+ bool $expected,
+ ): void {
+ $controller = $this->getController();
+
+ $this->encryptionManager->expects($this->any())
+ ->method('isEnabled')
+ ->willReturn($encryptionEnabled);
+ $this->encryptionManager->expects($this->any())
+ ->method('getEncryptionModule')
+ ->willReturnCallback(function () use ($encryptionModuleLoaded) {
+ if ($encryptionModuleLoaded) {
+ return $this->encryptionModule;
+ } else {
+ throw new ModuleDoesNotExistsException();
+ }
+ });
+ $this->encryptionModule->expects($this->any())
+ ->method('needDetailedAccessList')
+ ->willReturn(!$masterKeyEnabled);
+
+ $result = $this->invokePrivate($controller, 'canAdminChangeUserPasswords', []);
+ $this->assertSame($expected, $result);
+ }
+
+ public static function dataTestCanAdminChangeUserPasswords(): array {
+ return [
+ // encryptionEnabled, encryptionModuleLoaded, masterKeyEnabled, expectedResult
+ [true, true, true, true],
+ [false, true, true, true],
+ [true, false, true, false],
+ [false, false, true, true],
+ [true, true, false, false],
+ [false, true, false, false],
+ [true, false, false, false],
+ [false, false, false, true],
+ ];
+ }
+}
diff --git a/apps/settings/tests/Mailer/NewUserMailHelperTest.php b/apps/settings/tests/Mailer/NewUserMailHelperTest.php
new file mode 100644
index 00000000000..f352a2b733d
--- /dev/null
+++ b/apps/settings/tests/Mailer/NewUserMailHelperTest.php
@@ -0,0 +1,907 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Mailer;
+
+use OC\Mail\EMailTemplate;
+use OC\Mail\Message;
+use OCA\Settings\Mailer\NewUserMailHelper;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Defaults;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\L10N\IFactory;
+use OCP\Mail\Headers\AutoSubmitted;
+use OCP\Mail\IEMailTemplate;
+use OCP\Mail\IMailer;
+use OCP\Security\ICrypto;
+use OCP\Security\ISecureRandom;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class NewUserMailHelperTest extends TestCase {
+ private Defaults&MockObject $defaults;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IL10N&MockObject $l10n;
+ private IFactory&MockObject $l10nFactory;
+ private IMailer&MockObject $mailer;
+ private ISecureRandom&MockObject $secureRandom;
+ private ITimeFactory&MockObject $timeFactory;
+ private IConfig&MockObject $config;
+ private ICrypto&MockObject $crypto;
+ private NewUserMailHelper $newUserMailHelper;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->defaults = $this->createMock(Defaults::class);
+ $this->defaults->method('getLogo')
+ ->willReturn('myLogo');
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10nFactory = $this->createMock(IFactory::class);
+ $this->mailer = $this->createMock(IMailer::class);
+ $template = new EMailTemplate(
+ $this->defaults,
+ $this->urlGenerator,
+ $this->l10nFactory,
+ null,
+ null,
+ 'test.TestTemplate',
+ []
+ );
+ $this->mailer->method('createEMailTemplate')
+ ->willReturn($template);
+ $this->secureRandom = $this->createMock(ISecureRandom::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->config
+ ->expects($this->any())
+ ->method('getSystemValue')
+ ->willReturnCallback(function ($arg) {
+ switch ($arg) {
+ case 'secret':
+ return 'MyInstanceWideSecret';
+ case 'customclient_desktop':
+ return 'https://nextcloud.com/install/#install-clients';
+ }
+ return '';
+ });
+ $this->crypto = $this->createMock(ICrypto::class);
+ $this->l10n->method('t')
+ ->willReturnCallback(function ($text, $parameters = []) {
+ return vsprintf($text, $parameters);
+ });
+ $this->l10nFactory->method('get')
+ ->willReturnCallback(function ($text, $lang) {
+ return $this->l10n;
+ });
+
+ $this->newUserMailHelper = new NewUserMailHelper(
+ $this->defaults,
+ $this->urlGenerator,
+ $this->l10nFactory,
+ $this->mailer,
+ $this->secureRandom,
+ $this->timeFactory,
+ $this->config,
+ $this->crypto,
+ 'no-reply@nextcloud.com'
+ );
+ }
+
+ public function testGenerateTemplateWithPasswordResetToken(): void {
+ $this->secureRandom
+ ->expects($this->once())
+ ->method('generate')
+ ->with(21, ISecureRandom::CHAR_ALPHANUMERIC)
+ ->willReturn('MySuperLongSecureRandomToken');
+ $this->timeFactory
+ ->expects($this->once())
+ ->method('getTime')
+ ->willReturn(12345);
+ /** @var IUser&MockObject $user */
+ $user = $this->createMock(IUser::class);
+ $user
+ ->expects($this->any())
+ ->method('getEmailAddress')
+ ->willReturn('recipient@example.com');
+ $this->crypto
+ ->expects($this->once())
+ ->method('encrypt')
+ ->with('12345:MySuperLongSecureRandomToken', 'recipient@example.comMyInstanceWideSecret')
+ ->willReturn('TokenCiphertext');
+ $user
+ ->expects($this->any())
+ ->method('getUID')
+ ->willReturn('john');
+ $this->config
+ ->expects($this->once())
+ ->method('setUserValue')
+ ->with('john', 'core', 'lostpassword', 'TokenCiphertext');
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('linkToRouteAbsolute')
+ ->with('core.lost.resetform', ['userId' => 'john', 'token' => 'MySuperLongSecureRandomToken'])
+ ->willReturn('https://example.com/resetPassword/MySuperLongSecureRandomToken');
+ $user
+ ->expects($this->any())
+ ->method('getDisplayName')
+ ->willReturn('john');
+ $this->defaults
+ ->expects($this->any())
+ ->method('getName')
+ ->willReturn('TestCloud');
+ $this->defaults
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultColorPrimary')
+ ->willReturn('#00679e');
+ $this->defaults
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultTextColorPrimary')
+ ->willReturn('#ffffff');
+
+ $expectedHtmlBody = <<<EOF
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width">
+ <title></title>
+ <style type="text/css">@media only screen{html{min-height:100%;background:#fff}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
+</head>
+<body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;margin:0;background:#fff!important;box-sizing:border-box;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
+ <span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
+ </span>
+ <table class="body" style="-webkit-font-smoothing:antialiased;margin:0;background:#fff;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <center data-parsed="" style="min-width:580px;width:100%"><table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table align="center" class="container" style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:150px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <center data-parsed="" style="background-color:#00679e;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
+ <img class="logo float-center" src="" alt="TestCloud" align="center" style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;height:auto">
+ </center>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="40px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table><table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:center;word-wrap:normal">Welcome aboard</h1>
+ </td>
+ </tr>
+ </tbody>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="36px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:36px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table><table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table align="center" class="container" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <p style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center">Welcome to your TestCloud account, you can add, protect, and share your data.</p>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <p style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center">Your Login is: john</p>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table><table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:50px;font-weight:400;hyphens:auto;line-height:50px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table>
+<table align="center" class="row btn-group" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <center data-parsed="" style="min-width:490px;width:100%">
+ <!--[if (gte mso 9)|(IE)]>
+ <table>
+ <tr>
+ <td>
+ <![endif]-->
+ <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;border-radius:8px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:#00679e;background-color:#00679e;color:#fefefe;">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #00679e;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://example.com/resetPassword/MySuperLongSecureRandomToken" style="Margin:0;border:0 solid #00679e;color:#ffffff;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;padding:8px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Set your password</a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ <!--[if (gte mso 9)|(IE)]>
+ </td>
+ <td>
+ <![endif]-->
+ <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;background-color: #ccc;margin:0 0 30px 0;max-height:40px;max-width:300px;padding:1px;border-radius:8px;text-align:center;vertical-align:top;width:auto">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;border-radius: 7px;padding:8px;text-align:left;text-decoration:none">Install Client</a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ <!--[if (gte mso 9)|(IE)]>
+ </td>
+ </tr>
+ </table>
+ <![endif]-->
+ </center>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+</table><table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table>
+<table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <center data-parsed="" style="min-width:580px;width:100%">
+ <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="15px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+ </table>
+ <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">TestCloud<br>This is an automatically sent email, please do not reply.</p>
+ </center>
+ </td>
+ </tr>
+</table> </center>
+ </td>
+ </tr>
+ </table>
+ <!-- prevent Gmail on iOS font size manipulation -->
+ <div style="display:none;white-space:nowrap;font:15px courier;line-height:0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
+ </body>
+</html>
+
+EOF;
+ $expectedTextBody = <<<EOF
+Welcome aboard
+
+Welcome to your TestCloud account, you can add, protect, and share your data.
+
+Your Login is: john
+
+
+Set your password: https://example.com/resetPassword/MySuperLongSecureRandomToken
+Install Client: https://nextcloud.com/install/#install-clients
+
+
+EOF;
+ $expectedTextBody .= "\n-- \n";
+ $expectedTextBody .= <<<EOF
+TestCloud
+This is an automatically sent email, please do not reply.
+EOF;
+
+ $result = $this->newUserMailHelper->generateTemplate($user, true);
+ $this->assertEquals($expectedHtmlBody, $result->renderHtml());
+ $this->assertEquals($expectedTextBody, $result->renderText());
+ $this->assertSame('OC\Mail\EMailTemplate', get_class($result));
+ }
+
+ public function testGenerateTemplateWithoutPasswordResetToken(): void {
+ $this->urlGenerator
+ ->expects($this->any())
+ ->method('getAbsoluteURL')
+ ->willReturnMap([
+ ['/','https://example.com/'],
+ ['myLogo',''],
+ ]);
+
+ /** @var IUser&MockObject $user */
+ $user = $this->createMock(IUser::class);
+ $user
+ ->expects($this->any())
+ ->method('getDisplayName')
+ ->willReturn('John Doe');
+ $user
+ ->expects($this->any())
+ ->method('getUID')
+ ->willReturn('john');
+ $this->defaults
+ ->expects($this->any())
+ ->method('getName')
+ ->willReturn('TestCloud');
+ $this->defaults
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultColorPrimary')
+ ->willReturn('#00679e');
+ $this->defaults
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultTextColorPrimary')
+ ->willReturn('#ffffff');
+
+ $expectedHtmlBody = <<<EOF
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width">
+ <title></title>
+ <style type="text/css">@media only screen{html{min-height:100%;background:#fff}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
+</head>
+<body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;margin:0;background:#fff!important;box-sizing:border-box;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
+ <span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
+ </span>
+ <table class="body" style="-webkit-font-smoothing:antialiased;margin:0;background:#fff;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <center data-parsed="" style="min-width:580px;width:100%"><table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table align="center" class="container" style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:150px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <center data-parsed="" style="background-color:#00679e;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
+ <img class="logo float-center" src="" alt="TestCloud" align="center" style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;height:auto">
+ </center>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="40px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table><table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:center;word-wrap:normal">Welcome aboard John Doe</h1>
+ </td>
+ </tr>
+ </tbody>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="36px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:36px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table><table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table align="center" class="container" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <p style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center">Welcome to your TestCloud account, you can add, protect, and share your data.</p>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <p style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center">Your Login is: john</p>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table><table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:50px;font-weight:400;hyphens:auto;line-height:50px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table>
+<table align="center" class="row btn-group" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <center data-parsed="" style="min-width:490px;width:100%">
+ <!--[if (gte mso 9)|(IE)]>
+ <table>
+ <tr>
+ <td>
+ <![endif]-->
+ <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;border-radius:8px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:#00679e;background-color:#00679e;color:#fefefe;">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #00679e;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://example.com/" style="Margin:0;border:0 solid #00679e;color:#ffffff;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;padding:8px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Go to TestCloud</a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ <!--[if (gte mso 9)|(IE)]>
+ </td>
+ <td>
+ <![endif]-->
+ <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;background-color: #ccc;margin:0 0 30px 0;max-height:40px;max-width:300px;padding:1px;border-radius:8px;text-align:center;vertical-align:top;width:auto">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;border-radius: 7px;padding:8px;text-align:left;text-decoration:none">Install Client</a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ <!--[if (gte mso 9)|(IE)]>
+ </td>
+ </tr>
+ </table>
+ <![endif]-->
+ </center>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+</table><table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table>
+<table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <center data-parsed="" style="min-width:580px;width:100%">
+ <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="15px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+ </table>
+ <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">TestCloud<br>This is an automatically sent email, please do not reply.</p>
+ </center>
+ </td>
+ </tr>
+</table> </center>
+ </td>
+ </tr>
+ </table>
+ <!-- prevent Gmail on iOS font size manipulation -->
+ <div style="display:none;white-space:nowrap;font:15px courier;line-height:0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
+ </body>
+</html>
+
+EOF;
+ $expectedTextBody = <<<EOF
+Welcome aboard John Doe
+
+Welcome to your TestCloud account, you can add, protect, and share your data.
+
+Your Login is: john
+
+
+Go to TestCloud: https://example.com/
+Install Client: https://nextcloud.com/install/#install-clients
+
+
+EOF;
+ $expectedTextBody .= "\n-- \n";
+ $expectedTextBody .= <<<EOF
+TestCloud
+This is an automatically sent email, please do not reply.
+EOF;
+
+ $result = $this->newUserMailHelper->generateTemplate($user, false);
+ $this->assertEquals($expectedHtmlBody, $result->renderHtml());
+ $this->assertEquals($expectedTextBody, $result->renderText());
+ $this->assertSame('OC\Mail\EMailTemplate', get_class($result));
+ }
+
+ public function testGenerateTemplateWithoutUserId(): void {
+ $this->urlGenerator
+ ->expects($this->any())
+ ->method('getAbsoluteURL')
+ ->willReturnMap([
+ ['/', 'https://example.com/'],
+ ['myLogo', ''],
+ ]);
+
+ /** @var IUser&MockObject $user */
+ $user = $this->createMock(IUser::class);
+ $user
+ ->expects($this->any())
+ ->method('getDisplayName')
+ ->willReturn('John Doe');
+ $user
+ ->expects($this->any())
+ ->method('getUID')
+ ->willReturn('john');
+ $user
+ ->expects($this->atLeastOnce())
+ ->method('getBackendClassName')
+ ->willReturn('LDAP');
+ $this->defaults
+ ->expects($this->any())
+ ->method('getName')
+ ->willReturn('TestCloud');
+ $this->defaults
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultColorPrimary')
+ ->willReturn('#00679e');
+ $this->defaults
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultTextColorPrimary')
+ ->willReturn('#ffffff');
+
+ $expectedHtmlBody = <<<EOF
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width">
+ <title></title>
+ <style type="text/css">@media only screen{html{min-height:100%;background:#fff}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
+</head>
+<body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;margin:0;background:#fff!important;box-sizing:border-box;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
+ <span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
+ </span>
+ <table class="body" style="-webkit-font-smoothing:antialiased;margin:0;background:#fff;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <center data-parsed="" style="min-width:580px;width:100%"><table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table align="center" class="container" style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:150px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <center data-parsed="" style="background-color:#00679e;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
+ <img class="logo float-center" src="" alt="TestCloud" align="center" style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;height:auto">
+ </center>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="40px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table><table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:center;word-wrap:normal">Welcome aboard John Doe</h1>
+ </td>
+ </tr>
+ </tbody>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="36px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:36px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table><table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table align="center" class="container" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <p style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center">Welcome to your TestCloud account, you can add, protect, and share your data.</p>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table><table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:50px;font-weight:400;hyphens:auto;line-height:50px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table>
+<table align="center" class="row btn-group" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <center data-parsed="" style="min-width:490px;width:100%">
+ <!--[if (gte mso 9)|(IE)]>
+ <table>
+ <tr>
+ <td>
+ <![endif]-->
+ <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;border-radius:8px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:#00679e;background-color:#00679e;color:#fefefe;">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #00679e;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://example.com/" style="Margin:0;border:0 solid #00679e;color:#ffffff;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;padding:8px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Go to TestCloud</a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ <!--[if (gte mso 9)|(IE)]>
+ </td>
+ <td>
+ <![endif]-->
+ <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;background-color: #ccc;margin:0 0 30px 0;max-height:40px;max-width:300px;padding:1px;border-radius:8px;text-align:center;vertical-align:top;width:auto">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;border-radius: 7px;padding:8px;text-align:left;text-decoration:none">Install Client</a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ <!--[if (gte mso 9)|(IE)]>
+ </td>
+ </tr>
+ </table>
+ <![endif]-->
+ </center>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+</table><table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table>
+<table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <center data-parsed="" style="min-width:580px;width:100%">
+ <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="15px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+ </table>
+ <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">TestCloud<br>This is an automatically sent email, please do not reply.</p>
+ </center>
+ </td>
+ </tr>
+</table> </center>
+ </td>
+ </tr>
+ </table>
+ <!-- prevent Gmail on iOS font size manipulation -->
+ <div style="display:none;white-space:nowrap;font:15px courier;line-height:0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
+ </body>
+</html>
+
+EOF;
+ $expectedTextBody = <<<EOF
+Welcome aboard John Doe
+
+Welcome to your TestCloud account, you can add, protect, and share your data.
+
+
+Go to TestCloud: https://example.com/
+Install Client: https://nextcloud.com/install/#install-clients
+
+
+EOF;
+ $expectedTextBody .= "\n-- \n";
+ $expectedTextBody .= <<<EOF
+TestCloud
+This is an automatically sent email, please do not reply.
+EOF;
+
+ $result = $this->newUserMailHelper->generateTemplate($user, false);
+ $this->assertEquals($expectedHtmlBody, $result->renderHtml());
+ $this->assertEquals($expectedTextBody, $result->renderText());
+ $this->assertSame('OC\Mail\EMailTemplate', get_class($result));
+ }
+
+ public function testSendMail(): void {
+ /** @var IUser&MockObject $user */
+ $user = $this->createMock(IUser::class);
+ $user
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->willReturn('recipient@example.com');
+ $user
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->willReturn('John Doe');
+ /** @var IEMailTemplate&MockObject $emailTemplate */
+ $emailTemplate = $this->createMock(IEMailTemplate::class);
+ $message = $this->createMock(Message::class);
+ $message
+ ->expects($this->once())
+ ->method('setTo')
+ ->with(['recipient@example.com' => 'John Doe']);
+ $message
+ ->expects($this->once())
+ ->method('setFrom')
+ ->with(['no-reply@nextcloud.com' => 'TestCloud']);
+ $message
+ ->expects($this->once())
+ ->method('useTemplate')
+ ->with($emailTemplate);
+ $message
+ ->expects($this->once())
+ ->method('setAutoSubmitted')
+ ->with(AutoSubmitted::VALUE_AUTO_GENERATED);
+ $this->defaults
+ ->expects($this->once())
+ ->method('getName')
+ ->willReturn('TestCloud');
+ $this->mailer
+ ->expects($this->once())
+ ->method('createMessage')
+ ->willReturn($message);
+
+ $this->newUserMailHelper->sendMail($user, $emailTemplate);
+ }
+}
diff --git a/apps/settings/tests/Middleware/SubadminMiddlewareTest.php b/apps/settings/tests/Middleware/SubadminMiddlewareTest.php
new file mode 100644
index 00000000000..37cfb5ccc59
--- /dev/null
+++ b/apps/settings/tests/Middleware/SubadminMiddlewareTest.php
@@ -0,0 +1,126 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2014 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\Settings\Tests\Middleware;
+
+use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException;
+use OC\AppFramework\Utility\ControllerMethodReflector;
+use OCA\Settings\Middleware\SubadminMiddleware;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Group\ISubAdmin;
+use OCP\IL10N;
+use OCP\IUser;
+use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
+
+/**
+ * Verifies whether an user has at least subadmin rights.
+ * To bypass use the `@NoSubAdminRequired` annotation
+ *
+ * @package Tests\Settings\Middleware
+ */
+class SubadminMiddlewareTest extends \Test\TestCase {
+ private SubadminMiddleware $subadminMiddleware;
+ private IUserSession&MockObject $userSession;
+ private ISubAdmin&MockObject $subAdminManager;
+ private ControllerMethodReflector&MockObject $reflector;
+ private Controller&MockObject $controller;
+ private IL10N&MockObject $l10n;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->reflector = $this->createMock(ControllerMethodReflector::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->subAdminManager = $this->createMock(ISubAdmin::class);
+ $this->l10n = $this->createMock(IL10N::class);
+
+ $this->subadminMiddleware = new SubadminMiddleware(
+ $this->reflector,
+ $this->userSession,
+ $this->subAdminManager,
+ $this->l10n,
+ );
+
+ $this->controller = $this->createMock(Controller::class);
+
+ $this->userSession
+ ->expects(self::any())
+ ->method('getUser')
+ ->willReturn($this->createMock(IUser::class));
+ }
+
+
+ public function testBeforeControllerAsUserWithoutAnnotation(): void {
+ $this->expectException(NotAdminException::class);
+
+ $this->reflector
+ ->expects($this->exactly(2))
+ ->method('hasAnnotation')
+ ->willReturnMap([
+ ['NoSubAdminRequired', false],
+ ['AuthorizedAdminSetting', false],
+ ]);
+
+ $this->subAdminManager
+ ->expects(self::once())
+ ->method('isSubAdmin')
+ ->willReturn(false);
+
+ $this->subadminMiddleware->beforeController($this->controller, 'foo');
+ }
+
+
+ public function testBeforeControllerWithAnnotation(): void {
+ $this->reflector
+ ->expects($this->once())
+ ->method('hasAnnotation')
+ ->with('NoSubAdminRequired')
+ ->willReturn(true);
+
+ $this->subAdminManager
+ ->expects(self::never())
+ ->method('isSubAdmin');
+
+ $this->subadminMiddleware->beforeController($this->controller, 'foo');
+ }
+
+ public function testBeforeControllerAsSubAdminWithoutAnnotation(): void {
+ $this->reflector
+ ->expects($this->exactly(2))
+ ->method('hasAnnotation')
+ ->willReturnMap([
+ ['NoSubAdminRequired', false],
+ ['AuthorizedAdminSetting', false],
+ ]);
+
+ $this->subAdminManager
+ ->expects(self::once())
+ ->method('isSubAdmin')
+ ->willReturn(true);
+
+ $this->subadminMiddleware->beforeController($this->controller, 'foo');
+ }
+
+ public function testAfterNotAdminException(): void {
+ $expectedResponse = new TemplateResponse('core', '403', [], 'guest');
+ $expectedResponse->setStatus(403);
+ $this->assertEquals($expectedResponse, $this->subadminMiddleware->afterException($this->controller, 'foo', new NotAdminException('')));
+ }
+
+
+ public function testAfterRegularException(): void {
+ $this->expectException(\Exception::class);
+
+ $expectedResponse = new TemplateResponse('core', '403', [], 'guest');
+ $expectedResponse->setStatus(403);
+ $this->subadminMiddleware->afterException($this->controller, 'foo', new \Exception());
+ }
+}
diff --git a/apps/settings/tests/Settings/Admin/MailTest.php b/apps/settings/tests/Settings/Admin/MailTest.php
new file mode 100644
index 00000000000..992c7d43dba
--- /dev/null
+++ b/apps/settings/tests/Settings/Admin/MailTest.php
@@ -0,0 +1,95 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Settings\Admin;
+
+use OCA\Settings\Settings\Admin\Mail;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IBinaryFinder;
+use OCP\IConfig;
+use OCP\IL10N;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class MailTest extends TestCase {
+
+ private Mail $admin;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->config = $this->createMock(IConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
+
+ $this->admin = new Mail(
+ $this->config,
+ $this->l10n
+ );
+ }
+
+ public static function dataGetForm(): array {
+ return [
+ [true],
+ [false],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetForm')]
+ public function testGetForm(bool $sendmail) {
+ $finder = $this->createMock(IBinaryFinder::class);
+ $finder->expects(self::once())
+ ->method('findBinaryPath')
+ ->with('sendmail')
+ ->willReturn($sendmail ? '/usr/bin/sendmail': false);
+ $this->overwriteService(IBinaryFinder::class, $finder);
+
+ $this->config
+ ->expects($this->any())
+ ->method('getSystemValue')
+ ->willReturnMap([
+ ['mail_domain', '', 'mx.nextcloud.com'],
+ ['mail_from_address', '', 'no-reply@nextcloud.com'],
+ ['mail_smtpmode', '', 'smtp'],
+ ['mail_smtpsecure', '', true],
+ ['mail_smtphost', '', 'smtp.nextcloud.com'],
+ ['mail_smtpport', '', 25],
+ ['mail_smtpauth', false, true],
+ ['mail_smtpname', '', 'smtp.sender.com'],
+ ['mail_smtppassword', '', 'mypassword'],
+ ['mail_sendmailmode', 'smtp', 'smtp'],
+ ]);
+
+ $expected = new TemplateResponse(
+ 'settings',
+ 'settings/admin/additional-mail',
+ [
+ 'sendmail_is_available' => $sendmail,
+ 'mail_domain' => 'mx.nextcloud.com',
+ 'mail_from_address' => 'no-reply@nextcloud.com',
+ 'mail_smtpmode' => 'smtp',
+ 'mail_smtpsecure' => true,
+ 'mail_smtphost' => 'smtp.nextcloud.com',
+ 'mail_smtpport' => 25,
+ 'mail_smtpauth' => true,
+ 'mail_smtpname' => 'smtp.sender.com',
+ 'mail_smtppassword' => '********',
+ 'mail_sendmailmode' => 'smtp',
+ ],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection(): void {
+ $this->assertSame('server', $this->admin->getSection());
+ }
+
+ public function testGetPriority(): void {
+ $this->assertSame(10, $this->admin->getPriority());
+ }
+}
diff --git a/apps/settings/tests/Settings/Admin/SecurityTest.php b/apps/settings/tests/Settings/Admin/SecurityTest.php
new file mode 100644
index 00000000000..89a6d8c0d88
--- /dev/null
+++ b/apps/settings/tests/Settings/Admin/SecurityTest.php
@@ -0,0 +1,113 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Settings\Admin;
+
+use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
+use OC\Encryption\Manager;
+use OCA\Settings\Settings\Admin\Security;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
+use OCP\IURLGenerator;
+use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class SecurityTest extends TestCase {
+ private Manager $manager;
+ private IUserManager $userManager;
+ private MandatoryTwoFactor&MockObject $mandatoryTwoFactor;
+ private IInitialState&MockObject $initialState;
+ private Security $admin;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->manager = $this->createMock(Manager::class);
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
+ $this->initialState = $this->createMock(IInitialState::class);
+
+ $this->admin = new Security(
+ $this->manager,
+ $this->userManager,
+ $this->mandatoryTwoFactor,
+ $this->initialState,
+ $this->createMock(IURLGenerator::class)
+ );
+ }
+
+ public static function encryptionSettingsProvider(): array {
+ return [
+ [true],
+ [false],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')]
+ public function testGetFormWithOnlyOneBackend(bool $enabled): void {
+ $this->manager
+ ->expects($this->once())
+ ->method('isEnabled')
+ ->willReturn($enabled);
+ $this->manager
+ ->expects($this->once())
+ ->method('isReady')
+ ->willReturn($enabled);
+ $this->manager
+ ->expects($this->once())
+ ->method('getEncryptionModules')
+ ->willReturn([]);
+ $this->userManager
+ ->expects($this->once())
+ ->method('getBackends')
+ ->willReturn(['entry']);
+ $expected = new TemplateResponse(
+ 'settings',
+ 'settings/admin/security',
+ [],
+ ''
+ );
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ /**
+ * @param bool $enabled
+ */
+ #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')]
+ public function testGetFormWithMultipleBackends($enabled): void {
+ $this->manager
+ ->expects($this->once())
+ ->method('isEnabled')
+ ->willReturn($enabled);
+ $this->manager
+ ->expects($this->once())
+ ->method('isReady')
+ ->willReturn($enabled);
+ $this->manager
+ ->expects($this->once())
+ ->method('getEncryptionModules')
+ ->willReturn([]);
+ $this->userManager
+ ->expects($this->once())
+ ->method('getBackends')
+ ->willReturn(['entry', 'entry']);
+ $expected = new TemplateResponse(
+ 'settings',
+ 'settings/admin/security',
+ [ ],
+ ''
+ );
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection(): void {
+ $this->assertSame('security', $this->admin->getSection());
+ }
+
+ public function testGetPriority(): void {
+ $this->assertSame(10, $this->admin->getPriority());
+ }
+}
diff --git a/apps/settings/tests/Settings/Admin/ServerTest.php b/apps/settings/tests/Settings/Admin/ServerTest.php
new file mode 100644
index 00000000000..e2ca4cff3c6
--- /dev/null
+++ b/apps/settings/tests/Settings/Admin/ServerTest.php
@@ -0,0 +1,106 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Settings\Admin;
+
+use OC\Profile\ProfileManager;
+use OCA\Settings\Settings\Admin\Server;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IAppConfig;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\IL10N;
+use OCP\IUrlGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+/**
+ * @group DB
+ */
+class ServerTest extends TestCase {
+ private IDBConnection $connection;
+ private Server&MockObject $admin;
+ private IInitialState&MockObject $initialStateService;
+ private ProfileManager&MockObject $profileManager;
+ private ITimeFactory&MockObject $timeFactory;
+ private IConfig&MockObject $config;
+ private IAppConfig&MockObject $appConfig;
+ private IL10N&MockObject $l10n;
+ private IUrlGenerator&MockObject $urlGenerator;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->connection = \OCP\Server::get(IDBConnection::class);
+ $this->initialStateService = $this->createMock(IInitialState::class);
+ $this->profileManager = $this->createMock(ProfileManager::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->urlGenerator = $this->createMock(IUrlGenerator::class);
+
+ $this->admin = $this->getMockBuilder(Server::class)
+ ->onlyMethods(['cronMaxAge'])
+ ->setConstructorArgs([
+ $this->connection,
+ $this->initialStateService,
+ $this->profileManager,
+ $this->timeFactory,
+ $this->urlGenerator,
+ $this->config,
+ $this->appConfig,
+ $this->l10n,
+ ])
+ ->getMock();
+ }
+
+ public function testGetForm(): void {
+ $this->admin->expects($this->once())
+ ->method('cronMaxAge')
+ ->willReturn(1337);
+ $this->config
+ ->expects($this->any())
+ ->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'lastcron', '0', '0'],
+ ['core', 'cronErrors', ''],
+ ]);
+ $this->appConfig
+ ->expects($this->any())
+ ->method('getValueString')
+ ->willReturnCallback(fn ($a, $b, $default) => $default);
+ $this->appConfig
+ ->expects($this->any())
+ ->method('getValueBool')
+ ->willReturnCallback(fn ($a, $b, $default) => $default);
+ $this->profileManager
+ ->expects($this->exactly(2))
+ ->method('isProfileEnabled')
+ ->willReturn(true);
+ $expected = new TemplateResponse(
+ 'settings',
+ 'settings/admin/server',
+ [
+ 'profileEnabledGlobally' => true,
+ ],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection(): void {
+ $this->assertSame('server', $this->admin->getSection());
+ }
+
+ public function testGetPriority(): void {
+ $this->assertSame(0, $this->admin->getPriority());
+ }
+}
diff --git a/apps/settings/tests/Settings/Admin/SharingTest.php b/apps/settings/tests/Settings/Admin/SharingTest.php
new file mode 100644
index 00000000000..f37ade2171f
--- /dev/null
+++ b/apps/settings/tests/Settings/Admin/SharingTest.php
@@ -0,0 +1,264 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Settings\Admin;
+
+use OCA\Settings\Settings\Admin\Sharing;
+use OCP\App\IAppManager;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
+use OCP\Constants;
+use OCP\IAppConfig;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\Share\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class SharingTest extends TestCase {
+ private Sharing $admin;
+
+ private IConfig&MockObject $config;
+ private IAppConfig&MockObject $appConfig;
+ private IL10N&MockObject $l10n;
+ private IManager&MockObject $shareManager;
+ private IAppManager&MockObject $appManager;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IInitialState&MockObject $initialState;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
+
+ $this->shareManager = $this->createMock(IManager::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->initialState = $this->createMock(IInitialState::class);
+
+ $this->admin = new Sharing(
+ $this->config,
+ $this->appConfig,
+ $this->l10n,
+ $this->shareManager,
+ $this->appManager,
+ $this->urlGenerator,
+ $this->initialState,
+ 'settings',
+ );
+ }
+
+ public function testGetFormWithoutExcludedGroups(): void {
+ $this->appConfig
+ ->method('getValueBool')
+ ->willReturnMap([
+ ['core', 'shareapi_allow_federation_on_public_shares', true],
+ ['core', 'shareapi_enable_link_password_by_default', true],
+ ]);
+
+ $this->config
+ ->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_exclude_groups_list', '', ''],
+ ['core', 'shareapi_allow_links_exclude_groups', '', ''],
+ ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
+ ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
+ ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
+ ['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
+ ['core', 'shareapi_enabled', 'yes', 'yes'],
+ ['core', 'shareapi_default_expire_date', 'no', 'no'],
+ ['core', 'shareapi_expire_after_n_days', '7', '7'],
+ ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
+ ['core', 'shareapi_exclude_groups', 'no', 'no'],
+ ['core', 'shareapi_public_link_disclaimertext', '', 'Lorem ipsum'],
+ ['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
+ ['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
+ ['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
+ ['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
+ ['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
+ ['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
+ ['core', 'shareapi_only_share_with_group_members_exclude_group_list', '', '[]'],
+ ]);
+ $this->shareManager->method('shareWithGroupMembersOnly')
+ ->willReturn(false);
+
+ $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false);
+
+ $initialStateCalls = [];
+ $this->initialState
+ ->expects($this->exactly(3))
+ ->method('provideInitialState')
+ ->willReturnCallback(function (string $key) use (&$initialStateCalls): void {
+ $initialStateCalls[$key] = func_get_args();
+ });
+
+ $expectedInitialStateCalls = [
+ 'sharingAppEnabled' => false,
+ 'sharingDocumentation' => '',
+ 'sharingSettings' => [
+ 'allowGroupSharing' => true,
+ 'allowLinks' => true,
+ 'allowPublicUpload' => true,
+ 'allowResharing' => true,
+ 'allowShareDialogUserEnumeration' => true,
+ 'allowFederationOnPublicShares' => true,
+ 'restrictUserEnumerationToGroup' => false,
+ 'restrictUserEnumerationToPhone' => false,
+ 'restrictUserEnumerationFullMatch' => true,
+ 'restrictUserEnumerationFullMatchUserId' => true,
+ 'restrictUserEnumerationFullMatchEmail' => true,
+ 'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
+ 'enforceLinksPassword' => false,
+ 'onlyShareWithGroupMembers' => false,
+ 'enabled' => true,
+ 'defaultExpireDate' => false,
+ 'expireAfterNDays' => '7',
+ 'enforceExpireDate' => false,
+ 'excludeGroups' => 'no',
+ 'excludeGroupsList' => [],
+ 'publicShareDisclaimerText' => 'Lorem ipsum',
+ 'enableLinkPasswordByDefault' => true,
+ 'defaultPermissions' => Constants::PERMISSION_ALL,
+ 'defaultInternalExpireDate' => false,
+ 'internalExpireAfterNDays' => '7',
+ 'enforceInternalExpireDate' => false,
+ 'defaultRemoteExpireDate' => false,
+ 'remoteExpireAfterNDays' => '7',
+ 'enforceRemoteExpireDate' => false,
+ 'allowLinksExcludeGroups' => [],
+ 'onlyShareWithGroupMembersExcludeGroupList' => [],
+ 'enforceLinksPasswordExcludedGroups' => [],
+ 'enforceLinksPasswordExcludedGroupsEnabled' => false,
+ ]
+ ];
+
+ $expected = new TemplateResponse(
+ 'settings',
+ 'settings/admin/sharing',
+ [],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ $this->assertEquals(sort($expectedInitialStateCalls), sort($initialStateCalls), 'Provided initial state does not match');
+ }
+
+ public function testGetFormWithExcludedGroups(): void {
+ $this->config
+ ->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_exclude_groups_list', '', '["NoSharers","OtherNoSharers"]'],
+ ['core', 'shareapi_allow_links_exclude_groups', '', ''],
+ ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
+ ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
+ ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
+ ['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
+ ['core', 'shareapi_enabled', 'yes', 'yes'],
+ ['core', 'shareapi_default_expire_date', 'no', 'no'],
+ ['core', 'shareapi_expire_after_n_days', '7', '7'],
+ ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
+ ['core', 'shareapi_exclude_groups', 'no', 'yes'],
+ ['core', 'shareapi_public_link_disclaimertext', '', 'Lorem ipsum'],
+ ['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
+ ['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
+ ['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
+ ['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
+ ['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
+ ['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
+ ['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
+ ['core', 'shareapi_only_share_with_group_members_exclude_group_list', '', '[]'],
+ ]);
+ $this->shareManager->method('shareWithGroupMembersOnly')
+ ->willReturn(false);
+
+ $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true);
+
+ $initialStateCalls = [];
+ $this->initialState
+ ->expects($this->exactly(3))
+ ->method('provideInitialState')
+ ->willReturnCallback(function (string $key) use (&$initialStateCalls): void {
+ $initialStateCalls[$key] = func_get_args();
+ });
+
+ $expectedInitialStateCalls = [
+ 'sharingAppEnabled' => true,
+ 'sharingDocumentation' => '',
+ 'sharingSettings' => [
+ 'allowGroupSharing' => true,
+ 'allowLinks' => true,
+ 'allowPublicUpload' => true,
+ 'allowResharing' => true,
+ 'allowShareDialogUserEnumeration' => true,
+ 'restrictUserEnumerationToGroup' => false,
+ 'restrictUserEnumerationToPhone' => false,
+ 'restrictUserEnumerationFullMatch' => true,
+ 'restrictUserEnumerationFullMatchUserId' => true,
+ 'restrictUserEnumerationFullMatchEmail' => true,
+ 'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
+ 'enforceLinksPassword' => false,
+ 'onlyShareWithGroupMembers' => false,
+ 'enabled' => true,
+ 'defaultExpireDate' => false,
+ 'expireAfterNDays' => '7',
+ 'enforceExpireDate' => false,
+ 'excludeGroups' => 'yes',
+ 'excludeGroupsList' => ['NoSharers','OtherNoSharers'],
+ 'publicShareDisclaimerText' => 'Lorem ipsum',
+ 'enableLinkPasswordByDefault' => true,
+ 'defaultPermissions' => Constants::PERMISSION_ALL,
+ 'defaultInternalExpireDate' => false,
+ 'internalExpireAfterNDays' => '7',
+ 'enforceInternalExpireDate' => false,
+ 'defaultRemoteExpireDate' => false,
+ 'remoteExpireAfterNDays' => '7',
+ 'enforceRemoteExpireDate' => false,
+ 'allowLinksExcludeGroups' => [],
+ 'onlyShareWithGroupMembersExcludeGroupList' => [],
+ 'enforceLinksPasswordExcludedGroups' => [],
+ 'enforceLinksPasswordExcludedGroupsEnabled' => false,
+ ],
+ ];
+
+ $expected = new TemplateResponse(
+ 'settings',
+ 'settings/admin/sharing',
+ [],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ $this->assertEquals(sort($expectedInitialStateCalls), sort($initialStateCalls), 'Provided initial state does not match');
+ }
+
+ public function testGetSection(): void {
+ $this->assertSame('sharing', $this->admin->getSection());
+ }
+
+ public function testGetPriority(): void {
+ $this->assertSame(0, $this->admin->getPriority());
+ }
+}
diff --git a/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
new file mode 100644
index 00000000000..0a0ff4d84af
--- /dev/null
+++ b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
@@ -0,0 +1,110 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Settings\Personal\Security;
+
+use OC\Authentication\Token\IProvider as IAuthTokenProvider;
+use OC\Authentication\Token\PublicKeyToken;
+use OCA\Settings\Settings\Personal\Security\Authtokens;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
+use OCP\Authentication\Token\IToken;
+use OCP\ISession;
+use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class AuthtokensTest extends TestCase {
+ private IAuthTokenProvider&MockObject $authTokenProvider;
+ private ISession&MockObject $session;
+ private IUserSession&MockObject $userSession;
+ private IInitialState&MockObject $initialState;
+ private string $uid;
+ private Authtokens $section;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->authTokenProvider = $this->createMock(IAuthTokenProvider::class);
+ $this->session = $this->createMock(ISession::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->initialState = $this->createMock(IInitialState::class);
+ $this->uid = 'test123';
+
+ $this->section = new Authtokens(
+ $this->authTokenProvider,
+ $this->session,
+ $this->userSession,
+ $this->initialState,
+ $this->uid
+ );
+ }
+
+ public function testGetForm(): void {
+ $token1 = new PublicKeyToken();
+ $token1->setId(100);
+ $token2 = new PublicKeyToken();
+ $token2->setId(200);
+ $tokens = [
+ $token1,
+ $token2,
+ ];
+ $sessionToken = new PublicKeyToken();
+ $sessionToken->setId(100);
+
+ $this->authTokenProvider->expects($this->once())
+ ->method('getTokenByUser')
+ ->with($this->uid)
+ ->willReturn($tokens);
+ $this->session->expects($this->once())
+ ->method('getId')
+ ->willReturn('session123');
+ $this->authTokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('session123')
+ ->willReturn($sessionToken);
+
+ $calls = [
+ [
+ 'app_tokens', [
+ [
+ 'id' => 100,
+ 'name' => null,
+ 'lastActivity' => 0,
+ 'type' => 0,
+ 'canDelete' => false,
+ 'current' => true,
+ 'scope' => [IToken::SCOPE_FILESYSTEM => true],
+ 'canRename' => false,
+ ],
+ [
+ 'id' => 200,
+ 'name' => null,
+ 'lastActivity' => 0,
+ 'type' => 0,
+ 'canDelete' => true,
+ 'scope' => [IToken::SCOPE_FILESYSTEM => true],
+ 'canRename' => true,
+ ],
+ ]
+ ],
+ ['can_create_app_token', true],
+ ];
+ $this->initialState->expects($this->exactly(2))
+ ->method('provideInitialState')
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
+
+ $form = $this->section->getForm();
+
+ $expected = new TemplateResponse('settings', 'settings/personal/security/authtokens');
+ $this->assertEquals($expected, $form);
+ }
+}
diff --git a/apps/settings/tests/Settings/Personal/Security/PasswordTest.php b/apps/settings/tests/Settings/Personal/Security/PasswordTest.php
new file mode 100644
index 00000000000..34a4b8e296f
--- /dev/null
+++ b/apps/settings/tests/Settings/Personal/Security/PasswordTest.php
@@ -0,0 +1,52 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\Settings\Personal\Security;
+
+use OCA\Settings\Settings\Personal\Security\Password;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IUser;
+use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class PasswordTest extends TestCase {
+ private IUserManager&MockObject $userManager;
+ private string $uid;
+ private Password $section;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->uid = 'test123';
+
+ $this->section = new Password(
+ $this->userManager,
+ $this->uid
+ );
+ }
+
+ public function testGetForm(): void {
+ $user = $this->createMock(IUser::class);
+ $this->userManager->expects($this->once())
+ ->method('get')
+ ->with($this->uid)
+ ->willReturn($user);
+ $user->expects($this->once())
+ ->method('canChangePassword')
+ ->willReturn(true);
+
+ $form = $this->section->getForm();
+
+ $expected = new TemplateResponse('settings', 'settings/personal/security/password', [
+ 'passwordChangeSupported' => true,
+ ]);
+ $this->assertEquals($expected, $form);
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php b/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php
new file mode 100644
index 00000000000..423f932dcf5
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php
@@ -0,0 +1,102 @@
+<?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\AppDirsWithDifferentOwner;
+use OCP\IL10N;
+use Test\TestCase;
+
+class AppDirsWithDifferentOwnerTest extends TestCase {
+ private IL10N $l10n;
+ private AppDirsWithDifferentOwner $check;
+
+ /**
+ * Holds a list of directories created during tests.
+ *
+ * @var array
+ */
+ private $dirsToRemove = [];
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ $this->check = new AppDirsWithDifferentOwner(
+ $this->l10n,
+ );
+ }
+
+ /**
+ * Setups a temp directory and some subdirectories.
+ * Then calls the 'getAppDirsWithDifferentOwner' method.
+ * The result is expected to be empty since
+ * there are no directories with different owners than the current user.
+ *
+ * @return void
+ */
+ public function testAppDirectoryOwnersOk(): void {
+ $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
+ mkdir($tempDir);
+ mkdir($tempDir . DIRECTORY_SEPARATOR . 'app1');
+ mkdir($tempDir . DIRECTORY_SEPARATOR . 'app2');
+ $this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app1';
+ $this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app2';
+ $this->dirsToRemove[] = $tempDir;
+ \OC::$APPSROOTS = [
+ [
+ 'path' => $tempDir,
+ 'url' => '/apps',
+ 'writable' => true,
+ ],
+ ];
+ $this->assertSame(
+ [],
+ $this->invokePrivate($this->check, 'getAppDirsWithDifferentOwner', [posix_getuid()])
+ );
+ }
+
+ /**
+ * Calls the check for a none existing app root that is marked as not writable.
+ * It's expected that no error happens since the check shouldn't apply.
+ *
+ * @return void
+ */
+ public function testAppDirectoryOwnersNotWritable(): void {
+ $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
+ \OC::$APPSROOTS = [
+ [
+ 'path' => $tempDir,
+ 'url' => '/apps',
+ 'writable' => false,
+ ],
+ ];
+ $this->assertSame(
+ [],
+ $this->invokePrivate($this->check, 'getAppDirsWithDifferentOwner', [posix_getuid()])
+ );
+ }
+
+ /**
+ * Removes directories created during tests.
+ *
+ * @after
+ * @return void
+ */
+ public function removeTestDirectories() {
+ foreach ($this->dirsToRemove as $dirToRemove) {
+ rmdir($dirToRemove);
+ }
+ $this->dirsToRemove = [];
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/CodeIntegrityTest.php b/apps/settings/tests/SetupChecks/CodeIntegrityTest.php
new file mode 100644
index 00000000000..4dd54a644f5
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/CodeIntegrityTest.php
@@ -0,0 +1,134 @@
+<?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 OC\IntegrityCheck\Checker;
+use OCA\Settings\SetupChecks\CodeIntegrity;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class CodeIntegrityTest extends TestCase {
+
+ private IL10N&MockObject $l10n;
+ private IURLGenerator&MockObject $urlGenerator;
+ private Checker&MockObject $checker;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->checker = $this->createMock(Checker::class);
+ }
+
+ public function testSkipOnDisabled(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(false);
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::INFO, $check->run()->getSeverity());
+ }
+
+ public function testSuccessOnEmptyResults(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn([]);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(true);
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+
+ public function testCheckerIsReRunWithoutResults(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn(null);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(true);
+
+ // This is important and must be called
+ $this->checker->expects($this->once())
+ ->method('runInstanceVerification');
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+
+ public function testCheckerIsNotReReInAdvance(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn(['mocked']);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(true);
+
+ // There are results thus this must never be called
+ $this->checker->expects($this->never())
+ ->method('runInstanceVerification');
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+
+ public function testErrorOnMissingIntegrity(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn(['mocked']);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(false);
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::ERROR, $check->run()->getSeverity());
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php b/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php
new file mode 100644
index 00000000000..c20c78c6e16
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php
@@ -0,0 +1,117 @@
+<?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\DataDirectoryProtected;
+use OCP\Http\Client\IClientService;
+use OCP\Http\Client\IResponse;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class DataDirectoryProtectedTest extends TestCase {
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IClientService&MockObject $clientService;
+ private LoggerInterface&MockObject $logger;
+ private DataDirectoryProtected&MockObject $setupcheck;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+
+ $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->setupcheck = $this->getMockBuilder(DataDirectoryProtected::class)
+ ->onlyMethods(['runRequest'])
+ ->setConstructorArgs([
+ $this->l10n,
+ $this->config,
+ $this->urlGenerator,
+ $this->clientService,
+ $this->logger,
+ ])
+ ->getMock();
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestStatusCode')]
+ public function testStatusCode(array $status, string $expected, bool $hasBody): void {
+ $responses = array_map(function ($state) use ($hasBody) {
+ $response = $this->createMock(IResponse::class);
+ $response->expects($this->any())->method('getStatusCode')->willReturn($state);
+ $response->expects(($this->atMost(1)))->method('getBody')->willReturn($hasBody ? '# Nextcloud data directory' : 'something else');
+ return $response;
+ }, $status);
+
+ $this->setupcheck
+ ->expects($this->once())
+ ->method('runRequest')
+ ->will($this->generate($responses));
+
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValueString')
+ ->willReturn('');
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals($expected, $result->getSeverity());
+ }
+
+ public static function dataTestStatusCode(): array {
+ return [
+ 'success: forbidden access' => [[403], SetupResult::SUCCESS, true],
+ 'success: forbidden access with redirect' => [[200], SetupResult::SUCCESS, false],
+ 'error: can access' => [[200], SetupResult::ERROR, true],
+ 'error: one forbidden one can access' => [[403, 200], SetupResult::ERROR, true],
+ 'warning: connection issue' => [[], SetupResult::WARNING, true],
+ ];
+ }
+
+ public function testNoResponse(): void {
+ $response = $this->createMock(IResponse::class);
+ $response->expects($this->any())->method('getStatusCode')->willReturn(200);
+
+ $this->setupcheck
+ ->expects($this->once())
+ ->method('runRequest')
+ ->will($this->generate([]));
+
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValueString')
+ ->willReturn('');
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
+ $this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
+ }
+
+ /**
+ * Helper function creates a nicer interface for mocking Generator behavior
+ */
+ protected function generate(array $yield_values) {
+ return $this->returnCallback(function () use ($yield_values) {
+ yield from $yield_values;
+ });
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php b/apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php
new file mode 100644
index 00000000000..9b4878b45cc
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php
@@ -0,0 +1,119 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\SetupChecks;
+
+use OCA\Settings\SetupChecks\ForwardedForHeaders;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use Test\TestCase;
+
+class ForwardedForHeadersTest extends TestCase {
+ private IL10N $l10n;
+ private IConfig $config;
+ private IURLGenerator $urlGenerator;
+ private IRequest $request;
+ private ForwardedForHeaders $check;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ $this->config = $this->getMockBuilder(IConfig::class)->getMock();
+ $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
+ $this->request = $this->getMockBuilder(IRequest::class)->getMock();
+ $this->check = new ForwardedForHeaders(
+ $this->l10n,
+ $this->config,
+ $this->urlGenerator,
+ $this->request,
+ );
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataForwardedForHeadersWorking')]
+ public function testForwardedForHeadersWorking(array $trustedProxies, string $remoteAddrNotForwarded, string $remoteAddr, string $result): void {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('trusted_proxies', [])
+ ->willReturn($trustedProxies);
+ $this->request->expects($this->atLeastOnce())
+ ->method('getHeader')
+ ->willReturnMap([
+ ['REMOTE_ADDR', $remoteAddrNotForwarded],
+ ['X-Forwarded-Host', '']
+ ]);
+ $this->request->expects($this->any())
+ ->method('getRemoteAddress')
+ ->willReturn($remoteAddr);
+
+ $this->assertEquals(
+ $result,
+ $this->check->run()->getSeverity()
+ );
+ }
+
+ public static function dataForwardedForHeadersWorking(): array {
+ return [
+ // description => trusted proxies, getHeader('REMOTE_ADDR'), getRemoteAddr, expected result
+ 'no trusted proxies' => [[], '2.2.2.2', '2.2.2.2', SetupResult::SUCCESS],
+ 'trusted proxy, remote addr not trusted proxy' => [['1.1.1.1'], '2.2.2.2', '2.2.2.2', SetupResult::SUCCESS],
+ 'trusted proxy, remote addr is trusted proxy, x-forwarded-for working' => [['1.1.1.1'], '1.1.1.1', '2.2.2.2', SetupResult::SUCCESS],
+ 'trusted proxy, remote addr is trusted proxy, x-forwarded-for not set' => [['1.1.1.1'], '1.1.1.1', '1.1.1.1', SetupResult::WARNING],
+ ];
+ }
+
+ public function testForwardedHostPresentButTrustedProxiesNotAnArray(): void {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('trusted_proxies', [])
+ ->willReturn('1.1.1.1');
+ $this->request->expects($this->atLeastOnce())
+ ->method('getHeader')
+ ->willReturnMap([
+ ['REMOTE_ADDR', '1.1.1.1'],
+ ['X-Forwarded-Host', 'nextcloud.test']
+ ]);
+ $this->request->expects($this->any())
+ ->method('getRemoteAddress')
+ ->willReturn('1.1.1.1');
+
+ $this->assertEquals(
+ SetupResult::ERROR,
+ $this->check->run()->getSeverity()
+ );
+ }
+
+ public function testForwardedHostPresentButTrustedProxiesEmpty(): void {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('trusted_proxies', [])
+ ->willReturn([]);
+ $this->request->expects($this->atLeastOnce())
+ ->method('getHeader')
+ ->willReturnMap([
+ ['REMOTE_ADDR', '1.1.1.1'],
+ ['X-Forwarded-Host', 'nextcloud.test']
+ ]);
+ $this->request->expects($this->any())
+ ->method('getRemoteAddress')
+ ->willReturn('1.1.1.1');
+
+ $this->assertEquals(
+ SetupResult::ERROR,
+ $this->check->run()->getSeverity()
+ );
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/LoggingLevelTest.php b/apps/settings/tests/SetupChecks/LoggingLevelTest.php
new file mode 100644
index 00000000000..67224e11e3a
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/LoggingLevelTest.php
@@ -0,0 +1,76 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\SetupChecks;
+
+use OCA\Settings\SetupChecks\LoggingLevel;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\ILogger;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LogLevel;
+use Test\TestCase;
+
+class LoggingLevelTest extends TestCase {
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ $this->config = $this->createMock(IConfig::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ }
+
+ public static function dataRun(): array {
+ return [
+ [ILogger::INFO, SetupResult::SUCCESS],
+ [ILogger::WARN, SetupResult::SUCCESS],
+ [ILogger::ERROR, SetupResult::SUCCESS],
+ [ILogger::FATAL, SetupResult::SUCCESS],
+
+ // Debug is valid but will result in an warning
+ [ILogger::DEBUG, SetupResult::WARNING],
+
+ // negative - invalid range
+ [-1, SetupResult::ERROR],
+ // string value instead of number
+ ['1', SetupResult::ERROR],
+ // random string value
+ ['error', SetupResult::ERROR],
+ // PSR logger value
+ [LogLevel::ALERT, SetupResult::ERROR],
+ // out of range
+ [ILogger::FATAL + 1, SetupResult::ERROR],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRun')]
+ public function testRun(string|int $value, string $expected): void {
+ $this->urlGenerator->method('linkToDocs')->willReturn('admin-logging');
+
+ $this->config->expects(self::once())
+ ->method('getSystemValue')
+ ->with('loglevel', ILogger::WARN)
+ ->willReturn($value);
+
+ $check = new LoggingLevel($this->l10n, $this->config, $this->urlGenerator);
+
+ $result = $check->run();
+ $this->assertEquals($expected, $result->getSeverity());
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/OcxProvicersTest.php b/apps/settings/tests/SetupChecks/OcxProvicersTest.php
new file mode 100644
index 00000000000..8e5a2c1b88b
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/OcxProvicersTest.php
@@ -0,0 +1,151 @@
+<?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\OcxProviders;
+use OCP\Http\Client\IClientService;
+use OCP\Http\Client\IResponse;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class OcxProvicersTest extends TestCase {
+ private IL10N|MockObject $l10n;
+ private IConfig|MockObject $config;
+ private IURLGenerator|MockObject $urlGenerator;
+ private IClientService|MockObject $clientService;
+ private LoggerInterface|MockObject $logger;
+ private OcxProviders|MockObject $setupcheck;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+
+ $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->setupcheck = $this->getMockBuilder(OcxProviders::class)
+ ->onlyMethods(['runRequest'])
+ ->setConstructorArgs([
+ $this->l10n,
+ $this->config,
+ $this->urlGenerator,
+ $this->clientService,
+ $this->logger,
+ ])
+ ->getMock();
+ }
+
+ public function testSuccess(): void {
+ $response = $this->createMock(IResponse::class);
+ $response->expects($this->any())->method('getStatusCode')->willReturn(200);
+
+ $this->setupcheck
+ ->expects($this->exactly(2))
+ ->method('runRequest')
+ ->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([$response]));
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
+ }
+
+ public function testLateSuccess(): void {
+ $response1 = $this->createMock(IResponse::class);
+ $response1->expects($this->exactly(3))->method('getStatusCode')->willReturnOnConsecutiveCalls(404, 500, 200);
+ $response2 = $this->createMock(IResponse::class);
+ $response2->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(200);
+
+ $this->setupcheck
+ ->expects($this->exactly(2))
+ ->method('runRequest')
+ ->willReturnOnConsecutiveCalls($this->generate([$response1, $response1, $response1]), $this->generate([$response2])); // only one response out of two
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
+ }
+
+ public function testNoResponse(): void {
+ $response = $this->createMock(IResponse::class);
+ $response->expects($this->any())->method('getStatusCode')->willReturn(200);
+
+ $this->setupcheck
+ ->expects($this->exactly(2))
+ ->method('runRequest')
+ ->willReturnOnConsecutiveCalls($this->generate([]), $this->generate([])); // No responses
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
+ $this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
+ }
+
+ public function testPartialResponse(): void {
+ $response = $this->createMock(IResponse::class);
+ $response->expects($this->any())->method('getStatusCode')->willReturn(200);
+
+ $this->setupcheck
+ ->expects($this->exactly(2))
+ ->method('runRequest')
+ ->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([])); // only one response out of two
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
+ $this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
+ }
+
+ public function testInvalidResponse(): void {
+ $response = $this->createMock(IResponse::class);
+ $response->expects($this->any())->method('getStatusCode')->willReturn(404);
+
+ $this->setupcheck
+ ->expects($this->exactly(2))
+ ->method('runRequest')
+ ->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([$response])); // only one response out of two
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
+ $this->assertMatchesRegularExpression('/^Your web server is not properly set up/', $result->getDescription());
+ }
+
+ public function testPartialInvalidResponse(): void {
+ $response1 = $this->createMock(IResponse::class);
+ $response1->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(200);
+ $response2 = $this->createMock(IResponse::class);
+ $response2->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(404);
+
+ $this->setupcheck
+ ->expects($this->exactly(2))
+ ->method('runRequest')
+ ->willReturnOnConsecutiveCalls($this->generate([$response1]), $this->generate([$response2]));
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
+ $this->assertMatchesRegularExpression('/^Your web server is not properly set up/', $result->getDescription());
+ }
+
+ /**
+ * Helper function creates a nicer interface for mocking Generator behavior
+ */
+ protected function generate(array $yield_values) {
+ return $this->returnCallback(function () use ($yield_values) {
+ yield from $yield_values;
+ });
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php b/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php
new file mode 100644
index 00000000000..3722346219a
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php
@@ -0,0 +1,45 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\SetupChecks;
+
+use OCA\Settings\SetupChecks\PhpDefaultCharset;
+use OCP\IL10N;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class PhpDefaultCharsetTest extends TestCase {
+ /** @var IL10N|MockObject */
+ private $l10n;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ }
+
+ public function testPass(): void {
+ $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->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
new file mode 100644
index 00000000000..de509347044
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\SetupChecks;
+
+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->createMock(IL10N::class);
+ $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->l10n);
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/SecurityHeadersTest.php b/apps/settings/tests/SetupChecks/SecurityHeadersTest.php
new file mode 100644
index 00000000000..1f75907d427
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/SecurityHeadersTest.php
@@ -0,0 +1,196 @@
+<?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\SecurityHeaders;
+use OCP\Http\Client\IClientService;
+use OCP\Http\Client\IResponse;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class SecurityHeadersTest extends TestCase {
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IClientService&MockObject $clientService;
+ private LoggerInterface&MockObject $logger;
+ private SecurityHeaders&MockObject $setupcheck;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+
+ $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->setupcheck = $this->getMockBuilder(SecurityHeaders::class)
+ ->onlyMethods(['runRequest'])
+ ->setConstructorArgs([
+ $this->l10n,
+ $this->config,
+ $this->urlGenerator,
+ $this->clientService,
+ $this->logger,
+ ])
+ ->getMock();
+ }
+
+ public function testInvalidStatusCode(): void {
+ $this->setupResponse(500, []);
+
+ $result = $this->setupcheck->run();
+ $this->assertMatchesRegularExpression('/^Could not check that your web server serves security headers correctly/', $result->getDescription());
+ $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
+ }
+
+ public function testAllHeadersMissing(): void {
+ $this->setupResponse(200, []);
+
+ $result = $this->setupcheck->run();
+ $this->assertMatchesRegularExpression('/^Some headers are not set correctly on your instance/', $result->getDescription());
+ $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
+ }
+
+ public function testSomeHeadersMissing(): void {
+ $this->setupResponse(
+ 200,
+ [
+ 'X-Robots-Tag' => 'noindex, nofollow',
+ 'X-Frame-Options' => 'SAMEORIGIN',
+ 'Strict-Transport-Security' => 'max-age=15768000;preload',
+ 'X-Permitted-Cross-Domain-Policies' => 'none',
+ 'Referrer-Policy' => 'no-referrer',
+ ]
+ );
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(
+ "Some headers are not set correctly on your instance\n- The `X-Content-Type-Options` HTTP header is not set to `nosniff`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n",
+ $result->getDescription()
+ );
+ $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
+ }
+
+ public static function dataSuccess(): array {
+ return [
+ // description => modifiedHeaders
+ 'basic' => [[]],
+ 'no-space-in-x-robots' => [['X-Robots-Tag' => 'noindex,nofollow']],
+ 'strict-origin-when-cross-origin' => [['Referrer-Policy' => 'strict-origin-when-cross-origin']],
+ 'referrer-no-referrer-when-downgrade' => [['Referrer-Policy' => 'no-referrer-when-downgrade']],
+ 'referrer-strict-origin' => [['Referrer-Policy' => 'strict-origin']],
+ 'referrer-strict-origin-when-cross-origin' => [['Referrer-Policy' => 'strict-origin-when-cross-origin']],
+ 'referrer-same-origin' => [['Referrer-Policy' => 'same-origin']],
+ 'hsts-minimum' => [['Strict-Transport-Security' => 'max-age=15552000']],
+ 'hsts-include-subdomains' => [['Strict-Transport-Security' => 'max-age=99999999; includeSubDomains']],
+ 'hsts-include-subdomains-preload' => [['Strict-Transport-Security' => 'max-age=99999999; preload; includeSubDomains']],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSuccess')]
+ public function testSuccess(array $headers): void {
+ $headers = array_merge(
+ [
+ 'X-Content-Type-Options' => 'nosniff',
+ 'X-Robots-Tag' => 'noindex, nofollow',
+ 'X-Frame-Options' => 'SAMEORIGIN',
+ 'Strict-Transport-Security' => 'max-age=15768000',
+ 'X-Permitted-Cross-Domain-Policies' => 'none',
+ 'Referrer-Policy' => 'no-referrer',
+ ],
+ $headers
+ );
+ $this->setupResponse(
+ 200,
+ $headers
+ );
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(
+ 'Your server is correctly configured to send security headers.',
+ $result->getDescription()
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
+ }
+
+ public static function dataFailure(): array {
+ return [
+ // description => modifiedHeaders
+ 'x-robots-none' => [['X-Robots-Tag' => 'none'], "- The `X-Robots-Tag` HTTP header is not set to `noindex,nofollow`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n"],
+ 'referrer-origin' => [['Referrer-Policy' => 'origin'], "- The `Referrer-Policy` HTTP header is not set to `no-referrer`, `no-referrer-when-downgrade`, `strict-origin`, `strict-origin-when-cross-origin` or `same-origin`. This can leak referer information. See the {w3c-recommendation}.\n"],
+ 'referrer-origin-when-cross-origin' => [['Referrer-Policy' => 'origin-when-cross-origin'], "- The `Referrer-Policy` HTTP header is not set to `no-referrer`, `no-referrer-when-downgrade`, `strict-origin`, `strict-origin-when-cross-origin` or `same-origin`. This can leak referer information. See the {w3c-recommendation}.\n"],
+ 'referrer-unsafe-url' => [['Referrer-Policy' => 'unsafe-url'], "- The `Referrer-Policy` HTTP header is not set to `no-referrer`, `no-referrer-when-downgrade`, `strict-origin`, `strict-origin-when-cross-origin` or `same-origin`. This can leak referer information. See the {w3c-recommendation}.\n"],
+ 'hsts-missing' => [['Strict-Transport-Security' => ''], "- The `Strict-Transport-Security` HTTP header is not set (should be at least `15552000` seconds). For enhanced security, it is recommended to enable HSTS.\n"],
+ 'hsts-too-low' => [['Strict-Transport-Security' => 'max-age=15551999'], "- The `Strict-Transport-Security` HTTP header is not set to at least `15552000` seconds (current value: `15551999`). For enhanced security, it is recommended to use a long HSTS policy.\n"],
+ 'hsts-malformed' => [['Strict-Transport-Security' => 'iAmABogusHeader342'], "- The `Strict-Transport-Security` HTTP header is malformed: `iAmABogusHeader342`. For enhanced security, it is recommended to enable HSTS.\n"],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFailure')]
+ public function testFailure(array $headers, string $msg): void {
+ $headers = array_merge(
+ [
+ 'X-Content-Type-Options' => 'nosniff',
+ 'X-Robots-Tag' => 'noindex, nofollow',
+ 'X-Frame-Options' => 'SAMEORIGIN',
+ 'Strict-Transport-Security' => 'max-age=15768000',
+ 'X-Permitted-Cross-Domain-Policies' => 'none',
+ 'Referrer-Policy' => 'no-referrer',
+ ],
+ $headers
+ );
+ $this->setupResponse(
+ 200,
+ $headers
+ );
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(
+ 'Some headers are not set correctly on your instance' . "\n$msg",
+ $result->getDescription()
+ );
+ $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
+ }
+
+ protected function setupResponse(int $statuscode, array $headers): void {
+ $response = $this->createMock(IResponse::class);
+ $response->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statuscode);
+ $response->expects($this->any())->method('getHeader')
+ ->willReturnCallback(
+ fn (string $header): string => $headers[$header] ?? ''
+ );
+
+ $this->setupcheck
+ ->expects($this->atLeastOnce())
+ ->method('runRequest')
+ ->willReturnOnConsecutiveCalls($this->generate([$response]));
+ }
+
+ /**
+ * Helper function creates a nicer interface for mocking Generator behavior
+ */
+ protected function generate(array $yield_values) {
+ return $this->returnCallback(function () use ($yield_values) {
+ yield from $yield_values;
+ });
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php b/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php
new file mode 100644
index 00000000000..6c75df47aa0
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php
@@ -0,0 +1,51 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\SetupChecks;
+
+use OCA\Settings\SetupChecks\SupportedDatabase;
+use OCP\IDBConnection;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\Server;
+use OCP\SetupCheck\SetupResult;
+use Test\TestCase;
+
+/**
+ * @group DB
+ */
+class SupportedDatabaseTest extends TestCase {
+ private IL10N $l10n;
+ private IUrlGenerator $urlGenerator;
+ private IDBConnection $connection;
+
+ private SupportedDatabase $check;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->connection = Server::get(IDBConnection::class);
+
+ $this->check = new SupportedDatabase(
+ $this->l10n,
+ $this->urlGenerator,
+ Server::get(IDBConnection::class)
+ );
+ }
+
+ public function testPass(): void {
+ if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
+ /** SQlite always gets a warning */
+ $this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
+ } else {
+ $this->assertContains($this->check->run()->getSeverity(), [SetupResult::SUCCESS, SetupResult::INFO]);
+ }
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php b/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php
new file mode 100644
index 00000000000..6375d9f6e7f
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php
@@ -0,0 +1,73 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests;
+
+use OCA\Settings\SetupChecks\TaskProcessingPickupSpeed;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IL10N;
+use OCP\SetupCheck\SetupResult;
+use OCP\TaskProcessing\IManager;
+use OCP\TaskProcessing\Task;
+use Test\TestCase;
+
+class TaskProcessingPickupSpeedTest extends TestCase {
+ private IL10N $l10n;
+ private ITimeFactory $timeFactory;
+ private IManager $taskProcessingManager;
+
+ private TaskProcessingPickupSpeed $check;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
+ $this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock();
+ $this->taskProcessingManager = $this->getMockBuilder(IManager::class)->getMock();
+
+ $this->check = new TaskProcessingPickupSpeed(
+ $this->l10n,
+ $this->taskProcessingManager,
+ $this->timeFactory,
+ );
+ }
+
+ public function testPass(): void {
+ $tasks = [];
+ for ($i = 0; $i < 100; $i++) {
+ $task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
+ $task->setStartedAt(0);
+ if ($i < 15) {
+ $task->setScheduledAt(60 * 5); // 15% get 5mins
+ } else {
+ $task->setScheduledAt(60); // the rest gets 1min
+ }
+ $tasks[] = $task;
+ }
+ $this->taskProcessingManager->method('getTasks')->willReturn($tasks);
+
+ $this->assertEquals(SetupResult::SUCCESS, $this->check->run()->getSeverity());
+ }
+
+ public function testFail(): void {
+ $tasks = [];
+ for ($i = 0; $i < 100; $i++) {
+ $task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
+ $task->setStartedAt(0);
+ if ($i < 30) {
+ $task->setScheduledAt(60 * 5); // 30% get 5mins
+ } else {
+ $task->setScheduledAt(60); // the rest gets 1min
+ }
+ $tasks[] = $task;
+ }
+ $this->taskProcessingManager->method('getTasks')->willReturn($tasks);
+
+ $this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php b/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php
new file mode 100644
index 00000000000..d55835d66fc
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php
@@ -0,0 +1,215 @@
+<?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\WellKnownUrls;
+use OCP\Http\Client\IClientService;
+use OCP\Http\Client\IResponse;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class WellKnownUrlsTest extends TestCase {
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IClientService&MockObject $clientService;
+ private LoggerInterface&MockObject $logger;
+ private WellKnownUrls&MockObject $setupcheck;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ /** @var IL10N&MockObject */
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+
+ $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->setupcheck = $this->getMockBuilder(WellKnownUrls::class)
+ ->onlyMethods(['runRequest'])
+ ->setConstructorArgs([
+ $this->l10n,
+ $this->config,
+ $this->urlGenerator,
+ $this->clientService,
+ $this->logger,
+ ])
+ ->getMock();
+ }
+
+ /**
+ * Test that the SetupCheck is skipped if the system config is set
+ */
+ public function testDisabled(): void {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('check_for_working_wellknown_setup')
+ ->willReturn(false);
+
+ $this->setupcheck
+ ->expects($this->never())
+ ->method('runRequest');
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(SetupResult::INFO, $result->getSeverity());
+ $this->assertMatchesRegularExpression('/check was skipped/', $result->getDescription());
+ }
+
+ /**
+ * Test what happens if the local server could not be reached (no response from the requests)
+ */
+ public function testNoResponse(): void {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('check_for_working_wellknown_setup')
+ ->willReturn(true);
+
+ $this->setupcheck
+ ->expects($this->once())
+ ->method('runRequest')
+ ->will($this->generate([]));
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals(SetupResult::INFO, $result->getSeverity());
+ $this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
+ }
+
+ /**
+ * Test responses
+ */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestResponses')]
+ public function testResponses($responses, string $expectedSeverity): void {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('check_for_working_wellknown_setup')
+ ->willReturn(true);
+
+ $this->setupcheck
+ ->expects($this->atLeastOnce())
+ ->method('runRequest')
+ ->willReturnOnConsecutiveCalls(...$responses);
+
+ $result = $this->setupcheck->run();
+ $this->assertEquals($expectedSeverity, $result->getSeverity());
+ }
+
+ public function dataTestResponses(): array {
+ $createResponse = function (int $statuscode, array $header = []): IResponse&MockObject {
+ $response = $this->createMock(IResponse::class);
+ $response->expects($this->any())
+ ->method('getStatusCode')
+ ->willReturn($statuscode);
+ $response->expects($this->any())
+ ->method('getHeader')
+ ->willReturnCallback(fn ($name) => $header[$name] ?? '');
+ return $response;
+ };
+
+ $wellKnownHeader = ['X-NEXTCLOUD-WELL-KNOWN' => 'yes'];
+
+ return [
+ 'expected codes' => [
+ [
+ $this->generate([$createResponse(200, $wellKnownHeader)]),
+ $this->generate([$createResponse(200, $wellKnownHeader)]),
+ $this->generate([$createResponse(207)]),
+ $this->generate([$createResponse(207)]),
+ ],
+ SetupResult::SUCCESS,
+ ],
+ 'late response with expected codes' => [
+ [
+ $this->generate([$createResponse(404), $createResponse(200, $wellKnownHeader)]),
+ $this->generate([$createResponse(404), $createResponse(200, $wellKnownHeader)]),
+ $this->generate([$createResponse(404), $createResponse(207)]),
+ $this->generate([$createResponse(404), $createResponse(207)]),
+ ],
+ SetupResult::SUCCESS,
+ ],
+ 'working but disabled webfinger' => [
+ [
+ $this->generate([$createResponse(404, $wellKnownHeader)]),
+ $this->generate([$createResponse(404, $wellKnownHeader)]),
+ $this->generate([$createResponse(207)]),
+ $this->generate([$createResponse(207)]),
+ ],
+ SetupResult::SUCCESS,
+ ],
+ 'unauthorized webdav but with correct configured redirect' => [
+ [
+ $this->generate([$createResponse(404, $wellKnownHeader)]),
+ $this->generate([$createResponse(404, $wellKnownHeader)]),
+ $this->generate([$createResponse(401, ['X-Guzzle-Redirect-History' => 'https://example.com,https://example.com/remote.php/dav/'])]),
+ $this->generate([$createResponse(401, ['X-Guzzle-Redirect-History' => 'https://example.com/remote.php/dav/'])]),
+ ],
+ SetupResult::SUCCESS,
+ ],
+ 'not configured path' => [
+ [
+ $this->generate([$createResponse(404)]),
+ $this->generate([$createResponse(404)]),
+ $this->generate([$createResponse(404)]),
+ $this->generate([$createResponse(404)]),
+ ],
+ SetupResult::WARNING,
+ ],
+ 'Invalid webfinger' => [
+ [
+ $this->generate([$createResponse(404)]),
+ $this->generate([$createResponse(404, $wellKnownHeader)]),
+ $this->generate([$createResponse(207)]),
+ $this->generate([$createResponse(207)]),
+ ],
+ SetupResult::WARNING,
+ ],
+ 'Invalid nodeinfo' => [
+ [
+ $this->generate([$createResponse(404, $wellKnownHeader)]),
+ $this->generate([$createResponse(404)]),
+ $this->generate([$createResponse(207)]),
+ $this->generate([$createResponse(207)]),
+ ],
+ SetupResult::WARNING,
+ ],
+ 'Invalid caldav' => [
+ [
+ $this->generate([$createResponse(404, $wellKnownHeader)]),
+ $this->generate([$createResponse(404, $wellKnownHeader)]),
+ $this->generate([$createResponse(404)]),
+ $this->generate([$createResponse(207)]),
+ ],
+ SetupResult::WARNING,
+ ],
+ ];
+ }
+
+ /**
+ * Helper function creates a nicer interface for mocking Generator behavior
+ */
+ protected function generate(array $yield_values) {
+ return $this->returnCallback(function () use ($yield_values) {
+ yield from $yield_values;
+ });
+ }
+}
diff --git a/apps/settings/tests/UserMigration/AccountMigratorTest.php b/apps/settings/tests/UserMigration/AccountMigratorTest.php
new file mode 100644
index 00000000000..b8f8301f777
--- /dev/null
+++ b/apps/settings/tests/UserMigration/AccountMigratorTest.php
@@ -0,0 +1,165 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\UserMigration;
+
+use OCA\Settings\AppInfo\Application;
+use OCA\Settings\UserMigration\AccountMigrator;
+use OCP\Accounts\IAccountManager;
+use OCP\AppFramework\App;
+use OCP\IAvatarManager;
+use OCP\IConfig;
+use OCP\IUserManager;
+use OCP\Server;
+use OCP\UserMigration\IExportDestination;
+use OCP\UserMigration\IImportSource;
+use PHPUnit\Framework\Constraint\JsonMatches;
+use PHPUnit\Framework\MockObject\MockObject;
+use Sabre\VObject\UUIDUtil;
+use Symfony\Component\Console\Output\OutputInterface;
+use Test\TestCase;
+
+/**
+ * @group DB
+ */
+class AccountMigratorTest extends TestCase {
+ private IUserManager $userManager;
+ private IAvatarManager $avatarManager;
+ private AccountMigrator $migrator;
+ private IImportSource&MockObject $importSource;
+ private IExportDestination&MockObject $exportDestination;
+ private OutputInterface&MockObject $output;
+
+ private const ASSETS_DIR = __DIR__ . '/assets/';
+
+ private const REGEX_ACCOUNT_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/';
+
+ private const REGEX_AVATAR_FILE = '/^' . Application::APP_ID . '\/' . 'avatar\.(jpg|png)' . '$/';
+
+ private const REGEX_CONFIG_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/';
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $app = new App(Application::APP_ID);
+ $container = $app->getContainer();
+ $container->get(IConfig::class)->setSystemValue('has_internet_connection', false);
+
+ $this->userManager = $container->get(IUserManager::class);
+ $this->avatarManager = $container->get(IAvatarManager::class);
+ $this->migrator = $container->get(AccountMigrator::class);
+
+ $this->importSource = $this->createMock(IImportSource::class);
+ $this->exportDestination = $this->createMock(IExportDestination::class);
+ $this->output = $this->createMock(OutputInterface::class);
+ }
+
+ protected function tearDown(): void {
+ Server::get(IConfig::class)->setSystemValue('has_internet_connection', true);
+ parent::tearDown();
+ }
+
+ public static function dataImportExportAccount(): array {
+ return array_map(
+ static function (string $filename): array {
+ $dataPath = static::ASSETS_DIR . $filename;
+ // For each account json file there is an avatar image and a config json file with the same basename
+ $basename = pathinfo($filename, PATHINFO_FILENAME);
+ $avatarPath = static::ASSETS_DIR . (file_exists(static::ASSETS_DIR . "$basename.jpg") ? "$basename.jpg" : "$basename.png");
+ $configPath = static::ASSETS_DIR . "$basename-config." . pathinfo($filename, PATHINFO_EXTENSION);
+ return [
+ UUIDUtil::getUUID(),
+ json_decode(file_get_contents($dataPath), true, 512, JSON_THROW_ON_ERROR),
+ $avatarPath,
+ json_decode(file_get_contents($configPath), true, 512, JSON_THROW_ON_ERROR),
+ ];
+ },
+ array_filter(
+ scandir(static::ASSETS_DIR),
+ fn (string $filename) => pathinfo($filename, PATHINFO_EXTENSION) === 'json' && mb_strpos(pathinfo($filename, PATHINFO_FILENAME), 'config') === false,
+ ),
+ );
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataImportExportAccount')]
+ public function testImportExportAccount(string $userId, array $importData, string $avatarPath, array $importConfig): void {
+ $user = $this->userManager->createUser($userId, 'topsecretpassword');
+ $avatarExt = pathinfo($avatarPath, PATHINFO_EXTENSION);
+ $exportData = $importData;
+ $exportConfig = $importConfig;
+ // Verification status of email will be set to in progress on import so we set the export data to reflect that
+ $exportData[IAccountManager::PROPERTY_EMAIL]['verified'] = IAccountManager::VERIFICATION_IN_PROGRESS;
+
+ $this->importSource
+ ->expects($this->once())
+ ->method('getMigratorVersion')
+ ->with($this->migrator->getId())
+ ->willReturn(1);
+
+ $calls = [
+ [static::REGEX_ACCOUNT_FILE, json_encode($importData)],
+ [static::REGEX_CONFIG_FILE, json_encode($importConfig)],
+ ];
+ $this->importSource
+ ->expects($this->exactly(2))
+ ->method('getFileContents')
+ ->willReturnCallback(function ($path) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertMatchesRegularExpression($expected[0], $path);
+ return $expected[1];
+ });
+
+ $this->importSource
+ ->expects($this->once())
+ ->method('getFolderListing')
+ ->with(Application::APP_ID . '/')
+ ->willReturn(["avatar.$avatarExt"]);
+
+ $this->importSource
+ ->expects($this->once())
+ ->method('getFileAsStream')
+ ->with($this->matchesRegularExpression(static::REGEX_AVATAR_FILE))
+ ->willReturn(fopen($avatarPath, 'r'));
+
+ $this->migrator->import($user, $this->importSource, $this->output);
+
+ $importedAvatar = $this->avatarManager->getAvatar($user->getUID());
+ $this->assertTrue($importedAvatar->isCustomAvatar());
+
+ /**
+ * Avatar images are re-encoded on import therefore JPEG images which use lossy compression cannot be checked for equality
+ * @see https://github.com/nextcloud/server/blob/9644b7e505dc90a1e683f77ad38dc6dc4e90fa2f/lib/private/legacy/OC_Image.php#L383-L390
+ */
+
+ if ($avatarExt !== 'jpg') {
+ $this->assertStringEqualsFile(
+ $avatarPath,
+ $importedAvatar->getFile(-1)->getContent(),
+ );
+ }
+
+ $calls = [
+ [static::REGEX_ACCOUNT_FILE, new JsonMatches(json_encode($importData))],
+ [static::REGEX_CONFIG_FILE,new JsonMatches(json_encode($importConfig))],
+ ];
+ $this->exportDestination
+ ->expects($this->exactly(2))
+ ->method('addFileContents')
+ ->willReturnCallback(function ($path) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertMatchesRegularExpression($expected[0], $path);
+ return $expected[1];
+ });
+
+ $this->exportDestination
+ ->expects($this->once())
+ ->method('addFileAsStream')
+ ->with($this->matchesRegularExpression(static::REGEX_AVATAR_FILE), $this->isType('resource'));
+
+ $this->migrator->export($user, $this->exportDestination, $this->output);
+ }
+}
diff --git a/apps/settings/tests/UserMigration/assets/account-complex-config.json b/apps/settings/tests/UserMigration/assets/account-complex-config.json
new file mode 100644
index 00000000000..fecf819057c
--- /dev/null
+++ b/apps/settings/tests/UserMigration/assets/account-complex-config.json
@@ -0,0 +1 @@
+{"address":{"visibility":"show_users_only"},"avatar":{"visibility":"show_users_only"},"biography":{"visibility":"show"},"displayname":{"visibility":"show"},"fediverse":{"visibility":"show_users_only"},"headline":{"visibility":"show"},"organisation":{"visibility":"show"},"role":{"visibility":"show"},"email":{"visibility":"hide"},"phone":{"visibility":"hide"},"twitter":{"visibility":"show_users_only"},"website":{"visibility":"show_users_only"},"talk":{"visibility":"show"},"birthdate":{"visibility":"show_users_only"},"pronouns":{"visibility":"show"}} \ No newline at end of file
diff --git a/apps/settings/tests/UserMigration/assets/account-complex.jpg b/apps/settings/tests/UserMigration/assets/account-complex.jpg
new file mode 100644
index 00000000000..94508343322
--- /dev/null
+++ b/apps/settings/tests/UserMigration/assets/account-complex.jpg
Binary files differ
diff --git a/apps/settings/tests/UserMigration/assets/account-complex.json b/apps/settings/tests/UserMigration/assets/account-complex.json
new file mode 100644
index 00000000000..cb4668cf18c
--- /dev/null
+++ b/apps/settings/tests/UserMigration/assets/account-complex.json
@@ -0,0 +1 @@
+{"displayname":{"name":"displayname","value":"Steve Smith","scope":"v2-local","verified":"0","verificationData":""},"address":{"name":"address","value":"123 Water St","scope":"v2-local","verified":"0","verificationData":""},"website":{"name":"website","value":"https://example.org","scope":"v2-local","verified":"0","verificationData":""},"email":{"name":"email","value":"steve@example.org","scope":"v2-federated","verified":"1","verificationData":""},"avatar":{"name":"avatar","value":"","scope":"v2-local","verified":"0","verificationData":""},"phone":{"name":"phone","value":"+12178515387","scope":"v2-private","verified":"0","verificationData":""},"twitter":{"name":"twitter","value":"steve","scope":"v2-federated","verified":"0","verificationData":""},"fediverse":{"name":"fediverse","value":"steve@floss.social","scope":"v2-federated","verified":"0","verificationData":""},"organisation":{"name":"organisation","value":"Mytery Machine","scope":"v2-private","verified":"0","verificationData":""},"role":{"name":"role","value":"Manager","scope":"v2-private","verified":"0","verificationData":""},"headline":{"name":"headline","value":"I am Steve","scope":"v2-local","verified":"0","verificationData":""},"biography":{"name":"biography","value":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris porttitor ullamcorper dictum. Sed fermentum ut ligula scelerisque semper. Aliquam interdum convallis tellus eu dapibus. Integer in justo sollicitudin, hendrerit ligula sit amet, blandit sem.\n\nSuspendisse consectetur ultrices accumsan. Quisque sagittis bibendum lectus ut placerat. Mauris tincidunt ornare neque, et pulvinar tortor porttitor eu.","scope":"v2-local","verified":"0","verificationData":""},"birthdate":{"name":"birthdate","value":"","scope":"v2-local","verified":"0","verificationData":""},"profile_enabled":{"name":"profile_enabled","value":"1","scope":"v2-local","verified":"0","verificationData":""},"pronouns":{"name":"pronouns","value":"they/them","scope":"v2-local","verified":"0","verificationData":""},"additional_mail":[{"name":"additional_mail","value":"steve@example.com","scope":"v2-published","verified":"0","verificationData":""},{"name":"additional_mail","value":"steve@earth.world","scope":"v2-local","verified":"0","verificationData":""}]} \ No newline at end of file
diff --git a/apps/settings/tests/UserMigration/assets/account-config.json b/apps/settings/tests/UserMigration/assets/account-config.json
new file mode 100644
index 00000000000..a1250fab8e9
--- /dev/null
+++ b/apps/settings/tests/UserMigration/assets/account-config.json
@@ -0,0 +1 @@
+{"address":{"visibility":"show_users_only"},"avatar":{"visibility":"show"},"biography":{"visibility":"show"},"displayname":{"visibility":"show"},"fediverse":{"visibility":"show"},"headline":{"visibility":"show"},"organisation":{"visibility":"show"},"role":{"visibility":"show"},"email":{"visibility":"show_users_only"},"phone":{"visibility":"show_users_only"},"twitter":{"visibility":"show"},"website":{"visibility":"show"},"birthdate":{"visibility":"show"},"pronouns":{"visibility":"show"}} \ No newline at end of file
diff --git a/apps/settings/tests/UserMigration/assets/account.json b/apps/settings/tests/UserMigration/assets/account.json
new file mode 100644
index 00000000000..6bdc3c72d47
--- /dev/null
+++ b/apps/settings/tests/UserMigration/assets/account.json
@@ -0,0 +1 @@
+{"displayname":{"name":"displayname","value":"Emma Jones","scope":"v2-federated","verified":"0","verificationData":""},"address":{"name":"address","value":"920 Grass St","scope":"v2-local","verified":"0","verificationData":""},"website":{"name":"website","value":"","scope":"v2-local","verified":"0","verificationData":""},"email":{"name":"email","value":"","scope":"v2-federated","verified":"1","verificationData":""},"avatar":{"name":"avatar","value":"","scope":"v2-federated","verified":"0","verificationData":""},"phone":{"name":"phone","value":"","scope":"v2-local","verified":"0","verificationData":""},"twitter":{"name":"twitter","value":"","scope":"v2-local","verified":"0","verificationData":""},"fediverse":{"name":"fediverse","value":"","scope":"v2-local","verified":"0","verificationData":""},"organisation":{"name":"organisation","value":"","scope":"v2-local","verified":"0","verificationData":""},"role":{"name":"role","value":"","scope":"v2-local","verified":"0","verificationData":""},"headline":{"name":"headline","value":"","scope":"v2-local","verified":"0","verificationData":""},"biography":{"name":"biography","value":"","scope":"v2-local","verified":"0","verificationData":""},"birthdate":{"name":"birthdate","value":"","scope":"v2-local","verified":"0","verificationData":""},"profile_enabled":{"name":"profile_enabled","value":"1","scope":"v2-local","verified":"0","verificationData":""},"pronouns":{"name":"pronouns","value":"","scope":"v2-federated","verified":"0","verificationData":""},"additional_mail":[]} \ No newline at end of file
diff --git a/apps/settings/tests/UserMigration/assets/account.png b/apps/settings/tests/UserMigration/assets/account.png
new file mode 100644
index 00000000000..41c4924e569
--- /dev/null
+++ b/apps/settings/tests/UserMigration/assets/account.png
Binary files differ