‪TYPO3CMS  10.4
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 
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
29 class ‪BackendUserAuthenticationTest extends FunctionalTestCase
30 {
36  protected ‪$backendUserFixture = __DIR__ . '/Fixtures/be_users.xml';
37 
41  protected ‪$authenticationService;
42 
46  protected ‪$subject;
47 
52  protected function ‪setUp(): void
53  {
54  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts'] = 1;
55  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName'] = 'be_typo_user';
56  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'] = '';
57  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'] = 4;
58  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIPv6'] = 8;
59  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'] = 28800;
60 
61  $this->subject = new ‪BackendUserAuthentication();
62  parent::setUp();
63  $this->importDataSet(__DIR__ . '/Fixtures/be_groups.xml');
64  $this->importDataSet(__DIR__ . '/Fixtures/pages.xml');
65  $this->setUpBackendUserFromFixture(2);
67  $this->subject = ‪$GLOBALS['BE_USER'];
68  }
69 
74  {
75  $result = $this->subject->isInWebMount(2);
76  self::assertNotNull($result);
77  }
78 
83  {
84  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = "custom.generic = installation-wide-configuration\ncustom.property = from configuration";
85  $this->subject->user['realName'] = 'Test user';
86  $this->subject->user['TSconfig'] = 'custom.property = from user';
87  $this->subject->includeGroupArray[] = 13;
88  $this->subject->userGroups[13]['TSconfig'] = "custom.property = from group\ncustom.groupProperty = 13";
89  $this->subject->fetchGroupData();
90  $result = $this->subject->getTSConfig();
91  self::assertEquals($this->subject->user['realName'], $result['TCAdefaults.']['sys_note.']['author']);
92  self::assertEquals('from user', $result['custom.']['property']);
93  self::assertEquals('13', $result['custom.']['groupProperty']);
94  self::assertEquals('installation-wide-configuration', $result['custom.']['generic']);
95  }
96 
100  public function ‪returnWebmountsFilterOutInaccessiblePages(): void
101  {
102  $result = $this->subject->returnWebmounts();
103 
104  self::assertNotContains('3', $result, 'Deleted page is not filtered out');
105  self::assertNotContains('4', $result, 'Page user has no permission to read is not filtered out');
106  self::assertNotContains('5', $result, 'Not existing page is not filtered out');
107  self::assertContains('40', $result, 'Accessible db mount page, child of a not accessible page is not shown');
108  self::assertEquals(['1', '40'], $result);
109  }
110 
115  {
116  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_file_storage.xml');
117  $path = 'user_upload/some-folder-that-does-not-exist';
118  $fullPathToStorageBase = ‪Environment::getPublicPath() . '/fileadmin/' . $path;
119  ‪GeneralUtility::rmdir($fullPathToStorageBase);
120  // Skip access permissions, as this is not checked here
121  $this->subject->user['admin'] = 1;
122  $this->subject->user['TSconfig'] = 'options.defaultUploadFolder = 1:/' . $path;
123  $this->subject->fetchGroupData();
124  $folder = $this->subject->getDefaultUploadFolder();
125  self::assertEquals('/user_upload/', $folder->getIdentifier());
126  // Now create the folder and check again
127  ‪GeneralUtility::mkdir_deep($fullPathToStorageBase);
128  $folder = $this->subject->getDefaultUploadFolder();
129  self::assertEquals('/' . $path . '/', $folder->getIdentifier());
130  }
131 
132  public function ‪isImportEnabledDataProvider(): array
133  {
134  return [
135  'admin user' => [
136  1,
137  '',
138  true,
139  ],
140  'editor user' => [
141  2,
142  '',
143  false,
144  ],
145  'editor user - enableImportForNonAdminUser = 1' => [
146  2,
147  'options.impexp.enableImportForNonAdminUser = 1',
148  true,
149  ],
150  ];
151  }
152 
157  public function ‪isImportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected): void
158  {
159  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = $tsConfig;
160 
161  ‪$subject = $this->setUpBackendUser($userId);
162  self::assertEquals($expected, ‪$subject->‪isImportEnabled());
163  }
164 
165  public function ‪isExportEnabledDataProvider(): array
166  {
167  return [
168  'admin user' => [
169  1,
170  '',
171  true,
172  ],
173  'editor user' => [
174  2,
175  '',
176  false,
177  ],
178  'editor user - enableExportForNonAdminUser = 1' => [
179  2,
180  'options.impexp.enableExportForNonAdminUser = 1',
181  true,
182  ],
183  ];
184  }
185 
190  public function ‪isExportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected): void
191  {
192  ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = $tsConfig;
193 
194  ‪$subject = $this->setUpBackendUser($userId);
195  self::assertEquals($expected, ‪$subject->‪isExportEnabled());
196  }
197 }
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getDefaultUploadFolderFallsBackToDefaultStorage
‪getDefaultUploadFolderFallsBackToDefaultStorage()
Definition: BackendUserAuthenticationTest.php:111
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$subject
‪BackendUserAuthentication $subject
Definition: BackendUserAuthenticationTest.php:43
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$backendUserFixture
‪string $backendUserFixture
Definition: BackendUserAuthenticationTest.php:35
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isExportEnabledReturnsExpectedValues
‪isExportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected)
Definition: BackendUserAuthenticationTest.php:187
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\userTsConfigIsResolvedProperlyWithPrioritization
‪userTsConfigIsResolvedProperlyWithPrioritization()
Definition: BackendUserAuthenticationTest.php:79
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledDataProvider
‪isImportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:129
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$authenticationService
‪AuthenticationService $authenticationService
Definition: BackendUserAuthenticationTest.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:2022
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest
Definition: BackendUserAuthenticationTest.php:30
‪TYPO3\CMS\Core\Tests\Functional\Authentication
Definition: AbstractUserAuthenticationTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isExportEnabledDataProvider
‪isExportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:162
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\setUp
‪setUp()
Definition: BackendUserAuthenticationTest.php:49
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getTranslatedPageOnWebMountIsInWebMountForNonAdminUser
‪getTranslatedPageOnWebMountIsInWebMountForNonAdminUser()
Definition: BackendUserAuthenticationTest.php:70
‪TYPO3\CMS\Core\Authentication\AuthenticationService
Definition: AuthenticationService.php:33
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir($path, $removeNonEmpty=false)
Definition: GeneralUtility.php:2075
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isExportEnabled
‪isExportEnabled()
Definition: BackendUserAuthentication.php:2703
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledReturnsExpectedValues
‪isImportEnabledReturnsExpectedValues(int $userId, string $tsConfig, bool $expected)
Definition: BackendUserAuthenticationTest.php:154
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isImportEnabled
‪isImportEnabled()
Definition: BackendUserAuthentication.php:2692
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\returnWebmountsFilterOutInaccessiblePages
‪returnWebmountsFilterOutInaccessiblePages()
Definition: BackendUserAuthenticationTest.php:97