‪TYPO3CMS  ‪main
NormalizedParamsTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 final class ‪NormalizedParamsTest extends UnitTestCase
24 {
28  public static function ‪getHttpHostReturnsSanitizedValueDataProvider(): array
29  {
30  return [
31  'simple HTTP_HOST' => [
32  [
33  'HTTP_HOST' => 'www.domain.com',
34  ],
35  [],
36  'www.domain.com',
37  ],
38  'first HTTP_X_FORWARDED_HOST from configured proxy, HTTP_HOST empty' => [
39  [
40  'HTTP_HOST' => '',
41  'REMOTE_ADDR' => '123.123.123.123',
42  'HTTP_X_FORWARDED_HOST' => 'www.domain1.com, www.domain2.com,',
43  ],
44  [
45  'reverseProxyIP' => ' 123.123.123.123',
46  'reverseProxyHeaderMultiValue' => 'first',
47  ],
48  'www.domain1.com',
49  ],
50  'first HTTP_X_FORWARDED_HOST from configured proxy, HTTP_HOST given' => [
51  [
52  'HTTP_HOST' => 'www.domain.com',
53  'REMOTE_ADDR' => '123.123.123.123',
54  'HTTP_X_FORWARDED_HOST' => 'www.domain1.com, www.domain2.com,',
55  ],
56  [
57  'reverseProxyIP' => '123.123.123.123',
58  'reverseProxyHeaderMultiValue' => 'first',
59  ],
60  'www.domain1.com',
61  ],
62  'last HTTP_X_FORWARDED_HOST from configured proxy' => [
63  [
64  'HTTP_HOST' => '',
65  'REMOTE_ADDR' => '123.123.123.123',
66  'HTTP_X_FORWARDED_HOST' => 'www.domain1.com, www.domain2.com,',
67  ],
68  [
69  'reverseProxyIP' => '123.123.123.123',
70  'reverseProxyHeaderMultiValue' => 'last',
71  ],
72  'www.domain2.com',
73  ],
74  'simple HTTP_HOST if reverseProxyHeaderMultiValue is not configured' => [
75  [
76  'HTTP_HOST' => 'www.domain.com',
77  'REMOTE_ADDR' => '123.123.123.123',
78  'HTTP_X_FORWARDED_HOST' => 'www.domain1.com',
79  ],
80  [
81  'reverseProxyIP' => '123.123.123.123',
82  ],
83  'www.domain.com',
84  ],
85  'simple HTTP_HOST if proxy IP does not match' => [
86  [
87  'HTTP_HOST' => 'www.domain.com',
88  'REMOTE_ADDR' => '123.123.123.123',
89  'HTTP_X_FORWARDED_HOST' => 'www.domain1.com',
90  ],
91  [
92  'reverseProxyIP' => '234.234.234.234',
93  'reverseProxyHeaderMultiValue' => 'last',
94  ],
95  'www.domain.com',
96  ],
97  'simple HTTP_HOST if REMOTE_ADDR misses' => [
98  [
99  'HTTP_HOST' => 'www.domain.com',
100  'HTTP_X_FORWARDED_HOST' => 'www.domain1.com',
101  ],
102  [
103  'reverseProxyIP' => '234.234.234.234',
104  'reverseProxyHeaderMultiValue' => 'last',
105  ],
106  'www.domain.com',
107  ],
108  'simple HTTP_HOST if HTTP_X_FORWARDED_HOST is empty' => [
109  [
110  'HTTP_HOST' => 'www.domain.com',
111  'REMOTE_ADDR' => '123.123.123.123',
112  'HTTP_X_FORWARDED_HOST' => '',
113  ],
114  [
115  'reverseProxyIP' => '123.123.123.123',
116  'reverseProxyHeaderMultiValue' => 'last',
117  ],
118  'www.domain.com',
119  ],
120  ];
121  }
122 
127  public function ‪getHttpHostReturnsSanitizedValue(array $serverParams, array $configuration, string $expected): void
128  {
129  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
130  self::assertSame($expected, $serverRequestParameters->getHttpHost());
131  }
132 
136  public static function ‪isHttpsReturnSanitizedValueDataProvider(): array
137  {
138  return [
139  'false if nothing special is set' => [
140  [
141  'HTTP_HOST' => 'www.domain.com',
142  ],
143  [],
144  false,
145  ],
146  'true if SSL_SESSION_ID is set' => [
147  [
148  'HTTP_HOST' => 'www.domain.com',
149  'SSL_SESSION_ID' => 'foo',
150  ],
151  [],
152  true,
153  ],
154  'false if SSL_SESSION_ID is empty' => [
155  [
156  'HTTP_HOST' => 'www.domain.com',
157  'SSL_SESSION_ID' => '',
158  ],
159  [],
160  false,
161  ],
162  'true if HTTPS is "ON"' => [
163  [
164  'HTTP_HOST' => 'www.domain.com',
165  'HTTPS' => 'ON',
166  ],
167  [],
168  true,
169  ],
170  'true if HTTPS is "on"' => [
171  [
172  'HTTP_HOST' => 'www.domain.com',
173  'HTTPS' => 'on',
174  ],
175  [],
176  true,
177  ],
178  'true if HTTPS is "1"' => [
179  [
180  'HTTP_HOST' => 'www.domain.com',
181  'HTTPS' => '1',
182  ],
183  [],
184  true,
185  ],
186  'true if HTTPS is int(1)"' => [
187  [
188  'HTTP_HOST' => 'www.domain.com',
189  'HTTPS' => 1,
190  ],
191  [],
192  true,
193  ],
194  'true if HTTPS is bool(true)' => [
195  [
196  'HTTP_HOST' => 'www.domain.com',
197  'HTTPS' => true,
198  ],
199  [],
200  true,
201  ],
202  // https://secure.php.net/manual/en/reserved.variables.server.php
203  // "Set to a non-empty value if the script was queried through the HTTPS protocol."
204  'true if HTTPS is "somethingrandom"' => [
205  [
206  'HTTP_HOST' => 'www.domain.com',
207  'HTTPS' => 'somethingrandom',
208  ],
209  [],
210  true,
211  ],
212  'false if HTTPS is "0"' => [
213  [
214  'HTTP_HOST' => 'www.domain.com',
215  'HTTPS' => '0',
216  ],
217  [],
218  false,
219  ],
220  'false if HTTPS is int(0)' => [
221  [
222  'HTTP_HOST' => 'www.domain.com',
223  'HTTPS' => 0,
224  ],
225  [],
226  false,
227  ],
228  'false if HTTPS is float(0)' => [
229  [
230  'HTTP_HOST' => 'www.domain.com',
231  'HTTPS' => 0.0,
232  ],
233  [],
234  false,
235  ],
236  'false if HTTPS is not on' => [
237  [
238  'HTTP_HOST' => 'www.domain.com',
239  'HTTPS' => 'off',
240  ],
241  [],
242  false,
243  ],
244  'false if HTTPS is empty' => [
245  [
246  'HTTP_HOST' => 'www.domain.com',
247  'HTTPS' => '',
248  ],
249  [],
250  false,
251  ],
252  'false if HTTPS is null' => [
253  [
254  'HTTP_HOST' => 'www.domain.com',
255  'HTTPS' => null,
256  ],
257  [],
258  false,
259  ],
260  'false if HTTPS is bool(false)' => [
261  [
262  'HTTP_HOST' => 'www.domain.com',
263  'HTTPS' => false,
264  ],
265  [],
266  false,
267  ],
268  // Per PHP documentation 'HTTPS' is:
269  // "Set to a non-empty value if the script
270  // was queried through the HTTPS protocol."
271  // So theoretically an empty array means HTTPS is off.
272  // We do not support that. Therefore this test is disabled.
273  //'false if HTTPS is an empty Array' => [
274  // [
275  // 'HTTP_HOST' => 'www.domain.com',
276  // 'HTTPS' => [],
277  // ],
278  // [],
279  // false,
280  //],
281  'true if ssl proxy IP matches REMOTE_ADDR' => [
282  [
283  'HTTP_HOST' => 'www.domain.com',
284  'REMOTE_ADDR' => '123.123.123.123 ',
285  ],
286  [
287  'reverseProxySSL' => ' 123.123.123.123',
288  ],
289  true,
290  ],
291  'false if ssl proxy IP does not match REMOTE_ADDR' => [
292  [
293  'HTTP_HOST' => 'www.domain.com',
294  'REMOTE_ADDR' => '123.123.123.123',
295  ],
296  [
297  'reverseProxySSL' => '234.234.234.234',
298  ],
299  false,
300  ],
301  'true if SSL proxy is * and reverse proxy IP matches REMOTE_ADDR' => [
302  [
303  'HTTP_HOST' => 'www.domain.com',
304  'REMOTE_ADDR' => '123.123.123.123',
305  ],
306  [
307  'reverseProxySSL' => '*',
308  'reverseProxyIP' => '123.123.123.123',
309  ],
310  true,
311  ],
312  'false if SSL proxy is * and reverse proxy IP does not match REMOTE_ADDR' => [
313  [
314  'HTTP_HOST' => 'www.domain.com',
315  'REMOTE_ADDR' => '123.123.123.123',
316  ],
317  [
318  'reverseProxySSL' => '*',
319  'reverseProxyIP' => '234.234.234.234',
320  ],
321  false,
322  ],
323  ];
324  }
325 
330  public function ‪isHttpsReturnSanitizedValue(array $serverParams, array $configuration, bool $expected): void
331  {
332  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
333  self::assertSame($expected, $serverRequestParameters->isHttps());
334  }
335 
339  public function ‪getRequestHostReturnsRequestHost(): void
340  {
341  $serverParams = [
342  'HTTP_HOST' => 'www.domain.com',
343  'HTTPS' => 'on',
344  ];
345  $expected = 'https://www.domain.com';
346  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
347  self::assertSame($expected, $serverRequestParameters->getRequestHost());
348  }
349 
353  public static function ‪getScriptNameReturnsExpectedValueDataProvider(): array
354  {
355  return [
356  'empty string if nothing is set' => [
357  [
358  'HTTP_HOST' => 'www.domain.com',
359  ],
360  [],
361  '',
362  ],
363  'use SCRIPT_NAME' => [
364  [
365  'SCRIPT_NAME' => '/script/name.php',
366  ],
367  [],
368  '/script/name.php',
369  ],
370  'apply URL encoding to SCRIPT_NAME' => [
371  [
372  'SCRIPT_NAME' => '/test:site/script/name.php',
373  ],
374  [],
375  '/test%3Asite/script/name.php',
376  ],
377  'add proxy ssl prefix' => [
378  [
379  'REMOTE_ADDR' => '123.123.123.123',
380  'HTTPS' => 'on',
381  'SCRIPT_NAME' => '/path/info.php',
382  ],
383  [
384  'reverseProxyIP' => '123.123.123.123',
385  'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
386  ],
387  '/proxyPrefixSSL/path/info.php',
388  ],
389  'add proxy prefix' => [
390  [
391  'REMOTE_ADDR' => '123.123.123.123',
392  'SCRIPT_NAME' => '/path/info.php',
393  ],
394  [
395  'reverseProxyIP' => '123.123.123.123',
396  'reverseProxyPrefix' => '/proxyPrefix',
397  ],
398  '/proxyPrefix/path/info.php',
399  ],
400  ];
401  }
402 
407  public function ‪getScriptNameReturnsExpectedValue(array $serverParams, array $configuration, string $expected): void
408  {
409  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
410  self::assertSame($expected, $serverRequestParameters->getScriptName());
411  }
412 
416  public static function ‪getRequestUriReturnsExpectedValueDataProvider(): array
417  {
418  return [
419  'slash if nothing is set' => [
420  [
421  'HTTP_HOST' => 'www.domain.com',
422  ],
423  [],
424  '/',
425  ],
426  'use REQUEST_URI' => [
427  [
428  'HTTP_HOST' => 'www.domain.com',
429  'REQUEST_URI' => 'typo3/bar?id=42',
430  ],
431  [],
432  '/typo3/bar?id=42',
433  ],
434  'use query string and script name if REQUEST_URI is not set' => [
435  [
436  'QUERY_STRING' => 'parameter=foo/bar&id=42',
437  'SCRIPT_NAME' => '/typo3/index.php',
438  ],
439  [],
440  '/typo3/index.php?parameter=foo/bar&id=42',
441  ],
442  'use query string and script name in special subdirectory if REQUEST_URI is not set' => [
443  [
444  'QUERY_STRING' => 'parameter=foo/bar&id=42',
445  'SCRIPT_NAME' => '/sub:dir/typo3/index.php',
446  ],
447  [],
448  '/sub%3Adir/typo3/index.php?parameter=foo/bar&id=42',
449  ],
450  'prefix with proxy prefix with ssl if using REQUEST_URI' => [
451  [
452  'HTTP_HOST' => 'www.domain.com',
453  'REMOTE_ADDR' => '123.123.123.123',
454  'HTTPS' => 'on',
455  'REQUEST_URI' => 'typo3/foo/bar?id=42',
456  ],
457  [
458  'reverseProxyIP' => '123.123.123.123',
459  'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
460  ],
461  '/proxyPrefixSSL/typo3/foo/bar?id=42',
462  ],
463  'prefix with proxy prefix if using REQUEST_URI' => [
464  [
465  'HTTP_HOST' => 'www.domain.com',
466  'REMOTE_ADDR' => '123.123.123.123',
467  'REQUEST_URI' => 'typo3/foo/bar?id=42',
468  ],
469  [
470  'reverseProxyIP' => '123.123.123.123',
471  'reverseProxyPrefix' => '/proxyPrefix',
472  ],
473  '/proxyPrefix/typo3/foo/bar?id=42',
474  ],
475  'prefix with proxy prefix with ssl if using query string and script name' => [
476  [
477  'REMOTE_ADDR' => '123.123.123.123',
478  'HTTPS' => 'on',
479  'QUERY_STRING' => 'parameter=foo/bar&id=42',
480  'SCRIPT_NAME' => '/typo3/index.php',
481  ],
482  [
483  'reverseProxyIP' => '123.123.123.123',
484  'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
485  ],
486  '/proxyPrefixSSL/typo3/index.php?parameter=foo/bar&id=42',
487  ],
488  'prefix with proxy prefix if using query string and script name' => [
489  [
490  'REMOTE_ADDR' => '123.123.123.123',
491  'HTTPS' => 'on',
492  'QUERY_STRING' => 'parameter=foo/bar&id=42',
493  'SCRIPT_NAME' => '/typo3/index.php',
494  ],
495  [
496  'reverseProxyIP' => '123.123.123.123',
497  'reverseProxyPrefix' => '/proxyPrefix',
498  ],
499  '/proxyPrefix/typo3/index.php?parameter=foo/bar&id=42',
500  ],
501  ];
502  }
503 
508  public function ‪getRequestUriReturnsExpectedValue(array $serverParams, array $configuration, string $expected): void
509  {
510  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
511  self::assertSame($expected, $serverRequestParameters->getRequestUri());
512  }
513 
518  {
519  ‪$GLOBALS['foo']['bar'] = '/foo/bar.php';
520  $serverParams = [
521  'HTTP_HOST' => 'www.domain.com',
522  ];
523  $configuration = [
524  'requestURIvar' => 'foo|bar',
525  ];
526  $expected = '/foo/bar.php';
527  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
528  self::assertSame($expected, $serverRequestParameters->getRequestUri());
529  }
530 
534  public function ‪getRequestUrlReturnsExpectedValue(): void
535  {
536  $serverParams = [
537  'HTTP_HOST' => 'www.domain.com',
538  'REQUEST_URI' => 'typo3/foo/bar?id=42',
539  ];
540  $expected = 'http://www.domain.com/typo3/foo/bar?id=42';
541  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
542  self::assertSame($expected, $serverRequestParameters->getRequestUrl());
543  }
544 
549  {
550  $serverParams = [
551  'HTTP_HOST' => 'www.domain.com',
552  'SCRIPT_NAME' => '/typo3/index.php',
553  ];
554  $expected = 'http://www.domain.com/typo3/index.php';
555  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
556  self::assertSame($expected, $serverRequestParameters->getRequestScript());
557  }
558 
562  public function ‪getRequestDirReturnsExpectedValue(): void
563  {
564  $serverParams = [
565  'HTTP_HOST' => 'www.domain.com',
566  'SCRIPT_NAME' => '/typo3/index.php',
567  ];
568  $expected = 'http://www.domain.com/typo3/';
569  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
570  self::assertSame($expected, $serverRequestParameters->getRequestDir());
571  }
572 
577  {
578  return [
579  'false with empty data' => [
580  [
581  'HTTP_HOST' => 'www.domain.com',
582  ],
583  [],
584  false,
585  ],
586  'false if REMOTE_ADDR and reverseProxyIP do not match' => [
587  [
588  'HTTP_HOST' => 'www.domain.com',
589  'REMOTE_ADDR' => '100.100.100.100',
590  ],
591  [
592  'reverseProxyIP' => '200.200.200.200',
593  ],
594  false,
595  ],
596  'true if REMOTE_ADDR matches configured reverseProxyIP' => [
597  [
598  'HTTP_HOST' => 'www.domain.com',
599  'REMOTE_ADDR' => '100.100.100.100',
600  ],
601  [
602  'reverseProxyIP' => '100.100.100.100',
603  ],
604  true,
605  ],
606  'true if trimmed REMOTE_ADDR matches configured trimmed reverseProxyIP' => [
607  [
608  'HTTP_HOST' => 'www.domain.com',
609  'REMOTE_ADDR' => ' 100.100.100.100 ',
610  ],
611  [
612  'reverseProxyIP' => ' 100.100.100.100 ',
613  ],
614  true,
615  ],
616  ];
617  }
618 
623  public function ‪isBehindReverseProxyReturnsExpectedValue(array $serverParams, array $configuration, bool $expected): void
624  {
625  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
626  self::assertSame($expected, $serverRequestParameters->isBehindReverseProxy());
627  }
628 
633  {
634  return [
635  'simple REMOTE_ADDR' => [
636  [
637  'HTTP_HOST' => 'www.domain.com',
638  'REMOTE_ADDR' => ' 123.123.123.123 ',
639  ],
640  [],
641  '123.123.123.123',
642  ],
643  'reverse proxy with last HTTP_X_FORWARDED_FOR' => [
644  [
645  'HTTP_HOST' => 'www.domain.com',
646  'REMOTE_ADDR' => ' 123.123.123.123 ',
647  'HTTP_X_FORWARDED_FOR' => ' 234.234.234.234, 235.235.235.235,',
648  ],
649  [
650  'reverseProxyIP' => '123.123.123.123',
651  'reverseProxyHeaderMultiValue' => ' last ',
652  ],
653  '235.235.235.235',
654  ],
655  'reverse proxy with first HTTP_X_FORWARDED_FOR' => [
656  [
657  'HTTP_HOST' => 'www.domain.com',
658  'REMOTE_ADDR' => ' 123.123.123.123 ',
659  'HTTP_X_FORWARDED_FOR' => ' 234.234.234.234, 235.235.235.235,',
660  ],
661  [
662  'reverseProxyIP' => '123.123.123.123 ',
663  'reverseProxyHeaderMultiValue' => ' first ',
664  ],
665  '234.234.234.234',
666  ],
667  'reverse proxy with broken reverseProxyHeaderMultiValue returns REMOTE_ADDR' => [
668  [
669  'HTTP_HOST' => 'www.domain.com',
670  'REMOTE_ADDR' => ' 123.123.123.123 ',
671  'HTTP_X_FORWARDED_FOR' => ' 234.234.234.234, 235.235.235.235,',
672  ],
673  [
674  'reverseProxyIP' => '123.123.123.123 ',
675  'reverseProxyHeaderMultiValue' => ' foo ',
676  ],
677  '123.123.123.123',
678  ],
679  ];
680  }
681 
686  public function ‪getRemoteAddressReturnsExpectedValue(array $serverParams, array $configuration, string $expected): void
687  {
688  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
689  self::assertSame($expected, $serverRequestParameters->getRemoteAddress());
690  }
691 
693  {
694  return [
695  'localhost ipv4 without port' => [
696  [
697  'HTTP_HOST' => '127.0.0.1',
698  ],
699  '127.0.0.1',
700  ],
701  'localhost ipv4 with port' => [
702  [
703  'HTTP_HOST' => '127.0.0.1:81',
704  ],
705  '127.0.0.1',
706  ],
707  'localhost ipv6 without port' => [
708  [
709  'HTTP_HOST' => '[::1]',
710  ],
711  '[::1]',
712  ],
713  'localhost ipv6 with port' => [
714  [
715  'HTTP_HOST' => '[::1]:81',
716  ],
717  '[::1]',
718  ],
719  'ipv6 without port' => [
720  [
721  'HTTP_HOST' => '[2001:DB8::1]',
722  ],
723  '[2001:DB8::1]',
724  ],
725  'ipv6 with port' => [
726  [
727  'HTTP_HOST' => '[2001:DB8::1]:81',
728  ],
729  '[2001:DB8::1]',
730  ],
731  'hostname without port' => [
732  [
733  'HTTP_HOST' => 'lolli.did.this',
734  ],
735  'lolli.did.this',
736  ],
737  'hostname with port' => [
738  [
739  'HTTP_HOST' => 'lolli.did.this:42',
740  ],
741  'lolli.did.this',
742  ],
743  ];
744  }
745 
750  public function ‪getRequestHostOnlyReturnsExpectedValue(array $serverParams, string $expected): void
751  {
752  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
753  self::assertSame($expected, $serverRequestParameters->getRequestHostOnly());
754  }
755 
757  {
758  return [
759  'localhost ipv4 without port' => [
760  [
761  'HTTP_HOST' => '127.0.0.1',
762  ],
763  0,
764  ],
765  'localhost ipv4 with port' => [
766  [
767  'HTTP_HOST' => '127.0.0.1:81',
768  ],
769  81,
770  ],
771  'localhost ipv6 without port' => [
772  [
773  'HTTP_HOST' => '[::1]',
774  ],
775  0,
776  ],
777  'localhost ipv6 with port' => [
778  [
779  'HTTP_HOST' => '[::1]:81',
780  ],
781  81,
782  ],
783  'ipv6 without port' => [
784  [
785  'HTTP_HOST' => '[2001:DB8::1]',
786  ],
787  0,
788  ],
789  'ipv6 with port' => [
790  [
791  'HTTP_HOST' => '[2001:DB8::1]:81',
792  ],
793  81,
794  ],
795  'hostname without port' => [
796  [
797  'HTTP_HOST' => 'lolli.did.this',
798  ],
799  0,
800  ],
801  'hostname with port' => [
802  [
803  'HTTP_HOST' => 'lolli.did.this:42',
804  ],
805  42,
806  ],
807  ];
808  }
809 
814  public function ‪getRequestPortReturnsExpectedValue(array $serverParams, int $expected): void
815  {
816  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
817  self::assertSame($expected, $serverRequestParameters->getRequestPort());
818  }
819 
824  {
825  $serverParams = [
826  'HTTP_HOST' => 'www.domain.com',
827  'SCRIPT_NAME' => '/typo3/index.php',
828  ];
829  $pathSite = '/var/www/';
830  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '/var/www/typo3/index.php', $pathSite);
831  self::assertSame('/var/www/typo3/index.php', $serverRequestParameters->getScriptFilename());
832  }
833 
838  {
839  $serverParams = [
840  'HTTP_HOST' => 'www.domain.com',
841  'SCRIPT_NAME' => '/typo3/index.php',
842  ];
843  $pathThisScript = '/var/www/myInstance/Web/typo3/index.php';
844  $pathSite = '/var/www/myInstance/Web/';
845  $expected = '/var/www/myInstance/Web';
846  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
847  self::assertSame($expected, $serverRequestParameters->getDocumentRoot());
848  }
849 
853  public function ‪getSiteUrlReturnsExpectedUrl(): void
854  {
855  $serverParams = [
856  'SCRIPT_NAME' => '/typo3/index.php',
857  'HTTP_HOST' => 'www.domain.com',
858  ];
859  $pathThisScript = '/var/www/myInstance/Web/typo3/index.php';
860  $pathSite = '/var/www/myInstance/Web';
861  $expected = 'http://www.domain.com/';
862  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
863  self::assertSame($expected, $serverRequestParameters->getSiteUrl());
864  }
865 
870  {
871  $serverParams = [];
872  $pathThisScript = '/var/www/html/typo3temp/var/tests/acceptance/typo3/sysext/core/bin/typo3';
873  $pathSite = '/var/www/html/typo3temp/var/tests/acceptance/';
874  $expected = '/';
875  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
876  self::assertSame($expected, $serverRequestParameters->getSiteUrl());
877  }
878 
882  public static function ‪getSitePathReturnsExpectedPathDataProvider(): array
883  {
884  return [
885  'empty config' => [
886  [],
887  '',
888  '',
889  '',
890  ],
891  'not in a sub directory' => [
892  [
893  'SCRIPT_NAME' => '/typo3/index.php',
894  'HTTP_HOST' => 'www.domain.com',
895  ],
896  '/var/www/myInstance/Web/typo3/index.php',
897  '/var/www/myInstance/Web',
898  '/',
899  ],
900  'in a sub directory' => [
901  [
902  'SCRIPT_NAME' => '/some/sub/dir/typo3/index.php',
903  'HTTP_HOST' => 'www.domain.com',
904  ],
905  '/var/www/myInstance/Web/typo3/index.php',
906  '/var/www/myInstance/Web',
907  '/some/sub/dir/',
908  ],
909  ];
910  }
911 
916  public function ‪getSitePathReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected): void
917  {
918  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
919  self::assertSame($expected, $serverRequestParameters->getSitePath());
920  }
921 
925  public static function ‪getSiteScriptReturnsExpectedPathDataProvider(): array
926  {
927  return [
928  'not in a sub directory' => [
929  [
930  'SCRIPT_NAME' => '/typo3/index.php',
931  'REQUEST_URI' => '/typo3/index.php?id=42&foo=bar',
932  'HTTP_HOST' => 'www.domain.com',
933  ],
934  '/var/www/myInstance/Web/typo3/index.php',
935  '/var/www/myInstance/Web',
936  'typo3/index.php?id=42&foo=bar',
937  ],
938  'in a sub directory' => [
939  [
940  'SCRIPT_NAME' => '/some/sub/dir/typo3/index.php',
941  'REQUEST_URI' => '/some/sub/dir/typo3/index.php?id=42&foo=bar',
942  'HTTP_HOST' => 'www.domain.com',
943  ],
944  '/var/www/myInstance/Web/typo3/index.php',
945  '/var/www/myInstance/Web',
946  'typo3/index.php?id=42&foo=bar',
947  ],
948  'redirected to a sub directory' => [
949  'serverParams' => [
950  'REQUEST_URI' => '/',
951  'SCRIPT_NAME' => '/public/',
952  'HTTP_HOST' => 'www.domain.com',
953  ],
954  'pathThisScript' => '/var/www/html/public/index.php',
955  'pathSite' => '/var/www/html/html/public',
956  'expected' => '',
957  ],
958  ];
959  }
960 
965  public function ‪getSiteScriptReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected): void
966  {
967  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
968  self::assertSame($expected, $serverRequestParameters->getSiteScript());
969  }
970 
974  public function ‪getPathInfoReturnsExpectedValue(): void
975  {
976  $serverParams = [
977  'PATH_INFO' => '/foo/bar',
978  ];
979  $expected = '/foo/bar';
980  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
981  self::assertSame($expected, $serverRequestParameters->getPathInfo());
982  }
983 
988  {
989  $serverParams = [
990  'HTTP_REFERER' => 'https://www.domain.com/typo3/index.php?id=42',
991  ];
992  $expected = 'https://www.domain.com/typo3/index.php?id=42';
993  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
994  self::assertSame($expected, $serverRequestParameters->getHttpReferer());
995  }
996 
1001  {
1002  $serverParams = [
1003  'HTTP_USER_AGENT' => 'the client browser',
1004  ];
1005  $expected = 'the client browser';
1006  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1007  self::assertSame($expected, $serverRequestParameters->getHttpUserAgent());
1008  }
1009 
1014  {
1015  $serverParams = [
1016  'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
1017  ];
1018  $expected = 'gzip, deflate';
1019  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1020  self::assertSame($expected, $serverRequestParameters->getHttpAcceptEncoding());
1021  }
1022 
1027  {
1028  $serverParams = [
1029  'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
1030  ];
1031  $expected = 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7';
1032  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1033  self::assertSame($expected, $serverRequestParameters->getHttpAcceptLanguage());
1034  }
1035 
1040  {
1041  $serverParams = [
1042  'REMOTE_HOST' => 'www.clientDomain.com',
1043  ];
1044  $expected = 'www.clientDomain.com';
1045  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1046  self::assertSame($expected, $serverRequestParameters->getRemoteHost());
1047  }
1048 
1053  {
1054  $serverParams = [
1055  'QUERY_STRING' => 'id=42&foo=bar',
1056  ];
1057  $expected = 'id=42&foo=bar';
1058  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1059  self::assertSame($expected, $serverRequestParameters->getQueryString());
1060  }
1061 }
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestHostReturnsRequestHost
‪getRequestHostReturnsRequestHost()
Definition: NormalizedParamsTest.php:339
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestScriptReturnsExpectedValue
‪getRequestScriptReturnsExpectedValue()
Definition: NormalizedParamsTest.php:548
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestUriFetchesFromConfiguredRequestUriVar
‪getRequestUriFetchesFromConfiguredRequestUriVar()
Definition: NormalizedParamsTest.php:517
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpUserAgentReturnsExpectedValue
‪getHttpUserAgentReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1000
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getScriptFilenameReturnsThirdConstructorArgument
‪getScriptFilenameReturnsThirdConstructorArgument()
Definition: NormalizedParamsTest.php:823
‪TYPO3\CMS\Core\Tests\Unit\Http
Definition: ApplicationTypeTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSiteUrlReturnsExpectedUrlForCliCommand
‪getSiteUrlReturnsExpectedUrlForCliCommand()
Definition: NormalizedParamsTest.php:869
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\isHttpsReturnSanitizedValue
‪isHttpsReturnSanitizedValue(array $serverParams, array $configuration, bool $expected)
Definition: NormalizedParamsTest.php:330
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestHostOnlyReturnsExpectedValueDataProvider
‪static getRequestHostOnlyReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:692
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpAcceptEncodingReturnsExpectedValue
‪getHttpAcceptEncodingReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1013
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSiteScriptReturnsExpectedPath
‪getSiteScriptReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected)
Definition: NormalizedParamsTest.php:965
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestUriReturnsExpectedValue
‪getRequestUriReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
Definition: NormalizedParamsTest.php:508
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRemoteAddressReturnsExpectedValueDataProvider
‪static array[] getRemoteAddressReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:632
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRemoteHostReturnsExpectedValue
‪getRemoteHostReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1039
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSitePathReturnsExpectedPath
‪getSitePathReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected)
Definition: NormalizedParamsTest.php:916
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestUrlReturnsExpectedValue
‪getRequestUrlReturnsExpectedValue()
Definition: NormalizedParamsTest.php:534
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpAcceptLanguageReturnsExpectedValue
‪getHttpAcceptLanguageReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1026
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRemoteAddressReturnsExpectedValue
‪getRemoteAddressReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
Definition: NormalizedParamsTest.php:686
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getPathInfoReturnsExpectedValue
‪getPathInfoReturnsExpectedValue()
Definition: NormalizedParamsTest.php:974
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestDirReturnsExpectedValue
‪getRequestDirReturnsExpectedValue()
Definition: NormalizedParamsTest.php:562
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getScriptNameReturnsExpectedValueDataProvider
‪static array[] getScriptNameReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:353
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getDocumentRootReturnsExpectedPath
‪getDocumentRootReturnsExpectedPath()
Definition: NormalizedParamsTest.php:837
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpHostReturnsSanitizedValue
‪getHttpHostReturnsSanitizedValue(array $serverParams, array $configuration, string $expected)
Definition: NormalizedParamsTest.php:127
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestUriReturnsExpectedValueDataProvider
‪static array[] getRequestUriReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:416
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpHostReturnsSanitizedValueDataProvider
‪static array[] getHttpHostReturnsSanitizedValueDataProvider()
Definition: NormalizedParamsTest.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSiteScriptReturnsExpectedPathDataProvider
‪static array[] getSiteScriptReturnsExpectedPathDataProvider()
Definition: NormalizedParamsTest.php:925
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestPortReturnsExpectedValue
‪getRequestPortReturnsExpectedValue(array $serverParams, int $expected)
Definition: NormalizedParamsTest.php:814
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getQueryStringReturnsExpectedValue
‪getQueryStringReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1052
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSitePathReturnsExpectedPathDataProvider
‪static array[] getSitePathReturnsExpectedPathDataProvider()
Definition: NormalizedParamsTest.php:882
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpRefererReturnsExpectedValue
‪getHttpRefererReturnsExpectedValue()
Definition: NormalizedParamsTest.php:987
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\isHttpsReturnSanitizedValueDataProvider
‪static array[] isHttpsReturnSanitizedValueDataProvider()
Definition: NormalizedParamsTest.php:136
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getScriptNameReturnsExpectedValue
‪getScriptNameReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
Definition: NormalizedParamsTest.php:407
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest
Definition: NormalizedParamsTest.php:24
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestPortOnlyReturnsExpectedValueDataProvider
‪static getRequestPortOnlyReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:756
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:38
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestHostOnlyReturnsExpectedValue
‪getRequestHostOnlyReturnsExpectedValue(array $serverParams, string $expected)
Definition: NormalizedParamsTest.php:750
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\isBehindReverseProxyReturnsExpectedValueDataProvider
‪static array[] isBehindReverseProxyReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:576
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSiteUrlReturnsExpectedUrl
‪getSiteUrlReturnsExpectedUrl()
Definition: NormalizedParamsTest.php:853
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\isBehindReverseProxyReturnsExpectedValue
‪isBehindReverseProxyReturnsExpectedValue(array $serverParams, array $configuration, bool $expected)
Definition: NormalizedParamsTest.php:623