[BUGFIX] Set FE/loginSecurityLevel to normal for no ext:rsaauth loaded 58/59058/6
authorFlorian Peters <fpeters1392@googlemail.com>
Fri, 7 Dec 2018 19:44:04 +0000 (20:44 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Fri, 7 Dec 2018 20:29:23 +0000 (21:29 +0100)
Provide a silent upgrader the same way as for BE/loginSecurityLevel
to avoid FE login to fail after upgrade.

Resolves: #87103
Releases: 8.7
Related: #86417
Change-Id: Ie2cc2bfe9b542534de6d04259c1e5fc8bcd84fab
Reviewed-on: https://review.typo3.org/59058
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php
typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php

index 529a44a..47f9568 100644 (file)
@@ -109,6 +109,7 @@ class SilentConfigurationUpgradeService
     {
         $this->generateEncryptionKeyIfNeeded();
         $this->configureBackendLoginSecurity();
+        $this->configureFrontendLoginSecurity();
         $this->migrateImageProcessorSetting();
         $this->transferHttpSettings();
         $this->disableImageMagickDetailSettingsIfImageMagickIsDisabled();
@@ -169,6 +170,26 @@ class SilentConfigurationUpgradeService
     }
 
     /**
+     * Frontend login security is set to normal in case
+     * any other value is set while ext:rsaauth is not loaded.
+     *
+     * @throws RedirectException
+     */
+    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->throwRedirectException();
+            }
+        } catch (\RuntimeException $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 11e4566..3fc9689 100644 (file)
@@ -136,6 +136,80 @@ class SilentConfigurationUpgradeServiceTest extends \TYPO3\TestingFramework\Core
     }
 
     /**
+     * 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 \RuntimeException('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) {
+            $this->configurationManager->expects($this->once())
+                ->method('setLocalConfigurationValueByPath')
+                ->with($this->equalTo('FE/loginSecurityLevel'), $this->equalTo($setting));
+            $this->expectException(RedirectException::class);
+        }
+
+        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
+
+        $silentConfigurationUpgradeServiceInstance->_call('configureFrontendLoginSecurity');
+    }
+
+    /**
      * @test
      */
     public function removeObsoleteLocalConfigurationSettingsIfThereAreOldSettings()