[BUGFIX] Transfer curlProxyServer to new HTTP settings 79/31879/2
authorErnesto Baschny <ernst@cron-it.de>
Sun, 27 Jul 2014 11:59:20 +0000 (13:59 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 18 Sep 2014 21:46:41 +0000 (23:46 +0200)
Splits up the old curlProxyServer correctly, stripping "http://" and
potentially trailing slashes.

Resolves: #45834
Releases: 6.3, 6.2, 6.1
Change-Id: Ibfefb927b5fd3fe900170870e1093027d4fe34b5
Reviewed-on: http://review.typo3.org/31879
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Core/Bootstrap.php
typo3/sysext/core/Tests/Unit/Core/BootstrapTest.php

index ed8c972..23cf66e 100644 (file)
@@ -464,20 +464,24 @@ class Bootstrap {
        /**
         * Parse old curl options and set new http ones instead
         *
-        * @TODO: This code segment must still be finished
+        * @TODO: Move this functionality to the silent updater in the Install Tool
         * @return Bootstrap
         */
        protected function transferDeprecatedCurlSettings() {
-               if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
-                       $proxyParts = Utility\GeneralUtility::revExplode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'], 2);
+               if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']) && empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'])) {
+                       $curlProxy = rtrim(preg_replace('#^https?://#', '', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']), '/');
+                       $proxyParts = Utility\GeneralUtility::revExplode(':', $curlProxy, 2);
                        $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
                        $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
                }
-               if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'])) {
+               if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']) && empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'])) {
                        $userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
                        $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
                        $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
                }
+               if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse']) {
+                       $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter'] = 'curl';
+               }
                return $this;
        }
 
index d1f540d..1f7a8a2 100644 (file)
@@ -100,4 +100,84 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $bootstrapInstance->setEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
                $bootstrapInstance->loadCachedTca();
        }
+
+       /**
+        * Dataprovider for transferDeprecatedCurlSettings
+        *
+        * @return array
+        */
+       public function curlProxySettingsToHttpSettingsMapping() {
+               return array(
+                       array('http://proxy:3128/', 'proxy', '3128'),
+                       array('http://proxy:3128', 'proxy', '3128'),
+                       array('proxy:3128', 'proxy', '3128'),
+                       array('https://proxy:3128/', 'proxy', '3128'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider curlProxySettingsToHttpSettingsMapping
+        */
+       public function transferDeprecatedCurlSettings($curlProxyServer, $proxyHost, $proxyPort) {
+               /** @var $bootstrapInstance \TYPO3\CMS\Core\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $bootstrapInstance = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Core\\Bootstrap',
+                       array('dummy'),
+                       array(),
+                       '',
+                       FALSE
+               );
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'] = $curlProxyServer;
+               $bootstrapInstance->_call('transferDeprecatedCurlSettings');
+               $this->assertEquals($proxyHost, $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host']);
+               $this->assertEquals($proxyPort, $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port']);
+       }
+
+       /**
+        * @test
+        */
+       public function curlProxyServerDoesNotOverwriteHttpSettings() {
+               /** @var $bootstrapInstance \TYPO3\CMS\Core\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $bootstrapInstance = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Core\\Bootstrap',
+                       array('dummy'),
+                       array(),
+                       '',
+                       FALSE
+               );
+
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'] = 'http://proxyOld:3128/';
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'] = 'userOld:passOld';
+               $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = 'proxyNew';
+               $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = '3128';
+               $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = 'userNew';
+               $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_pass'] = 'passNew';
+
+               $bootstrapInstance->_call('transferDeprecatedCurlSettings');
+               $this->assertEquals('http://proxyOld:3128/', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']);
+               $this->assertEquals('userOld:passOld', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']);
+               $this->assertEquals('proxyNew', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host']);
+               $this->assertEquals('3128', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port']);
+               $this->assertEquals('userNew', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user']);
+               $this->assertEquals('passNew', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_pass']);
+       }
+
+       /**
+        * @test
+        */
+       public function curlAdapterUsedIfCurlUse() {
+               /** @var $bootstrapInstance \TYPO3\CMS\Core\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $bootstrapInstance = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Core\\Bootstrap',
+                       array('dummy'),
+                       array(),
+                       '',
+                       FALSE
+               );
+
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] = TRUE;
+               $bootstrapInstance->_call('transferDeprecatedCurlSettings');
+               $this->assertEquals('curl', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter']);
+       }
 }