[BUGFIX] Fix inconsistencies in getTSConfig in BackenuserAuth 32/23032/4
authorHelmut Hummel <helmut.hummel@typo3.org>
Sat, 10 Aug 2013 21:18:05 +0000 (23:18 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Mon, 12 Aug 2013 19:02:07 +0000 (21:02 +0200)
BackenuserAuthentication::getTSConfig() behaves
inconsistently when an object string is given with
multiple sections but no result in the actual TSConfig
of the user. Other than noted in the method declaration,
the method returns an empty array instead of an array
where the 'properties' key is null.

Additionally we fix a bug which caused wrong results
if "0" was used as a key in configuration and accessed
with something like "permissions.file.0"

Resolves: #51007
Releases: 6.0, 6.1, 6.2
Change-Id: I80fc7398c1955ff77d052377e3ba81bb8aea01cf
Reviewed-on: https://review.typo3.org/23032
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php
typo3/sysext/core/Tests/Unit/Authentication/BackendUserAuthenticationTest.php

index 4fd8ede..ef804e0 100644 (file)
@@ -1131,11 +1131,11 @@ class BackendUserAuthentication extends \TYPO3\CMS\Core\Authentication\AbstractU
                        // Getting Root-ts if not sent
                        $config = $this->userTS;
                }
-               $TSConf = array();
-               $parts = explode('.', $objectString, 2);
+               $TSConf = array('value' => NULL, 'properties' => NULL);
+               $parts = GeneralUtility::trimExplode('.', $objectString, TRUE, 2);
                $key = $parts[0];
-               if (trim($key)) {
-                       if (count($parts) > 1 && trim($parts[1])) {
+               if (strlen($key) > 0) {
+                       if (count($parts) > 1 && strlen($parts[1]) > 0) {
                                // Go on, get the next level
                                if (is_array($config[$key . '.'])) {
                                        $TSConf = $this->getTSConfig($parts[1], $config[$key . '.']);
index caee5c8..5fafd51 100644 (file)
@@ -60,6 +60,158 @@ class BackendUserAuthenticationTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->fixture->logoff();
        }
 
+       /**
+        * @return array
+        */
+       public function getTSConfigDataProvider() {
+
+               $completeConfiguration = array(
+                       'value' => 'oneValue',
+                       'value.' => array('oneProperty' => 'oneValue'),
+                       'permissions.' => array(
+                               'file.' => array(
+                                       'default.' => array('readAction' => '1'),
+                                       '1.' => array('writeAction' => '1'),
+                                       '0.' => array('readAction' => '0'),
+                               ),
+                       )
+               );
+
+               return array(
+                       'single level string' => array(
+                               $completeConfiguration,
+                               'permissions',
+                               array(
+                                       'value' => NULL,
+                                       'properties' =>
+                                       array(
+                                               'file.' => array(
+                                                       'default.' => array('readAction' => '1'),
+                                                       '1.' => array('writeAction' => '1'),
+                                                       '0.' => array('readAction' => '0'),
+                                               ),
+                                       ),
+                               ),
+                       ),
+                       'two levels string' => array(
+                               $completeConfiguration,
+                               'permissions.file',
+                               array(
+                                       'value' => NULL,
+                                       'properties' =>
+                                       array(
+                                               'default.' => array('readAction' => '1'),
+                                               '1.' => array('writeAction' => '1'),
+                                               '0.' => array('readAction' => '0'),
+                                       ),
+                               ),
+                       ),
+                       'three levels string' => array(
+                               $completeConfiguration,
+                               'permissions.file.default',
+                               array(
+                                       'value' => NULL,
+                                       'properties' =>
+                                       array('readAction' => '1'),
+                               ),
+                       ),
+                       'three levels string with integer property' => array(
+                               $completeConfiguration,
+                               'permissions.file.1',
+                               array(
+                                       'value' => NULL,
+                                       'properties' => array('writeAction' => '1'),
+                               ),
+                       ),
+                       'three levels string with integer zero property' => array(
+                               $completeConfiguration,
+                               'permissions.file.0',
+                               array(
+                                       'value' => NULL,
+                                       'properties' => array('readAction' => '0'),
+                               ),
+                       ),
+                       'four levels string with integer zero property, value, no properties' => array(
+                               $completeConfiguration,
+                               'permissions.file.0.readAction',
+                               array(
+                                       'value' => '0',
+                                       'properties' => NULL,
+                               ),
+                       ),
+                       'four levels string with integer property, value, no properties' => array(
+                               $completeConfiguration,
+                               'permissions.file.1.writeAction',
+                               array(
+                                       'value' => '1',
+                                       'properties' => NULL,
+                               ),
+                       ),
+                       'one level, not existant string' => array(
+                               $completeConfiguration,
+                               'foo',
+                               array(
+                                       'value' => NULL,
+                                       'properties' => NULL,
+                               ),
+                       ),
+                       'two level, not existant string' => array(
+                               $completeConfiguration,
+                               'foo.bar',
+                               array(
+                                       'value' => NULL,
+                                       'properties' => NULL,
+                               ),
+                       ),
+                       'two level, where second level does not exist' => array(
+                               $completeConfiguration,
+                               'permissions.bar',
+                               array(
+                                       'value' => NULL,
+                                       'properties' => NULL,
+                               ),
+                       ),
+                       'three level, where third level does not exist' => array(
+                               $completeConfiguration,
+                               'permissions.file.foo',
+                               array(
+                                       'value' => NULL,
+                                       'properties' => NULL,
+                               ),
+                       ),
+                       'three level, where second and third level does not exist' => array(
+                               $completeConfiguration,
+                               'permissions.foo.bar',
+                               array(
+                                       'value' => NULL,
+                                       'properties' => NULL,
+                               ),
+                       ),
+                       'value and properties' => array(
+                               $completeConfiguration,
+                               'value',
+                               array(
+                                       'value' => 'oneValue',
+                                       'properties' => array('oneProperty' => 'oneValue'),
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @param array $completeConfiguration
+        * @param string $objectString
+        * @param array $expectedConfiguration
+        * @dataProvider getTSConfigDataProvider
+        * @test
+        */
+       public function getTSConfigReturnsCorrectArrayForGivenObjectString(array $completeConfiguration, $objectString, array $expectedConfiguration) {
+               $this->fixture->userTS = $completeConfiguration;
+
+               $actualConfiguration = $this->fixture->getTSConfig($objectString);
+               $this->assertSame($expectedConfiguration, $actualConfiguration);
+       }
+
 }
 
 ?>
\ No newline at end of file