[TASK] Set FE/loginSecurityLevel to normal for no ext:rsaauth loaded 29/58429/12
authorAnja <aleichsenring@ab-softlab.de>
Fri, 28 Sep 2018 10:44:30 +0000 (12:44 +0200)
committerJan Helke <typo3@helke.de>
Sat, 29 Sep 2018 09:14:57 +0000 (11:14 +0200)
Provide a silent upgrader the same way as for BE/loginSecurityLevel
to avoid FE login to fail after upgrade.

Change-Id: I8c27c370206effc1f88fd5334b9f20f01a628757
Resolves: #86417
Releases: master
Reviewed-on: https://review.typo3.org/58429
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Tested-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php
typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php

index 501eb07..b72234a 100644 (file)
@@ -152,6 +152,7 @@ class SilentConfigurationUpgradeService
     {
         $this->generateEncryptionKeyIfNeeded();
         $this->configureBackendLoginSecurity();
+        $this->configureFrontendLoginSecurity();
         $this->migrateImageProcessorSetting();
         $this->transferHttpSettings();
         $this->disableImageMagickDetailSettingsIfImageMagickIsDisabled();
@@ -219,6 +220,26 @@ class SilentConfigurationUpgradeService
     }
 
     /**
+     * Frontend login security is set to normal in case
+     * any other value is set while ext:rsaauth is not loaded.
+     *
+     * @throws ConfigurationChangedException
+     */
+    protected function configureFrontendLoginSecurity()
+    {
+        $rsaauthLoaded = ExtensionManagementUtility::isLoaded('rsaauth');
+        try {
+            $currentLoginSecurityLevelValue = $this->configurationManager->getLocalConfigurationValueByPath('FE/loginSecurityLevel');
+            if (!$rsaauthLoaded && $currentLoginSecurityLevelValue !== 'normal') {
+                $this->configurationManager->setLocalConfigurationValueByPath('FE/loginSecurityLevel', 'normal');
+                $this->throwConfigurationChangedException();
+            }
+        } catch (MissingArrayPathException $e) {
+            // no value set, just ignore
+        }
+    }
+
+    /**
      * The encryption key is crucial for securing form tokens
      * and the whole TYPO3 link rendering later on. A random key is set here in
      * LocalConfiguration if it does not exist yet. This might possible happen
index 34cfe34..5504485 100644 (file)
@@ -116,7 +116,7 @@ class SilentConfigurationUpgradeServiceTest extends UnitTestCase
             ['BE/loginSecurityLevel', $current]
         ];
         $closure = function () {
-            throw new MissingArrayPathException('Path does not exist in array', 1476109311);
+            throw new MissingArrayPathException('Path does not exist in array', 1538160231);
         };
 
         $this->createConfigurationManagerWithMockedMethods(
@@ -146,6 +146,81 @@ class SilentConfigurationUpgradeServiceTest extends UnitTestCase
     }
 
     /**
+     * Dataprovider for configureBackendLoginSecurity
+     *
+     * @return array
+     */
+    public function configureFrontendLoginSecurityLocalconfiguration(): array
+    {
+        return [
+            ['', 'rsa', true, false],
+            ['normal', 'rsa', true, true],
+            ['rsa', 'normal', false, true],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider configureFrontendLoginSecurityLocalconfiguration
+     * @param string $current
+     * @param string $setting
+     * @param bool $isPackageActive
+     * @param bool $hasLocalConfig
+     */
+    public function configureFrontendLoginSecurity($current, $setting, $isPackageActive, $hasLocalConfig)
+    {
+        /** @var $silentConfigurationUpgradeServiceInstance SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
+        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
+            SilentConfigurationUpgradeService::class,
+            ['dummy'],
+            [],
+            '',
+            false
+        );
+
+        /** @var $packageManager PackageManager|\PHPUnit_Framework_MockObject_MockObject */
+        $packageManager = $this->createMock(PackageManager::class);
+        $packageManager->expects($this->any())
+            ->method('isPackageActive')
+            ->will($this->returnValue($isPackageActive));
+        ExtensionManagementUtility::setPackageManager($packageManager);
+
+        $currentLocalConfiguration = [
+            ['FE/loginSecurityLevel', $current]
+        ];
+        $closure = function () {
+            throw new MissingArrayPathException('Path does not exist in array', 1476109311);
+        };
+
+        $this->createConfigurationManagerWithMockedMethods(
+            [
+                'getLocalConfigurationValueByPath',
+                'setLocalConfigurationValueByPath',
+            ]
+        );
+        if ($hasLocalConfig) {
+            $this->configurationManager->expects($this->once())
+                ->method('getLocalConfigurationValueByPath')
+                ->will($this->returnValueMap($currentLocalConfiguration));
+        } else {
+            $this->configurationManager->expects($this->once())
+                ->method('getLocalConfigurationValueByPath')
+                ->will($this->returnCallback($closure));
+        }
+        if ($isPackageActive === false) {
+            $this->configurationManager->expects($this->once())
+                ->method('setLocalConfigurationValueByPath')
+                ->with($this->equalTo('FE/loginSecurityLevel'), $this->equalTo($setting));
+
+            $this->expectException(ConfigurationChangedException::class);
+        }
+
+        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
+
+        $silentConfigurationUpgradeServiceInstance->_call('configureFrontendLoginSecurity');
+    }
+
+    /**
      * @test
      */
     public function removeObsoleteLocalConfigurationSettingsIfThereAreOldSettings()