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