‪TYPO3CMS  ‪main
BackendUserAuthenticationTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
25 final class ‪BackendUserAuthenticationTest extends FunctionalTestCase
26 {
27  protected array ‪$testExtensionsToLoad = [
28  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_defaulttsconfig',
29  ];
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  $this->importCSVDataSet(__DIR__ . '/Fixtures/be_groups.csv');
35  $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv');
36  $this->importCSVDataSet(__DIR__ . '/Fixtures/be_users.csv');
37  $this->importCSVDataSet(__DIR__ . '/Fixtures/sys_filemounts.csv');
38  $this->importCSVDataSet(__DIR__ . '/../Fixtures/sys_file_storage.csv');
39  }
40 
45  {
46  $backendUser = $this->setUpBackendUser(3);
47  self::assertCount(3, $backendUser->getFileMountRecords());
48  }
49 
54  {
55  $subject = $this->setUpBackendUser(2);
56  self::assertNotNull($subject->isInWebMount(2));
57  }
58 
63  {
64  // Uses ext:test_defaulttsconfig/Configuration/user.tsconfig
65  $subject = $this->setUpBackendUser(2);
66  $subject->user['TSconfig'] = 'custom.property = from user';
67  $subject->userGroupsUID[] = 13;
68  $subject->userGroups[13]['TSconfig'] = "custom.property = from group\ncustom.groupProperty = 13";
69  $subject->fetchGroupData();
70  $result = $subject->getTSConfig();
71  self::assertEquals('from user', $result['custom.']['property']);
72  self::assertEquals('13', $result['custom.']['groupProperty']);
73  self::assertEquals('installation-wide-configuration', $result['custom.']['generic']);
74  }
75 
80  {
81  $subject = $this->setUpBackendUser(2);
82  $result = $subject->returnWebmounts();
83  self::assertNotContains('3', $result, 'Deleted page is not filtered out');
84  self::assertNotContains('4', $result, 'Page user has no permission to read is not filtered out');
85  self::assertNotContains('5', $result, 'Not existing page is not filtered out');
86  self::assertContains('40', $result, 'Accessible db mount page, child of a not accessible page is not shown');
87  self::assertEquals(['1', '40'], $result);
88  }
89 
94  {
95  $path = 'user_upload/some-folder-that-does-not-exist';
96  $fullPathToStorageBase = ‪Environment::getPublicPath() . '/fileadmin/' . $path;
97  ‪GeneralUtility::rmdir($fullPathToStorageBase);
98  // Skip access permissions, as this is not checked here
99  $subject = $this->setUpBackendUser(2);
100  $subject->user['admin'] = 1;
101  $subject->user['TSconfig'] = 'options.defaultUploadFolder = 1:/' . $path;
102  $subject->fetchGroupData();
103  $folder = $subject->getDefaultUploadFolder();
104  self::assertEquals('/user_upload/', $folder->getIdentifier());
105  // Now create the folder and check again
106  ‪GeneralUtility::mkdir_deep($fullPathToStorageBase);
107  $folder = $subject->getDefaultUploadFolder();
108  self::assertEquals('/' . $path . '/', $folder->getIdentifier());
109  }
110 
115  {
116  $subject = $this->setUpBackendUser(3);
117  $subject->fetchGroupData();
118  self::assertEquals('web_info,web_layout,web_list,file_filelist', $subject->groupData['modules']);
119  self::assertEquals([1, 4, 5, 3, 2, 6], $subject->userGroupsUID);
120  self::assertEquals(['groupValue' => 'from_group_6', 'userValue' => 'from_user_3'], $subject->getTSConfig()['test.']['default.']);
121  }
122 
126  public function ‪mfaRequiredExceptionIsThrown(): void
127  {
128  $this->expectException(MfaRequiredException::class);
129  // This will set up a user and therefore implicit call the ->checkAuthentication() method
130  // which should fail since the user in the fixture has MFA activated but not yet passed.
131  $this->setUpBackendUser(4);
132  }
133 
134  public static function ‪isImportEnabledDataProvider(): array
135  {
136  return [
137  'admin user' => [
138  1,
139  true,
140  ],
141  'editor user' => [
142  2,
143  false,
144  ],
145  'editor user - enableImportForNonAdminUser = 1' => [
146  6,
147  true,
148  ],
149  ];
150  }
151 
156  public function ‪isImportEnabledReturnsExpectedValues(int $userId, bool $expected): void
157  {
158  $subject = $this->setUpBackendUser($userId);
159  self::assertEquals($expected, $subject->isImportEnabled());
160  }
161 
162  public static function ‪isExportEnabledDataProvider(): array
163  {
164  return [
165  'admin user' => [
166  1,
167  true,
168  ],
169  'editor user' => [
170  2,
171  false,
172  ],
173  'editor user - enableExportForNonAdminUser = 1' => [
174  6,
175  true,
176  ],
177  ];
178  }
179 
184  public function ‪isExportEnabledReturnsExpectedValues(int $userId, bool $expected): void
185  {
186  $subject = $this->setUpBackendUser($userId);
187  self::assertEquals($expected, $subject->isExportEnabled());
188  }
189 }
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getDefaultUploadFolderFallsBackToDefaultStorage
‪getDefaultUploadFolderFallsBackToDefaultStorage()
Definition: BackendUserAuthenticationTest.php:93
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getFileMountRecordsReturnsFilemounts
‪getFileMountRecordsReturnsFilemounts()
Definition: BackendUserAuthenticationTest.php:44
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\userTsConfigIsResolvedProperlyWithPrioritization
‪userTsConfigIsResolvedProperlyWithPrioritization()
Definition: BackendUserAuthenticationTest.php:62
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledDataProvider
‪static isImportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:134
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledReturnsExpectedValues
‪isImportEnabledReturnsExpectedValues(int $userId, bool $expected)
Definition: BackendUserAuthenticationTest.php:156
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:1638
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest
Definition: BackendUserAuthenticationTest.php:26
‪TYPO3\CMS\Core\Authentication\Mfa\MfaRequiredException
Definition: MfaRequiredException.php:29
‪TYPO3\CMS\Core\Tests\Functional\Authentication
Definition: AbstractUserAuthenticationTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\setUp
‪setUp()
Definition: BackendUserAuthenticationTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\loadGroupsWithProperSettingsAndOrder
‪loadGroupsWithProperSettingsAndOrder()
Definition: BackendUserAuthenticationTest.php:114
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getTranslatedPageOnWebMountIsInWebMountForNonAdminUser
‪getTranslatedPageOnWebMountIsInWebMountForNonAdminUser()
Definition: BackendUserAuthenticationTest.php:53
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: BackendUserAuthenticationTest.php:27
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isExportEnabledReturnsExpectedValues
‪isExportEnabledReturnsExpectedValues(int $userId, bool $expected)
Definition: BackendUserAuthenticationTest.php:184
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isExportEnabledDataProvider
‪static isExportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:162
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir($path, $removeNonEmpty=false)
Definition: GeneralUtility.php:1691
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\mfaRequiredExceptionIsThrown
‪mfaRequiredExceptionIsThrown()
Definition: BackendUserAuthenticationTest.php:126
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\returnWebmountsFilterOutInaccessiblePages
‪returnWebmountsFilterOutInaccessiblePages()
Definition: BackendUserAuthenticationTest.php:79