[TASK] Deprecate GeneralUtility::clientInfo() 09/57909/3
authorBenni Mack <benni@typo3.org>
Wed, 15 Aug 2018 09:08:01 +0000 (11:08 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 15 Aug 2018 17:34:24 +0000 (19:34 +0200)
The functionality for parsing the HTTP_USER_AGENT server variable is only
used in one place within TYPO3 core and can be substituted directly with
the proper HTTP_USER_AGENT string.

Resolves: #85858
Releases: master
Change-Id: Ie299ebbe157f346caa46ac562fb27250f7daf5d3
Reviewed-on: https://review.typo3.org/57909
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-85858-GeneralUtilityclientInfo.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Authentication/AbstractUserAuthenticationTest.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php

index acb853a..83a0e23 100644 (file)
@@ -465,8 +465,8 @@ abstract class AbstractUserAuthentication implements LoggerAwareInterface
         $pragmaHeader = 'no-cache';
         // Prevent error message in IE when using a https connection
         // see http://forge.typo3.org/issues/24125
-        $clientInfo = GeneralUtility::clientInfo();
-        if ($clientInfo['BROWSER'] === 'msie' && GeneralUtility::getIndpEnv('TYPO3_SSL')) {
+        if (strpos(GeneralUtility::getIndpEnv('HTTP_USER_AGENT'), 'MSIE') !== false
+            && GeneralUtility::getIndpEnv('TYPO3_SSL')) {
             // Some IEs can not handle no-cache
             // see http://support.microsoft.com/kb/323308/en-us
             $cacheControlHeader = 'must-revalidate';
index 2d73182..ff8bda3 100644 (file)
@@ -2985,9 +2985,11 @@ class GeneralUtility
      *
      * @param string $useragent Alternative User Agent string (if empty, \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_USER_AGENT') is used)
      * @return array Parsed information about the HTTP_USER_AGENT in categories BROWSER, VERSION, SYSTEM
+     * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0.
      */
     public static function clientInfo($useragent = '')
     {
+        trigger_error('GeneralUtility::clientInfo() will be removed in TYPO3 v10.0. Use your own detection via HTTP_USER_AGENT Server string', E_USER_DEPRECATED);
         if (!$useragent) {
             $useragent = self::getIndpEnv('HTTP_USER_AGENT');
         }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85858-GeneralUtilityclientInfo.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85858-GeneralUtilityclientInfo.rst
new file mode 100644 (file)
index 0000000..18a498e
--- /dev/null
@@ -0,0 +1,40 @@
+.. include:: ../../Includes.txt
+
+==================================================
+Deprecation: #85858 - GeneralUtility::clientInfo()
+==================================================
+
+See :issue:`85858`
+
+Description
+===========
+
+The helper method :php:`GeneralUtility::clientInfo()` responsible for
+parsing the server variable :php:`$_SERVER['HTTP_USER_AGENT']` has been marked
+as deprecated.
+
+This method is not up-to-date with current browser headers, and in light of
+browser that are able to fake the HTTP_USER_AGENT the detection is not practical
+anymore.
+
+
+Impact
+======
+
+Calling the method directly will trigger a deprecation warning.
+
+
+Affected Installations
+======================
+
+Any TYPO3 installation with extensions directly calling this method.
+
+
+Migration
+=========
+
+Depending on the use-case, it is best to use the PSR-7-based request object,
+if available in the context, or `$_SERVER['HTTP_USER_AGENT']` to detect a
+specific browser/client user agent.
+
+.. index:: PHP-API, FullyScanned, ext:core
\ No newline at end of file
index 56f3eec..097b481 100644 (file)
@@ -68,4 +68,30 @@ class AbstractUserAuthenticationTest extends UnitTestCase
         $result = $mock->getAuthInfoArray();
         $this->assertEquals('', $result['db_user']['checkPidList']);
     }
+
+    /**
+     * @test
+     */
+    public function getHttpHeadersReturnsNormalNoCacheHeadersForNonIe()
+    {
+        GeneralUtility::flushInternalRuntimeCaches();
+        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 6.2; rv:22.0) Gecko/20130405 Firefox/23.0';
+        $_SERVER['HTTPS'] = 'on';
+        $subject = $this->getAccessibleMockForAbstractClass(AbstractUserAuthentication::class);
+        $result = $subject->_call('getHttpHeaders');
+        $this->assertEquals($result['Pragma'], 'no-cache');
+    }
+
+    /**
+     * @test
+     */
+    public function getHttpHeadersReturnsSpecialNoCacheHeadersForIe()
+    {
+        GeneralUtility::flushInternalRuntimeCaches();
+        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US)';
+        $_SERVER['HTTPS'] = 'on';
+        $subject = $this->getAccessibleMockForAbstractClass(AbstractUserAuthentication::class);
+        $result = $subject->_call('getHttpHeaders');
+        $this->assertEquals($result['Pragma'], 'private');
+    }
 }
index 4ec3be3..a124768 100644 (file)
@@ -729,4 +729,11 @@ return [
             'Deprecation-85836-DeprecateBackendUtilitygetTCAtypes.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Utility\GeneralUtility::clientInfo' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 1,
+        'restFiles' => [
+            'Deprecation-85858-GeneralUtilityclientInfo.rst',
+        ],
+    ],
 ];