‪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 
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 class ‪BackendUserAuthenticationTest extends FunctionalTestCase
28 {
32  protected ‪$authenticationService;
33 
37  protected ‪$subject;
38 
43  protected function ‪setUp(): void
44  {
45  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName'] = 'be_typo_user';
46  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'] = '';
47  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'] = 4;
48  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIPv6'] = 8;
49  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'] = 28800;
50 
51  $this->subject = new ‪BackendUserAuthentication();
52  parent::setUp();
53  $this->importCSVDataSet(__DIR__ . '/Fixtures/be_groups.csv');
54  $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv');
55  $this->importCSVDataSet(__DIR__ . '/Fixtures/be_users.csv');
56  $this->setUpBackendUser(2);
58  $backendUser = ‪$GLOBALS['BE_USER'];
59  $this->subject = $backendUser;
60  }
61 
66  {
67  $result = $this->subject->isInWebMount(2);
68  self::assertNotNull($result);
69  }
70 
75  {
76  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = "custom.generic = installation-wide-configuration\ncustom.property = from configuration";
77  $this->subject->user['TSconfig'] = 'custom.property = from user';
78  $this->subject->userGroupsUID[] = 13;
79  $this->subject->userGroups[13]['TSconfig'] = "custom.property = from group\ncustom.groupProperty = 13";
80  $this->subject->fetchGroupData();
81  $result = $this->subject->getTSConfig();
82  self::assertEquals('from user', $result['custom.']['property']);
83  self::assertEquals('13', $result['custom.']['groupProperty']);
84  self::assertEquals('installation-wide-configuration', $result['custom.']['generic']);
85  }
86 
90  public function ‪returnWebmountsFilterOutInaccessiblePages(): void
91  {
92  $result = $this->subject->returnWebmounts();
93 
94  self::assertNotContains('3', $result, 'Deleted page is not filtered out');
95  self::assertNotContains('4', $result, 'Page user has no permission to read is not filtered out');
96  self::assertNotContains('5', $result, 'Not existing page is not filtered out');
97  self::assertContains('40', $result, 'Accessible db mount page, child of a not accessible page is not shown');
98  self::assertEquals(['1', '40'], $result);
99  }
100 
105  {
106  $this->importCSVDataSet(__DIR__ . '/../Fixtures/sys_file_storage.csv');
107  $path = 'user_upload/some-folder-that-does-not-exist';
108  $fullPathToStorageBase = ‪Environment::getPublicPath() . '/fileadmin/' . $path;
109  ‪GeneralUtility::rmdir($fullPathToStorageBase);
110  // Skip access permissions, as this is not checked here
111  $this->subject->user['admin'] = 1;
112  $this->subject->user['TSconfig'] = 'options.defaultUploadFolder = 1:/' . $path;
113  $this->subject->fetchGroupData();
114  $folder = $this->subject->getDefaultUploadFolder();
115  self::assertEquals('/user_upload/', $folder->getIdentifier());
116  // Now create the folder and check again
117  ‪GeneralUtility::mkdir_deep($fullPathToStorageBase);
118  $folder = $this->subject->getDefaultUploadFolder();
119  self::assertEquals('/' . $path . '/', $folder->getIdentifier());
120  }
121 
125  public function ‪loadGroupsWithProperSettingsAndOrder(): void
126  {
127  ‪$subject = $this->setUpBackendUser(3);
129  self::assertEquals('web_info,web_layout,web_list,file_filelist', ‪$subject->groupData['modules']);
130  self::assertEquals([1, 4, 5, 3, 2, 6], ‪$subject->userGroupsUID);
131  self::assertEquals(['groupValue' => 'from_group_6', 'userValue' => 'from_user_3'], ‪$subject->‪getTSConfig()['test.']['default.']);
132  }
133 
137  public function ‪mfaRequiredExceptionIsThrown(): void
138  {
139  $this->expectException(MfaRequiredException::class);
140  // This will setup a user and therefore implicit call the ->checkAuthentication() method
141  // which should fail since the user in the fixture has MFA activated but not yet passed.
142  $this->setUpBackendUser(4);
143  }
144 
145  public static function ‪isImportEnabledDataProvider(): array
146  {
147  return [
148  'admin user' => [
149  1,
150  '',
151  true,
152  ],
153  'editor user' => [
154  2,
155  '',
156  false,
157  ],
158  'editor user - enableImportForNonAdminUser = 1' => [
159  2,
160  'options.impexp.enableImportForNonAdminUser = 1',
161  true,
162  ],
163  ];
164  }
165 
170  public function ‪isImportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected): void
171  {
172  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = $tsConfig;
173 
174  ‪$subject = $this->setUpBackendUser($userId);
175  self::assertEquals($expected, ‪$subject->‪isImportEnabled());
176  }
177 
178  public static function ‪isExportEnabledDataProvider(): array
179  {
180  return [
181  'admin user' => [
182  1,
183  '',
184  true,
185  ],
186  'editor user' => [
187  2,
188  '',
189  false,
190  ],
191  'editor user - enableExportForNonAdminUser = 1' => [
192  2,
193  'options.impexp.enableExportForNonAdminUser = 1',
194  true,
195  ],
196  ];
197  }
198 
203  public function ‪isExportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected): void
204  {
205  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = $tsConfig;
206 
207  ‪$subject = $this->setUpBackendUser($userId);
208  self::assertEquals($expected, ‪$subject->‪isExportEnabled());
209  }
210 }
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getDefaultUploadFolderFallsBackToDefaultStorage
‪getDefaultUploadFolderFallsBackToDefaultStorage()
Definition: BackendUserAuthenticationTest.php:102
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:949
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$subject
‪BackendUserAuthentication $subject
Definition: BackendUserAuthenticationTest.php:35
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\fetchGroupData
‪fetchGroupData()
Definition: BackendUserAuthentication.php:1050
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isExportEnabledReturnsExpectedValues
‪isExportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected)
Definition: BackendUserAuthenticationTest.php:201
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\userTsConfigIsResolvedProperlyWithPrioritization
‪userTsConfigIsResolvedProperlyWithPrioritization()
Definition: BackendUserAuthenticationTest.php:72
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledDataProvider
‪static isImportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:143
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$authenticationService
‪AuthenticationService $authenticationService
Definition: BackendUserAuthenticationTest.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:1753
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest
Definition: BackendUserAuthenticationTest.php:28
‪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:41
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\loadGroupsWithProperSettingsAndOrder
‪loadGroupsWithProperSettingsAndOrder()
Definition: BackendUserAuthenticationTest.php:123
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:66
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getTranslatedPageOnWebMountIsInWebMountForNonAdminUser
‪getTranslatedPageOnWebMountIsInWebMountForNonAdminUser()
Definition: BackendUserAuthenticationTest.php:63
‪TYPO3\CMS\Core\Authentication\AuthenticationService
Definition: AuthenticationService.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isExportEnabledDataProvider
‪static isExportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:176
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir($path, $removeNonEmpty=false)
Definition: GeneralUtility.php:1806
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isExportEnabled
‪isExportEnabled()
Definition: BackendUserAuthentication.php:2301
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\mfaRequiredExceptionIsThrown
‪mfaRequiredExceptionIsThrown()
Definition: BackendUserAuthenticationTest.php:135
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledReturnsExpectedValues
‪isImportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected)
Definition: BackendUserAuthenticationTest.php:168
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isImportEnabled
‪isImportEnabled()
Definition: BackendUserAuthentication.php:2290
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\returnWebmountsFilterOutInaccessiblePages
‪returnWebmountsFilterOutInaccessiblePages()
Definition: BackendUserAuthenticationTest.php:88