[TASK] Use NormalizedParams with simplified arguments 71/58471/4
authorBenni Mack <benni@typo3.org>
Sat, 29 Sep 2018 18:32:46 +0000 (20:32 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Sat, 29 Sep 2018 20:04:32 +0000 (22:04 +0200)
Normalized Params only needs serverParams and
$TYPO3_CONF_VARS[SYS] to work with, so the object is modified
in order to simplify further work on the object.

Resolves: #86454
Releases: master
Change-Id: I30f2c6195468b275e61570c1de67b39f281bb494
Reviewed-on: https://review.typo3.org/58471
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: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Classes/Http/NormalizedParams.php
typo3/sysext/core/Classes/Middleware/NormalizedParamsAttribute.php
typo3/sysext/core/Tests/Unit/Http/NormalizedParamsTest.php
typo3/sysext/frontend/Tests/Unit/Compatibility/LegacyDomainResolverTest.php

index 7ad5922..6190c6d 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Core\Http;
  * The TYPO3 project - inspiring people to share!
  */
 
-use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -285,26 +284,25 @@ class NormalizedParams
      * dependency to $this. This ensures the chain of inter-property dependencies
      * is visible by only looking at the construct() method.
      *
-     * @param ServerRequestInterface $serverRequest Used to access $_SERVER
-     * @param array $typo3ConfVars $GLOBALS['TYPO3_CONF_VARS']
+     * @param array $serverParams, usually coming from $_SERVER or $request->getServerParams()
+     * @param array $configuration $GLOBALS['TYPO3_CONF_VARS']['SYS']
      * @param string $pathThisScript Absolute server entry script path, usually found within Environment::getCurrentScript()
      * @param string $pathSite Absolute server path to document root, Environment::getPublicPath()
      */
-    public function __construct(ServerRequestInterface $serverRequest, array $typo3ConfVars, string $pathThisScript, string $pathSite)
+    public function __construct(array $serverParams, array $configuration, string $pathThisScript, string $pathSite)
     {
-        $serverParams = $serverRequest->getServerParams();
-        $isBehindReverseProxy = $this->isBehindReverseProxy = self::determineIsBehindReverseProxy($serverParams, $typo3ConfVars);
-        $httpHost = $this->httpHost = self::determineHttpHost($serverParams, $typo3ConfVars, $isBehindReverseProxy);
-        $isHttps = $this->isHttps = self::determineHttps($serverParams, $typo3ConfVars);
+        $isBehindReverseProxy = $this->isBehindReverseProxy = self::determineIsBehindReverseProxy($serverParams, $configuration);
+        $httpHost = $this->httpHost = self::determineHttpHost($serverParams, $configuration, $isBehindReverseProxy);
+        $isHttps = $this->isHttps = self::determineHttps($serverParams, $configuration);
         $requestHost = $this->requestHost = ($isHttps ? 'https://' : 'http://') . $httpHost;
         $requestHostOnly = $this->requestHostOnly = self::determineRequestHostOnly($httpHost);
         $this->requestPort = self::determineRequestPort($httpHost, $requestHostOnly);
-        $scriptName = $this->scriptName = self::determineScriptName($serverParams, $typo3ConfVars, $isHttps, $isBehindReverseProxy);
-        $requestUri = $this->requestUri = self::determineRequestUri($serverParams, $typo3ConfVars, $isHttps, $scriptName, $isBehindReverseProxy);
+        $scriptName = $this->scriptName = self::determineScriptName($serverParams, $configuration, $isHttps, $isBehindReverseProxy);
+        $requestUri = $this->requestUri = self::determineRequestUri($serverParams, $configuration, $isHttps, $scriptName, $isBehindReverseProxy);
         $requestUrl = $this->requestUrl = $requestHost . $requestUri;
         $this->requestScript = $requestHost . $scriptName;
         $requestDir = $this->requestDir = $requestHost . GeneralUtility::dirname($scriptName) . '/';
-        $this->remoteAddress = self::determineRemoteAddress($serverParams, $typo3ConfVars, $isBehindReverseProxy);
+        $this->remoteAddress = self::determineRemoteAddress($serverParams, $configuration, $isBehindReverseProxy);
         $scriptFilename = $this->scriptFilename = $pathThisScript;
         $this->documentRoot = self::determineDocumentRoot($scriptName, $scriptFilename);
         $siteUrl = $this->siteUrl = self::determineSiteUrl($requestDir, $pathThisScript, $pathSite . '/');
@@ -532,11 +530,11 @@ class NormalizedParams
      * verify allowed hosts with configured trusted hosts pattern.
      *
      * @param array $serverParams Basically the $_SERVER, but from $request object
-     * @param array $typo3ConfVars TYPO3_CONF_VARS array
+     * @param array $configuration $TYPO3_CONF_VARS['SYS'] array
      * @param bool $isBehindReverseProxy True if reverse proxy setup is detected
      * @return string Sanitized HTTP_HOST
      */
-    protected static function determineHttpHost(array $serverParams, array $typo3ConfVars, bool $isBehindReverseProxy): string
+    protected static function determineHttpHost(array $serverParams, array $configuration, bool $isBehindReverseProxy): string
     {
         $httpHost = $serverParams['HTTP_HOST'] ?? '';
         if ($isBehindReverseProxy) {
@@ -546,7 +544,7 @@ class NormalizedParams
             $xForwardedHost = '';
             // Choose which host in list to use
             if (!empty($xForwardedHostArray)) {
-                $configuredReverseProxyHeaderMultiValue = trim($typo3ConfVars['SYS']['reverseProxyHeaderMultiValue'] ?? '');
+                $configuredReverseProxyHeaderMultiValue = trim($configuration['reverseProxyHeaderMultiValue'] ?? '');
                 // Default if reverseProxyHeaderMultiValue is not set or set to 'none', instead of 'first' / 'last' is to
                 // ignore $serverParams['HTTP_X_FORWARDED_HOST']
                 // @todo: Maybe this default is stupid: Both SYS/reverseProxyIP hand SYS/reverseProxyHeaderMultiValue have to
@@ -578,15 +576,15 @@ class NormalizedParams
      * configurations into account.
      *
      * @param array $serverParams Basically the $_SERVER, but from $request object
-     * @param array $typo3ConfVars TYPO3_CONF_VARS array
+     * @param array $configuration $TYPO3_CONF_VARS['SYS'] array
      * @return bool True if request has been done via HTTPS
      */
-    protected static function determineHttps(array $serverParams, array $typo3ConfVars): bool
+    protected static function determineHttps(array $serverParams, array $configuration): bool
     {
         $isHttps = false;
-        $configuredProxySSL = trim($typo3ConfVars['SYS']['reverseProxySSL'] ?? '');
+        $configuredProxySSL = trim($configuration['reverseProxySSL'] ?? '');
         if ($configuredProxySSL === '*') {
-            $configuredProxySSL = trim($typo3ConfVars['SYS']['reverseProxyIP'] ?? '');
+            $configuredProxySSL = trim($configuration['reverseProxyIP'] ?? '');
         }
         $httpsParam = (string)($serverParams['HTTPS'] ?? '');
         if (GeneralUtility::cmpIP(trim($serverParams['REMOTE_ADDR'] ?? ''), $configuredProxySSL)
@@ -604,12 +602,12 @@ class NormalizedParams
      * Determine script name and path
      *
      * @param array $serverParams Basically the $_SERVER, but from $request object
-     * @param array $typo3ConfVars TYPO3_CONF_VARS array
+     * @param array $configuration TYPO3_CONF_VARS['SYS'] array
      * @param bool $isHttps True if used protocol is HTTPS
      * @param bool $isBehindReverseProxy True if reverse proxy setup is detected
      * @return string Sanitized script name
      */
-    protected static function determineScriptName(array $serverParams, array $typo3ConfVars, bool $isHttps, bool $isBehindReverseProxy): string
+    protected static function determineScriptName(array $serverParams, array $configuration, bool $isHttps, bool $isBehindReverseProxy): string
     {
         $scriptName = $serverParams['ORIG_PATH_INFO'] ??
             $serverParams['PATH_INFO'] ??
@@ -618,10 +616,10 @@ class NormalizedParams
             '';
         if ($isBehindReverseProxy) {
             // Add a prefix if TYPO3 is behind a proxy: ext-domain.com => int-server.com/prefix
-            if ($isHttps && !empty($typo3ConfVars['SYS']['reverseProxyPrefixSSL'])) {
-                $scriptName = $typo3ConfVars['SYS']['reverseProxyPrefixSSL'] . $scriptName;
-            } elseif (!empty($typo3ConfVars['SYS']['reverseProxyPrefix'])) {
-                $scriptName = $typo3ConfVars['SYS']['reverseProxyPrefix'] . $scriptName;
+            if ($isHttps && !empty($configuration['reverseProxyPrefixSSL'])) {
+                $scriptName = $configuration['reverseProxyPrefixSSL'] . $scriptName;
+            } elseif (!empty($configuration['reverseProxyPrefix'])) {
+                $scriptName = $configuration['reverseProxyPrefix'] . $scriptName;
             }
         }
         return $scriptName;
@@ -632,20 +630,20 @@ class NormalizedParams
      * specifics into account.
      *
      * @param array $serverParams Basically the $_SERVER, but from $request object
-     * @param array $typo3ConfVars TYPO3_CONF_VARS array
+     * @param array $configuration $TYPO3_CONF_VARS['SYS'] array
      * @param bool $isHttps True if used protocol is HTTPS
      * @param string $scriptName Script name
      * @param bool $isBehindReverseProxy True if reverse proxy setup is detected
      * @return string Sanitized REQUEST_URI
      */
-    protected static function determineRequestUri(array $serverParams, array $typo3ConfVars, bool $isHttps, string $scriptName, bool $isBehindReverseProxy): string
+    protected static function determineRequestUri(array $serverParams, array $configuration, bool $isHttps, string $scriptName, bool $isBehindReverseProxy): string
     {
         $proxyPrefixApplied = false;
-        if (!empty($typo3ConfVars['SYS']['requestURIvar'])) {
+        if (!empty($configuration['requestURIvar'])) {
             // This is for URL rewriter that store the original URI in a server
             // variable (e.g. ISAPI Rewriter for IIS: HTTP_X_REWRITE_URL), a config then looks like:
             // requestURIvar = '_SERVER|HTTP_X_REWRITE_URL' which will access $GLOBALS['_SERVER']['HTTP_X_REWRITE_URL']
-            list($firstLevel, $secondLevel) = GeneralUtility::trimExplode('|', $typo3ConfVars['SYS']['requestURIvar'], true);
+            list($firstLevel, $secondLevel) = GeneralUtility::trimExplode('|', $configuration['requestURIvar'], true);
             $requestUri = $GLOBALS[$firstLevel][$secondLevel];
         } elseif (empty($serverParams['REQUEST_URI'])) {
             // This is for ISS/CGI which does not have the REQUEST_URI available.
@@ -658,10 +656,10 @@ class NormalizedParams
         }
         if (!$proxyPrefixApplied && $isBehindReverseProxy) {
             // Add a prefix if TYPO3 is behind a proxy: ext-domain.com => int-server.com/prefix
-            if ($isHttps && !empty($typo3ConfVars['SYS']['reverseProxyPrefixSSL'])) {
-                $requestUri = $typo3ConfVars['SYS']['reverseProxyPrefixSSL'] . $requestUri;
-            } elseif (!empty($typo3ConfVars['SYS']['reverseProxyPrefix'])) {
-                $requestUri = $typo3ConfVars['SYS']['reverseProxyPrefix'] . $requestUri;
+            if ($isHttps && !empty($configuration['reverseProxyPrefixSSL'])) {
+                $requestUri = $configuration['reverseProxyPrefixSSL'] . $requestUri;
+            } elseif (!empty($configuration['reverseProxyPrefix'])) {
+                $requestUri = $configuration['reverseProxyPrefix'] . $requestUri;
             }
         }
         return $requestUri;
@@ -671,17 +669,17 @@ class NormalizedParams
      * Determine clients REMOTE_ADDR, even if there is a reverse proxy in between.
      *
      * @param array $serverParams Basically the $_SERVER, but from $request object
-     * @param array $typo3ConfVars TYPO3_CONF_VARS array
+     * @param array $configuration $TYPO3_CONF_VARS[SYS] array
      * @param bool $isBehindReverseProxy True if reverse proxy setup is detected
      * @return string Resolved REMOTE_ADDR
      */
-    protected static function determineRemoteAddress(array $serverParams, array $typo3ConfVars, bool $isBehindReverseProxy): string
+    protected static function determineRemoteAddress(array $serverParams, array $configuration, bool $isBehindReverseProxy): string
     {
         $remoteAddress = trim($serverParams['REMOTE_ADDR'] ?? '');
         if ($isBehindReverseProxy) {
             $ip = GeneralUtility::trimExplode(',', $serverParams['HTTP_X_FORWARDED_FOR'] ?? '', true);
             // Choose which IP in list to use
-            $configuredReverseProxyHeaderMultiValue = trim($typo3ConfVars['SYS']['reverseProxyHeaderMultiValue'] ?? '');
+            $configuredReverseProxyHeaderMultiValue = trim($configuration['reverseProxyHeaderMultiValue'] ?? '');
             if (!empty($ip) && $configuredReverseProxyHeaderMultiValue === 'last') {
                 $ip = array_pop($ip);
             } elseif (!empty($ip) && $configuredReverseProxyHeaderMultiValue === 'first') {
@@ -700,12 +698,12 @@ class NormalizedParams
      * Check if a configured reverse proxy setup is detected.
      *
      * @param array $serverParams Basically the $_SERVER, but from $request object
-     * @param array $typo3ConfVars TYPO3_CONF_VARS array
+     * @param array $configuration $TYPO3_CONF_VARS[SYS] array
      * @return bool True if TYPO3 is behind a reverse proxy
      */
-    protected static function determineIsBehindReverseProxy($serverParams, $typo3ConfVars): bool
+    protected static function determineIsBehindReverseProxy($serverParams, $configuration): bool
     {
-        return GeneralUtility::cmpIP(trim($serverParams['REMOTE_ADDR'] ?? ''), trim($typo3ConfVars['SYS']['reverseProxyIP'] ?? ''));
+        return GeneralUtility::cmpIP(trim($serverParams['REMOTE_ADDR'] ?? ''), trim($configuration['reverseProxyIP'] ?? ''));
     }
 
     /**
index be09055..e0e9358 100644 (file)
@@ -43,8 +43,8 @@ class NormalizedParamsAttribute implements MiddlewareInterface
         $request = $request->withAttribute(
             'normalizedParams',
             new NormalizedParams(
-                $request,
-                $GLOBALS['TYPO3_CONF_VARS'],
+                $request->getServerParams(),
+                $GLOBALS['TYPO3_CONF_VARS']['SYS'],
                 Environment::getCurrentScript(),
                 Environment::getPublicPath()
             )
index 66f8c3e..251d943 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Core\Tests\Unit\Http;
  * The TYPO3 project - inspiring people to share!
  */
 
-use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Http\NormalizedParams;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -44,10 +43,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'HTTP_X_FORWARDED_HOST' => 'www.domain1.com, www.domain2.com,'
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => ' 123.123.123.123',
-                        'reverseProxyHeaderMultiValue' => 'first',
-                    ]
+                    'reverseProxyIP' => ' 123.123.123.123',
+                    'reverseProxyHeaderMultiValue' => 'first',
                 ],
                 'www.domain1.com',
             ],
@@ -58,10 +55,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'HTTP_X_FORWARDED_HOST' => 'www.domain1.com, www.domain2.com,'
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                        'reverseProxyHeaderMultiValue' => 'last',
-                    ]
+                    'reverseProxyIP' => '123.123.123.123',
+                    'reverseProxyHeaderMultiValue' => 'last',
                 ],
                 'www.domain2.com',
             ],
@@ -72,9 +67,7 @@ class NormalizedParamsTest extends UnitTestCase
                     'HTTP_X_FORWARDED_HOST' => 'www.domain1.com'
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                    ]
+                    'reverseProxyIP' => '123.123.123.123',
                 ],
                 'www.domain.com',
             ],
@@ -85,10 +78,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'HTTP_X_FORWARDED_HOST' => 'www.domain1.com'
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '234.234.234.234',
-                        'reverseProxyHeaderMultiValue' => 'last',
-                    ]
+                    'reverseProxyIP' => '234.234.234.234',
+                    'reverseProxyHeaderMultiValue' => 'last',
                 ],
                 'www.domain.com',
             ],
@@ -98,10 +89,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'HTTP_X_FORWARDED_HOST' => 'www.domain1.com'
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '234.234.234.234',
-                        'reverseProxyHeaderMultiValue' => 'last',
-                    ]
+                    'reverseProxyIP' => '234.234.234.234',
+                    'reverseProxyHeaderMultiValue' => 'last',
                 ],
                 'www.domain.com',
             ],
@@ -112,10 +101,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'HTTP_X_FORWARDED_HOST' => ''
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                        'reverseProxyHeaderMultiValue' => 'last',
-                    ]
+                    'reverseProxyIP' => '123.123.123.123',
+                    'reverseProxyHeaderMultiValue' => 'last',
                 ],
                 'www.domain.com',
             ],
@@ -126,14 +113,12 @@ class NormalizedParamsTest extends UnitTestCase
      * @test
      * @dataProvider getHttpHostReturnsSanitizedValueDataProvider
      * @param array $serverParams
-     * @param array $typo3ConfVars
+     * @param array $configuration
      * @param string $expected
      */
-    public function getHttpHostReturnsSanitizedValue(array $serverParams, array $typo3ConfVars, string $expected)
+    public function getHttpHostReturnsSanitizedValue(array $serverParams, array $configuration, string $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), $typo3ConfVars, '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, $configuration, '', '');
         $this->assertSame($expected, $serverRequestParameters->getHttpHost());
     }
 
@@ -291,9 +276,7 @@ class NormalizedParamsTest extends UnitTestCase
                     'REMOTE_ADDR' => '123.123.123.123 ',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxySSL' => ' 123.123.123.123',
-                    ],
+                    'reverseProxySSL' => ' 123.123.123.123',
                 ],
                 true
             ],
@@ -303,9 +286,7 @@ class NormalizedParamsTest extends UnitTestCase
                     'REMOTE_ADDR' => '123.123.123.123',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxySSL' => '234.234.234.234',
-                    ],
+                    'reverseProxySSL' => '234.234.234.234',
                 ],
                 false
             ],
@@ -315,10 +296,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'REMOTE_ADDR' => '123.123.123.123',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxySSL' => '*',
-                        'reverseProxyIP' => '123.123.123.123',
-                    ],
+                    'reverseProxySSL' => '*',
+                    'reverseProxyIP' => '123.123.123.123',
                 ],
                 true
             ],
@@ -328,10 +307,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'REMOTE_ADDR' => '123.123.123.123',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxySSL' => '*',
-                        'reverseProxyIP' => '234.234.234.234',
-                    ],
+                    'reverseProxySSL' => '*',
+                    'reverseProxyIP' => '234.234.234.234',
                 ],
                 false
             ]
@@ -342,14 +319,12 @@ class NormalizedParamsTest extends UnitTestCase
      * @test
      * @dataProvider isHttpsReturnSanitizedValueDataProvider
      * @param array $serverParams
-     * @param array $typo3ConfVars
+     * @param array $configuration
      * @param bool $expected
      */
-    public function isHttpsReturnSanitizedValue(array $serverParams, array $typo3ConfVars, bool $expected)
+    public function isHttpsReturnSanitizedValue(array $serverParams, array $configuration, bool $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), $typo3ConfVars, '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, $configuration, '', '');
         $this->assertSame($expected, $serverRequestParameters->isHttps());
     }
 
@@ -363,9 +338,7 @@ class NormalizedParamsTest extends UnitTestCase
             'HTTPS' => 'on',
         ];
         $expected = 'https://www.domain.com';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getRequestHost());
     }
 
@@ -423,10 +396,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'PATH_INFO' => '/path/info.php',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                        'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
-                    ],
+                    'reverseProxyIP' => '123.123.123.123',
+                    'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
                 ],
                 '/proxyPrefixSSL/path/info.php',
             ],
@@ -436,10 +407,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'PATH_INFO' => '/path/info.php',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                        'reverseProxyPrefix' => '/proxyPrefix',
-                    ],
+                    'reverseProxyIP' => '123.123.123.123',
+                    'reverseProxyPrefix' => '/proxyPrefix',
                 ],
                 '/proxyPrefix/path/info.php',
             ],
@@ -450,14 +419,12 @@ class NormalizedParamsTest extends UnitTestCase
      * @test
      * @dataProvider getScriptNameReturnsExpectedValueDataProvider
      * @param array $serverParams
-     * @param array $typo3ConfVars
+     * @param array $configuration
      * @param string $expected
      */
-    public function getScriptNameReturnsExpectedValue(array $serverParams, array $typo3ConfVars, string $expected)
+    public function getScriptNameReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), $typo3ConfVars, '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, $configuration, '', '');
         $this->assertSame($expected, $serverRequestParameters->getScriptName());
     }
 
@@ -498,10 +465,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'REQUEST_URI' => 'typo3/index.php?route=foo/bar&id=42',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                        'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
-                    ],
+                    'reverseProxyIP' => '123.123.123.123',
+                    'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
                 ],
                 '/proxyPrefixSSL/typo3/index.php?route=foo/bar&id=42',
             ],
@@ -512,10 +477,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'REQUEST_URI' => 'typo3/index.php?route=foo/bar&id=42',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                        'reverseProxyPrefix' => '/proxyPrefix',
-                    ],
+                    'reverseProxyIP' => '123.123.123.123',
+                    'reverseProxyPrefix' => '/proxyPrefix',
                 ],
                 '/proxyPrefix/typo3/index.php?route=foo/bar&id=42',
             ],
@@ -527,10 +490,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'SCRIPT_NAME' => '/typo3/index.php',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                        'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
-                    ],
+                    'reverseProxyIP' => '123.123.123.123',
+                    'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
                 ],
                 '/proxyPrefixSSL/typo3/index.php?route=foo/bar&id=42',
             ],
@@ -542,10 +503,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'SCRIPT_NAME' => '/typo3/index.php',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                        'reverseProxyPrefix' => '/proxyPrefix',
-                    ],
+                    'reverseProxyIP' => '123.123.123.123',
+                    'reverseProxyPrefix' => '/proxyPrefix',
                 ],
                 '/proxyPrefix/typo3/index.php?route=foo/bar&id=42',
             ],
@@ -556,14 +515,12 @@ class NormalizedParamsTest extends UnitTestCase
      * @test
      * @dataProvider getRequestUriReturnsExpectedValueDataProvider
      * @param array $serverParams
-     * @param array $typo3ConfVars
+     * @param array $configuration
      * @param string $expected
      */
-    public function getRequestUriReturnsExpectedValue(array $serverParams, array $typo3ConfVars, string $expected)
+    public function getRequestUriReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), $typo3ConfVars, '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, $configuration, '', '');
         $this->assertSame($expected, $serverRequestParameters->getRequestUri());
     }
 
@@ -576,15 +533,11 @@ class NormalizedParamsTest extends UnitTestCase
         $serverParams = [
             'HTTP_HOST' => 'www.domain.com',
         ];
-        $typo3ConfVars = [
-            'SYS' => [
-                'requestURIvar' => 'foo|bar',
-            ],
+        $configuration = [
+            'requestURIvar' => 'foo|bar',
         ];
         $expected = '/foo/bar.php';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), $typo3ConfVars, '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, $configuration, '', '');
         $this->assertSame($expected, $serverRequestParameters->getRequestUri());
     }
 
@@ -598,9 +551,7 @@ class NormalizedParamsTest extends UnitTestCase
             'REQUEST_URI' => 'typo3/index.php?route=foo/bar&id=42',
         ];
         $expected = 'http://www.domain.com/typo3/index.php?route=foo/bar&id=42';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getRequestUrl());
     }
 
@@ -614,9 +565,7 @@ class NormalizedParamsTest extends UnitTestCase
             'PATH_INFO' => '/typo3/index.php',
         ];
         $expected = 'http://www.domain.com/typo3/index.php';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getRequestScript());
     }
 
@@ -630,9 +579,7 @@ class NormalizedParamsTest extends UnitTestCase
             'PATH_INFO' => '/typo3/index.php',
         ];
         $expected = 'http://www.domain.com/typo3/';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getRequestDir());
     }
 
@@ -655,9 +602,7 @@ class NormalizedParamsTest extends UnitTestCase
                     'REMOTE_ADDR' => '100.100.100.100',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '200.200.200.200',
-                    ],
+                    'reverseProxyIP' => '200.200.200.200',
                 ],
                 false
             ],
@@ -667,9 +612,7 @@ class NormalizedParamsTest extends UnitTestCase
                     'REMOTE_ADDR' => '100.100.100.100',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '100.100.100.100',
-                    ],
+                    'reverseProxyIP' => '100.100.100.100',
                 ],
                 true
             ],
@@ -679,9 +622,7 @@ class NormalizedParamsTest extends UnitTestCase
                     'REMOTE_ADDR' => ' 100.100.100.100 ',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '  100.100.100.100  ',
-                    ],
+                    'reverseProxyIP' => '  100.100.100.100  ',
                 ],
                 true
             ]
@@ -692,14 +633,12 @@ class NormalizedParamsTest extends UnitTestCase
      * @test
      * @dataProvider isBehindReverseProxyReturnsExpectedValueDataProvider
      * @param array $serverParams
-     * @param array $typo3ConfVars
+     * @param array $configuration
      * @param bool $expected
      */
-    public function isBehindReverseProxyReturnsExpectedValue(array $serverParams, array $typo3ConfVars, bool $expected)
+    public function isBehindReverseProxyReturnsExpectedValue(array $serverParams, array $configuration, bool $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), $typo3ConfVars, '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, $configuration, '', '');
         $this->assertSame($expected, $serverRequestParameters->isBehindReverseProxy());
     }
 
@@ -724,10 +663,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'HTTP_X_FORWARDED_FOR' => ' 234.234.234.234, 235.235.235.235,',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123',
-                        'reverseProxyHeaderMultiValue' => ' last ',
-                    ]
+                    'reverseProxyIP' => '123.123.123.123',
+                    'reverseProxyHeaderMultiValue' => ' last ',
                 ],
                 '235.235.235.235'
             ],
@@ -738,10 +675,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'HTTP_X_FORWARDED_FOR' => ' 234.234.234.234, 235.235.235.235,',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123 ',
-                        'reverseProxyHeaderMultiValue' => ' first ',
-                    ]
+                    'reverseProxyIP' => '123.123.123.123 ',
+                    'reverseProxyHeaderMultiValue' => ' first ',
                 ],
                 '234.234.234.234'
             ],
@@ -752,10 +687,8 @@ class NormalizedParamsTest extends UnitTestCase
                     'HTTP_X_FORWARDED_FOR' => ' 234.234.234.234, 235.235.235.235,',
                 ],
                 [
-                    'SYS' => [
-                        'reverseProxyIP' => '123.123.123.123 ',
-                        'reverseProxyHeaderMultiValue' => ' foo ',
-                    ]
+                    'reverseProxyIP' => '123.123.123.123 ',
+                    'reverseProxyHeaderMultiValue' => ' foo ',
                 ],
                 '123.123.123.123'
             ],
@@ -766,14 +699,12 @@ class NormalizedParamsTest extends UnitTestCase
      * @test
      * @dataProvider getRemoteAddressReturnsExpectedValueDataProvider
      * @param array $serverParams
-     * @param array $typo3ConfVars
+     * @param array $configuration
      * @param string $expected
      */
-    public function getRemoteAddressReturnsExpectedValue(array $serverParams, array $typo3ConfVars, string $expected)
+    public function getRemoteAddressReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), $typo3ConfVars, '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, $configuration, '', '');
         $this->assertSame($expected, $serverRequestParameters->getRemoteAddress());
     }
 
@@ -842,9 +773,7 @@ class NormalizedParamsTest extends UnitTestCase
      */
     public function getRequestHostOnlyReturnsExpectedValue(array $serverParams, string $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getRequestHostOnly());
     }
 
@@ -913,9 +842,7 @@ class NormalizedParamsTest extends UnitTestCase
      */
     public function getRequestPortReturnsExpectedValue(array $serverParams, int $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getRequestPort());
     }
 
@@ -929,9 +856,7 @@ class NormalizedParamsTest extends UnitTestCase
             'SCRIPT_NAME' => '/typo3/index.php',
         ];
         $pathSite = '/var/www/';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '/var/www/typo3/index.php', $pathSite);
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '/var/www/typo3/index.php', $pathSite);
         $this->assertSame('/var/www/typo3/index.php', $serverRequestParameters->getScriptFilename());
     }
 
@@ -947,9 +872,7 @@ class NormalizedParamsTest extends UnitTestCase
         $pathThisScript = '/var/www/myInstance/Web/typo3/index.php';
         $pathSite = '/var/www/myInstance/Web/';
         $expected = '/var/www/myInstance/Web';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], $pathThisScript, $pathSite);
+        $serverRequestParameters = new NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
         $this->assertSame($expected, $serverRequestParameters->getDocumentRoot());
     }
 
@@ -966,9 +889,7 @@ class NormalizedParamsTest extends UnitTestCase
         $pathThisScript = '/var/www/myInstance/Web/typo3/index.php';
         $pathSite = '/var/www/myInstance/Web';
         $expected = 'http://www.domain.com/';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], $pathThisScript, $pathSite);
+        $serverRequestParameters = new NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
         $this->assertSame($expected, $serverRequestParameters->getSiteUrl());
     }
 
@@ -1015,9 +936,7 @@ class NormalizedParamsTest extends UnitTestCase
      */
     public function getSitePathReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], $pathThisScript, $pathSite);
+        $serverRequestParameters = new NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
         $this->assertSame($expected, $serverRequestParameters->getSitePath());
     }
 
@@ -1058,9 +977,7 @@ class NormalizedParamsTest extends UnitTestCase
      */
     public function getSiteScriptReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected)
     {
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], $pathThisScript, $pathSite);
+        $serverRequestParameters = new NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
         $this->assertSame($expected, $serverRequestParameters->getSiteScript());
     }
 
@@ -1073,9 +990,7 @@ class NormalizedParamsTest extends UnitTestCase
             'PATH_INFO' => '/typo3/index.php',
         ];
         $expected = '/typo3/index.php';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getPathInfo());
     }
 
@@ -1088,9 +1003,7 @@ class NormalizedParamsTest extends UnitTestCase
             'HTTP_REFERER' => 'https://www.domain.com/typo3/index.php?id=42',
         ];
         $expected = 'https://www.domain.com/typo3/index.php?id=42';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getHttpReferer());
     }
 
@@ -1103,9 +1016,7 @@ class NormalizedParamsTest extends UnitTestCase
             'HTTP_USER_AGENT' => 'the client browser',
         ];
         $expected = 'the client browser';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getHttpUserAgent());
     }
 
@@ -1118,9 +1029,7 @@ class NormalizedParamsTest extends UnitTestCase
             'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
         ];
         $expected = 'gzip, deflate';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getHttpAcceptEncoding());
     }
 
@@ -1133,9 +1042,7 @@ class NormalizedParamsTest extends UnitTestCase
             'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
         ];
         $expected = 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getHttpAcceptLanguage());
     }
 
@@ -1148,9 +1055,7 @@ class NormalizedParamsTest extends UnitTestCase
             'REMOTE_HOST' => 'www.clientDomain.com',
         ];
         $expected = 'www.clientDomain.com';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getRemoteHost());
     }
 
@@ -1163,9 +1068,7 @@ class NormalizedParamsTest extends UnitTestCase
             'QUERY_STRING' => 'id=42&foo=bar',
         ];
         $expected = 'id=42&foo=bar';
-        $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
-        $serverRequestProphecy->getServerParams()->willReturn($serverParams);
-        $serverRequestParameters = new NormalizedParams($serverRequestProphecy->reveal(), [], '', '');
+        $serverRequestParameters = new NormalizedParams($serverParams, [], '', '');
         $this->assertSame($expected, $serverRequestParameters->getQueryString());
     }
 }
index a573c2f..3b88e4b 100644 (file)
@@ -94,7 +94,7 @@ class LegacyDomainResolverTest extends UnitTestCase
         $_SERVER['HTTP_HOST'] = $currentDomain;
         $_SERVER['SCRIPT_NAME'] = $scriptName;
         $request = ServerRequestFactory::fromGlobals();
-        $normalizedParams = new NormalizedParams($request, [], Environment::getCurrentScript(), Environment::getPublicPath());
+        $normalizedParams = new NormalizedParams($_SERVER, [], Environment::getCurrentScript(), Environment::getPublicPath());
         $request = $request->withAttribute('normalizedParams', $normalizedParams);
         $this->assertEquals($expectedResult, $this->subject->_call('domainNameMatchesCurrentRequest', $domainRecord, $request));
     }