‪TYPO3CMS  11.5
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 ‪$backendUserFixture = __DIR__ . '/Fixtures/be_users.xml';
33 
37  protected ‪$authenticationService;
38 
42  protected ‪$subject;
43 
48  protected function ‪setUp(): void
49  {
50  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName'] = 'be_typo_user';
51  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'] = '';
52  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'] = 4;
53  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIPv6'] = 8;
54  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'] = 28800;
55 
56  $this->subject = new ‪BackendUserAuthentication();
57  parent::setUp();
58  $this->importCSVDataSet(__DIR__ . '/Fixtures/be_groups.csv');
59  $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv');
60  $this->setUpBackendUserFromFixture(2);
62  $backendUser = ‪$GLOBALS['BE_USER'];
63  $this->subject = $backendUser;
64  }
65 
70  {
71  $result = $this->subject->isInWebMount(2);
72  self::assertNotNull($result);
73  }
74 
79  {
80  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = "custom.generic = installation-wide-configuration\ncustom.property = from configuration";
81  $this->subject->user['realName'] = 'Test user';
82  $this->subject->user['TSconfig'] = 'custom.property = from user';
83  $this->subject->userGroupsUID[] = 13;
84  $this->subject->userGroups[13]['TSconfig'] = "custom.property = from group\ncustom.groupProperty = 13";
85  $this->subject->fetchGroupData();
86  $result = $this->subject->getTSConfig();
87  self::assertEquals($this->subject->user['realName'], $result['TCAdefaults.']['sys_note.']['author']);
88  self::assertEquals('from user', $result['custom.']['property']);
89  self::assertEquals('13', $result['custom.']['groupProperty']);
90  self::assertEquals('installation-wide-configuration', $result['custom.']['generic']);
91  }
92 
96  public function ‪returnWebmountsFilterOutInaccessiblePages(): void
97  {
98  $result = $this->subject->returnWebmounts();
99 
100  self::assertNotContains('3', $result, 'Deleted page is not filtered out');
101  self::assertNotContains('4', $result, 'Page user has no permission to read is not filtered out');
102  self::assertNotContains('5', $result, 'Not existing page is not filtered out');
103  self::assertContains('40', $result, 'Accessible db mount page, child of a not accessible page is not shown');
104  self::assertEquals(['1', '40'], $result);
105  }
106 
111  {
112  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_file_storage.xml');
113  $path = 'user_upload/some-folder-that-does-not-exist';
114  $fullPathToStorageBase = ‪Environment::getPublicPath() . '/fileadmin/' . $path;
115  ‪GeneralUtility::rmdir($fullPathToStorageBase);
116  // Skip access permissions, as this is not checked here
117  $this->subject->user['admin'] = 1;
118  $this->subject->user['TSconfig'] = 'options.defaultUploadFolder = 1:/' . $path;
119  $this->subject->fetchGroupData();
120  $folder = $this->subject->getDefaultUploadFolder();
121  self::assertEquals('/user_upload/', $folder->getIdentifier());
122  // Now create the folder and check again
123  ‪GeneralUtility::mkdir_deep($fullPathToStorageBase);
124  $folder = $this->subject->getDefaultUploadFolder();
125  self::assertEquals('/' . $path . '/', $folder->getIdentifier());
126  }
127 
131  public function ‪loadGroupsWithProperSettingsAndOrder(): void
132  {
133  ‪$subject = $this->setUpBackendUser(3);
135  self::assertEquals('web_info,web_layout,web_list,file_filelist', ‪$subject->groupData['modules']);
136  self::assertEquals([1, 4, 5, 3, 2, 6], ‪$subject->userGroupsUID);
137  self::assertEquals(['groupValue' => 'from_group_6', 'userValue' => 'from_user_3'], ‪$subject->‪getTSConfig()['test.']['default.']);
138  }
139 
143  public function ‪mfaRequiredExceptionIsThrown(): void
144  {
145  $this->expectException(MfaRequiredException::class);
146  // This will setup a user and therefore implicit call the ->checkAuthentication() method
147  // which should fail since the user in the fixture has MFA activated but not yet passed.
148  $this->setUpBackendUser(4);
149  }
150 
151  public function ‪isImportEnabledDataProvider(): array
152  {
153  return [
154  'admin user' => [
155  1,
156  '',
157  true,
158  ],
159  'editor user' => [
160  2,
161  '',
162  false,
163  ],
164  'editor user - enableImportForNonAdminUser = 1' => [
165  2,
166  'options.impexp.enableImportForNonAdminUser = 1',
167  true,
168  ],
169  ];
170  }
171 
176  public function ‪isImportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected): void
177  {
178  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = $tsConfig;
179 
180  ‪$subject = $this->setUpBackendUser($userId);
181  self::assertEquals($expected, ‪$subject->‪isImportEnabled());
182  }
183 
184  public function ‪isExportEnabledDataProvider(): array
185  {
186  return [
187  'admin user' => [
188  1,
189  '',
190  true,
191  ],
192  'editor user' => [
193  2,
194  '',
195  false,
196  ],
197  'editor user - enableExportForNonAdminUser = 1' => [
198  2,
199  'options.impexp.enableExportForNonAdminUser = 1',
200  true,
201  ],
202  ];
203  }
204 
209  public function ‪isExportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected): void
210  {
211  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = $tsConfig;
212 
213  ‪$subject = $this->setUpBackendUser($userId);
214  self::assertEquals($expected, ‪$subject->‪isExportEnabled());
215  }
216 }
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getDefaultUploadFolderFallsBackToDefaultStorage
‪getDefaultUploadFolderFallsBackToDefaultStorage()
Definition: BackendUserAuthenticationTest.php:108
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:206
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:1000
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$subject
‪BackendUserAuthentication $subject
Definition: BackendUserAuthenticationTest.php:40
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\fetchGroupData
‪fetchGroupData()
Definition: BackendUserAuthentication.php:1092
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$backendUserFixture
‪$backendUserFixture
Definition: BackendUserAuthenticationTest.php:32
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isExportEnabledReturnsExpectedValues
‪isExportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected)
Definition: BackendUserAuthenticationTest.php:207
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\userTsConfigIsResolvedProperlyWithPrioritization
‪userTsConfigIsResolvedProperlyWithPrioritization()
Definition: BackendUserAuthenticationTest.php:76
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledDataProvider
‪isImportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:149
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$authenticationService
‪AuthenticationService $authenticationService
Definition: BackendUserAuthenticationTest.php:36
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:1908
‪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\isExportEnabledDataProvider
‪isExportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:182
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\setUp
‪setUp()
Definition: BackendUserAuthenticationTest.php:46
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\loadGroupsWithProperSettingsAndOrder
‪loadGroupsWithProperSettingsAndOrder()
Definition: BackendUserAuthenticationTest.php:129
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getTranslatedPageOnWebMountIsInWebMountForNonAdminUser
‪getTranslatedPageOnWebMountIsInWebMountForNonAdminUser()
Definition: BackendUserAuthenticationTest.php:67
‪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:43
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir($path, $removeNonEmpty=false)
Definition: GeneralUtility.php:1961
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isExportEnabled
‪isExportEnabled()
Definition: BackendUserAuthentication.php:2370
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\mfaRequiredExceptionIsThrown
‪mfaRequiredExceptionIsThrown()
Definition: BackendUserAuthenticationTest.php:141
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledReturnsExpectedValues
‪isImportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected)
Definition: BackendUserAuthenticationTest.php:174
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isImportEnabled
‪isImportEnabled()
Definition: BackendUserAuthentication.php:2359
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\returnWebmountsFilterOutInaccessiblePages
‪returnWebmountsFilterOutInaccessiblePages()
Definition: BackendUserAuthenticationTest.php:94