‪TYPO3CMS  9.5
NormalizedParamsTest.php
Go to the documentation of this file.
1 <?php
2 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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪NormalizedParamsTest extends UnitTestCase
25 {
30  {
31  return [
32  'simple HTTP_HOST' => [
33  [
34  'HTTP_HOST' => 'www.domain.com'
35  ],
36  [],
37  'www.domain.com'
38  ],
39  'first HTTP_X_FORWARDED_HOST from configured proxy' => [
40  [
41  'HTTP_HOST' => '',
42  'REMOTE_ADDR' => '123.123.123.123',
43  'HTTP_X_FORWARDED_HOST' => 'www.domain1.com, www.domain2.com,'
44  ],
45  [
46  'reverseProxyIP' => ' 123.123.123.123',
47  'reverseProxyHeaderMultiValue' => 'first',
48  ],
49  'www.domain1.com',
50  ],
51  'last HTTP_X_FORWARDED_HOST from configured proxy' => [
52  [
53  'HTTP_HOST' => '',
54  'REMOTE_ADDR' => '123.123.123.123',
55  'HTTP_X_FORWARDED_HOST' => 'www.domain1.com, www.domain2.com,'
56  ],
57  [
58  'reverseProxyIP' => '123.123.123.123',
59  'reverseProxyHeaderMultiValue' => 'last',
60  ],
61  'www.domain2.com',
62  ],
63  'simple HTTP_HOST if reverseProxyHeaderMultiValue is not configured' => [
64  [
65  'HTTP_HOST' => 'www.domain.com',
66  'REMOTE_ADDR' => '123.123.123.123',
67  'HTTP_X_FORWARDED_HOST' => 'www.domain1.com'
68  ],
69  [
70  'reverseProxyIP' => '123.123.123.123',
71  ],
72  'www.domain.com',
73  ],
74  'simple HTTP_HOST if proxy IP does not match' => [
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' => '234.234.234.234',
82  'reverseProxyHeaderMultiValue' => 'last',
83  ],
84  'www.domain.com',
85  ],
86  'simple HTTP_HOST if REMOTE_ADDR misses' => [
87  [
88  'HTTP_HOST' => 'www.domain.com',
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 HTTP_X_FORWARDED_HOST is empty' => [
98  [
99  'HTTP_HOST' => 'www.domain.com',
100  'REMOTE_ADDR' => '123.123.123.123',
101  'HTTP_X_FORWARDED_HOST' => ''
102  ],
103  [
104  'reverseProxyIP' => '123.123.123.123',
105  'reverseProxyHeaderMultiValue' => 'last',
106  ],
107  'www.domain.com',
108  ],
109  ];
110  }
111 
119  public function ‪getHttpHostReturnsSanitizedValue(array $serverParams, array $configuration, string $expected)
120  {
121  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
122  $this->assertSame($expected, $serverRequestParameters->getHttpHost());
123  }
124 
129  {
130  return [
131  'false if nothing special is set' => [
132  [
133  'HTTP_HOST' => 'www.domain.com',
134  ],
135  [],
136  false
137  ],
138  'true if SSL_SESSION_ID is set' => [
139  [
140  'HTTP_HOST' => 'www.domain.com',
141  'SSL_SESSION_ID' => 'foo',
142  ],
143  [],
144  true
145  ],
146  'false if SSL_SESSION_ID is empty' => [
147  [
148  'HTTP_HOST' => 'www.domain.com',
149  'SSL_SESSION_ID' => '',
150  ],
151  [],
152  false
153  ],
154  'true if HTTPS is "ON"' => [
155  [
156  'HTTP_HOST' => 'www.domain.com',
157  'HTTPS' => 'ON',
158  ],
159  [],
160  true,
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 "1"' => [
171  [
172  'HTTP_HOST' => 'www.domain.com',
173  'HTTPS' => '1',
174  ],
175  [],
176  true,
177  ],
178  'true if HTTPS is int(1)"' => [
179  [
180  'HTTP_HOST' => 'www.domain.com',
181  'HTTPS' => 1,
182  ],
183  [],
184  true,
185  ],
186  'true if HTTPS is bool(true)' => [
187  [
188  'HTTP_HOST' => 'www.domain.com',
189  'HTTPS' => true,
190  ],
191  [],
192  true,
193  ],
194  // https://secure.php.net/manual/en/reserved.variables.server.php
195  // "Set to a non-empty value if the script was queried through the HTTPS protocol."
196  'true if HTTPS is "somethingrandom"' => [
197  [
198  'HTTP_HOST' => 'www.domain.com',
199  'HTTPS' => 'somethingrandom',
200  ],
201  [],
202  true,
203  ],
204  'false if HTTPS is "0"' => [
205  [
206  'HTTP_HOST' => 'www.domain.com',
207  'HTTPS' => '0',
208  ],
209  [],
210  false,
211  ],
212  'false if HTTPS is int(0)' => [
213  [
214  'HTTP_HOST' => 'www.domain.com',
215  'HTTPS' => 0,
216  ],
217  [],
218  false,
219  ],
220  'false if HTTPS is float(0)' => [
221  [
222  'HTTP_HOST' => 'www.domain.com',
223  'HTTPS' => 0.0,
224  ],
225  [],
226  false,
227  ],
228  'false if HTTPS is not on' => [
229  [
230  'HTTP_HOST' => 'www.domain.com',
231  'HTTPS' => 'off',
232  ],
233  [],
234  false,
235  ],
236  'false if HTTPS is empty' => [
237  [
238  'HTTP_HOST' => 'www.domain.com',
239  'HTTPS' => '',
240  ],
241  [],
242  false,
243  ],
244  'false if HTTPS is null' => [
245  [
246  'HTTP_HOST' => 'www.domain.com',
247  'HTTPS' => null,
248  ],
249  [],
250  false,
251  ],
252  'false if HTTPS is bool(false)' => [
253  [
254  'HTTP_HOST' => 'www.domain.com',
255  'HTTPS' => false,
256  ],
257  [],
258  false,
259  ],
260  // Per PHP documententation 'HTTPS' is:
261  // "Set to a non-empty value if the script
262  // was queried through the HTTPS protocol."
263  // So theoretically an empty array means HTTPS is off.
264  // We do not support that. Therefore this test is disabled.
265  //'false if HTTPS is an empty Array' => [
266  // [
267  // 'HTTP_HOST' => 'www.domain.com',
268  // 'HTTPS' => [],
269  // ],
270  // [],
271  // false,
272  //],
273  'true if ssl proxy IP matches REMOTE_ADDR' => [
274  [
275  'HTTP_HOST' => 'www.domain.com',
276  'REMOTE_ADDR' => '123.123.123.123 ',
277  ],
278  [
279  'reverseProxySSL' => ' 123.123.123.123',
280  ],
281  true
282  ],
283  'false if ssl proxy IP does not match REMOTE_ADDR' => [
284  [
285  'HTTP_HOST' => 'www.domain.com',
286  'REMOTE_ADDR' => '123.123.123.123',
287  ],
288  [
289  'reverseProxySSL' => '234.234.234.234',
290  ],
291  false
292  ],
293  'true if SSL proxy is * and reverse proxy IP matches REMOTE_ADDR' => [
294  [
295  'HTTP_HOST' => 'www.domain.com',
296  'REMOTE_ADDR' => '123.123.123.123',
297  ],
298  [
299  'reverseProxySSL' => '*',
300  'reverseProxyIP' => '123.123.123.123',
301  ],
302  true
303  ],
304  'false if SSL proxy is * and reverse proxy IP does not match REMOTE_ADDR' => [
305  [
306  'HTTP_HOST' => 'www.domain.com',
307  'REMOTE_ADDR' => '123.123.123.123',
308  ],
309  [
310  'reverseProxySSL' => '*',
311  'reverseProxyIP' => '234.234.234.234',
312  ],
313  false
314  ]
315  ];
316  }
317 
325  public function ‪isHttpsReturnSanitizedValue(array $serverParams, array $configuration, bool $expected)
326  {
327  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
328  $this->assertSame($expected, $serverRequestParameters->isHttps());
329  }
330 
335  {
336  $serverParams = [
337  'HTTP_HOST' => 'www.domain.com',
338  'HTTPS' => 'on',
339  ];
340  $expected = 'https://www.domain.com';
341  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
342  $this->assertSame($expected, $serverRequestParameters->getRequestHost());
343  }
344 
349  {
350  return [
351  'empty string if nothing is set' => [
352  [
353  'HTTP_HOST' => 'www.domain.com',
354  ],
355  [],
356  ''
357  ],
358  'use ORIG_SCRIPT_NAME if ORIG_PATH_INFO is set but empty' => [
359  [
360  'ORIG_PATH_INFO' => '',
361  'PATH_INFO' => '',
362  'ORIG_SCRIPT_NAME' => '/orig/script/name.php',
363  'SCRIPT_NAME' => '/script/name.php',
364  ],
365  [],
366  '/orig/script/name.php',
367  ],
368  'use ORIG_SCRIPT_NAME if PATH_INFO is set but empty' => [
369  [
370  'PATH_INFO' => '',
371  'ORIG_SCRIPT_NAME' => '/orig/script/name.php',
372  'SCRIPT_NAME' => '/script/name.php',
373  ],
374  [],
375  '/orig/script/name.php',
376  ],
377  'use SCRIPT_NAME if ORIG_PATH_INFO is set but empty' => [
378  [
379  'ORIG_PATH_INFO' => '',
380  'PATH_INFO' => '',
381  'ORIG_SCRIPT_NAME' => '',
382  'SCRIPT_NAME' => '/script/name.php',
383  ],
384  [],
385  '/script/name.php',
386  ],
387  'use SCRIPT_NAME if PATH_INFO is set but empty' => [
388  [
389  'PATH_INFO' => '',
390  'ORIG_SCRIPT_NAME' => '',
391  'SCRIPT_NAME' => '/script/name.php',
392  ],
393  [],
394  '/script/name.php',
395  ],
396  'use SCRIPT_NAME if ORIG_PATH_INFO is set' => [
397  [
398  'ORIG_PATH_INFO' => '/foo/bar',
399  'PATH_INFO' => '',
400  'ORIG_SCRIPT_NAME' => '',
401  'SCRIPT_NAME' => '/script/name.php',
402  ],
403  [],
404  '/script/name.php',
405  ],
406  'use SCRIPT_NAME if PATH_INFO is set' => [
407  [
408  'PATH_INFO' => '/foo/bar',
409  'ORIG_SCRIPT_NAME' => '',
410  'SCRIPT_NAME' => '/script/name.php',
411  ],
412  [],
413  '/script/name.php',
414  ],
415  'use ORIG_SCRIPT_NAME' => [
416  [
417  'ORIG_SCRIPT_NAME' => '/orig/script/name.php',
418  'SCRIPT_NAME' => '/script/name.php',
419  ],
420  [],
421  '/orig/script/name.php',
422  ],
423  'use SCRIPT_NAME' => [
424  [
425  'SCRIPT_NAME' => '/script/name.php',
426  ],
427  [],
428  '/script/name.php',
429  ],
430  'add proxy ssl prefix' => [
431  [
432  'REMOTE_ADDR' => '123.123.123.123',
433  'HTTPS' => 'on',
434  'SCRIPT_NAME' => '/path/info.php',
435  ],
436  [
437  'reverseProxyIP' => '123.123.123.123',
438  'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
439  ],
440  '/proxyPrefixSSL/path/info.php',
441  ],
442  'add proxy prefix' => [
443  [
444  'REMOTE_ADDR' => '123.123.123.123',
445  'SCRIPT_NAME' => '/path/info.php',
446  ],
447  [
448  'reverseProxyIP' => '123.123.123.123',
449  'reverseProxyPrefix' => '/proxyPrefix',
450  ],
451  '/proxyPrefix/path/info.php',
452  ],
453  ];
454  }
455 
463  public function ‪getScriptNameReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
464  {
465  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
466  $this->assertSame($expected, $serverRequestParameters->getScriptName());
467  }
468 
473  {
474  return [
475  'slash if nothing is set' => [
476  [
477  'HTTP_HOST' => 'www.domain.com',
478  ],
479  [],
480  '/'
481  ],
482  'use REQUEST_URI' => [
483  [
484  'HTTP_HOST' => 'www.domain.com',
485  'REQUEST_URI' => 'typo3/index.php?route=foo/bar&id=42',
486  ],
487  [],
488  '/typo3/index.php?route=foo/bar&id=42',
489  ],
490  'use query string and script name if REQUEST_URI is not set' => [
491  [
492  'QUERY_STRING' => 'route=foo/bar&id=42',
493  'SCRIPT_NAME' => '/typo3/index.php',
494  ],
495  [],
496  '/typo3/index.php?route=foo/bar&id=42',
497  ],
498  'prefix with proxy prefix with ssl if using REQUEST_URI' => [
499  [
500  'HTTP_HOST' => 'www.domain.com',
501  'REMOTE_ADDR' => '123.123.123.123',
502  'HTTPS' => 'on',
503  'REQUEST_URI' => 'typo3/index.php?route=foo/bar&id=42',
504  ],
505  [
506  'reverseProxyIP' => '123.123.123.123',
507  'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
508  ],
509  '/proxyPrefixSSL/typo3/index.php?route=foo/bar&id=42',
510  ],
511  'prefix with proxy prefix if using REQUEST_URI' => [
512  [
513  'HTTP_HOST' => 'www.domain.com',
514  'REMOTE_ADDR' => '123.123.123.123',
515  'REQUEST_URI' => 'typo3/index.php?route=foo/bar&id=42',
516  ],
517  [
518  'reverseProxyIP' => '123.123.123.123',
519  'reverseProxyPrefix' => '/proxyPrefix',
520  ],
521  '/proxyPrefix/typo3/index.php?route=foo/bar&id=42',
522  ],
523  'prefix with proxy prefix with ssl if using query string and script name' => [
524  [
525  'REMOTE_ADDR' => '123.123.123.123',
526  'HTTPS' => 'on',
527  'QUERY_STRING' => 'route=foo/bar&id=42',
528  'SCRIPT_NAME' => '/typo3/index.php',
529  ],
530  [
531  'reverseProxyIP' => '123.123.123.123',
532  'reverseProxyPrefixSSL' => '/proxyPrefixSSL',
533  ],
534  '/proxyPrefixSSL/typo3/index.php?route=foo/bar&id=42',
535  ],
536  'prefix with proxy prefix if using query string and script name' => [
537  [
538  'REMOTE_ADDR' => '123.123.123.123',
539  'HTTPS' => 'on',
540  'QUERY_STRING' => 'route=foo/bar&id=42',
541  'SCRIPT_NAME' => '/typo3/index.php',
542  ],
543  [
544  'reverseProxyIP' => '123.123.123.123',
545  'reverseProxyPrefix' => '/proxyPrefix',
546  ],
547  '/proxyPrefix/typo3/index.php?route=foo/bar&id=42',
548  ],
549  ];
550  }
551 
559  public function ‪getRequestUriReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
560  {
561  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
562  $this->assertSame($expected, $serverRequestParameters->getRequestUri());
563  }
564 
569  {
570  ‪$GLOBALS['foo']['bar'] = '/foo/bar.php';
571  $serverParams = [
572  'HTTP_HOST' => 'www.domain.com',
573  ];
574  $configuration = [
575  'requestURIvar' => 'foo|bar',
576  ];
577  $expected = '/foo/bar.php';
578  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
579  $this->assertSame($expected, $serverRequestParameters->getRequestUri());
580  }
581 
586  {
587  $serverParams = [
588  'HTTP_HOST' => 'www.domain.com',
589  'REQUEST_URI' => 'typo3/index.php?route=foo/bar&id=42',
590  ];
591  $expected = 'http://www.domain.com/typo3/index.php?route=foo/bar&id=42';
592  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
593  $this->assertSame($expected, $serverRequestParameters->getRequestUrl());
594  }
595 
600  {
601  $serverParams = [
602  'HTTP_HOST' => 'www.domain.com',
603  'SCRIPT_NAME' => '/typo3/index.php',
604  ];
605  $expected = 'http://www.domain.com/typo3/index.php';
606  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
607  $this->assertSame($expected, $serverRequestParameters->getRequestScript());
608  }
609 
614  {
615  $serverParams = [
616  'HTTP_HOST' => 'www.domain.com',
617  'SCRIPT_NAME' => '/typo3/index.php',
618  ];
619  $expected = 'http://www.domain.com/typo3/';
620  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
621  $this->assertSame($expected, $serverRequestParameters->getRequestDir());
622  }
623 
628  {
629  return [
630  'false with empty data' => [
631  [
632  'HTTP_HOST' => 'www.domain.com',
633  ],
634  [],
635  false
636  ],
637  'false if REMOTE_ADDR and reverseProxyIP do not match' => [
638  [
639  'HTTP_HOST' => 'www.domain.com',
640  'REMOTE_ADDR' => '100.100.100.100',
641  ],
642  [
643  'reverseProxyIP' => '200.200.200.200',
644  ],
645  false
646  ],
647  'true if REMOTE_ADDR matches configured reverseProxyIP' => [
648  [
649  'HTTP_HOST' => 'www.domain.com',
650  'REMOTE_ADDR' => '100.100.100.100',
651  ],
652  [
653  'reverseProxyIP' => '100.100.100.100',
654  ],
655  true
656  ],
657  'true if trimmed REMOTE_ADDR matches configured trimmed reverseProxyIP' => [
658  [
659  'HTTP_HOST' => 'www.domain.com',
660  'REMOTE_ADDR' => ' 100.100.100.100 ',
661  ],
662  [
663  'reverseProxyIP' => ' 100.100.100.100 ',
664  ],
665  true
666  ]
667  ];
668  }
669 
677  public function ‪isBehindReverseProxyReturnsExpectedValue(array $serverParams, array $configuration, bool $expected)
678  {
679  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
680  $this->assertSame($expected, $serverRequestParameters->isBehindReverseProxy());
681  }
682 
687  {
688  return [
689  'simple REMOTE_ADDR' => [
690  [
691  'HTTP_HOST' => 'www.domain.com',
692  'REMOTE_ADDR' => ' 123.123.123.123 ',
693  ],
694  [],
695  '123.123.123.123'
696  ],
697  'reverse proxy with last HTTP_X_FORWARDED_FOR' => [
698  [
699  'HTTP_HOST' => 'www.domain.com',
700  'REMOTE_ADDR' => ' 123.123.123.123 ',
701  'HTTP_X_FORWARDED_FOR' => ' 234.234.234.234, 235.235.235.235,',
702  ],
703  [
704  'reverseProxyIP' => '123.123.123.123',
705  'reverseProxyHeaderMultiValue' => ' last ',
706  ],
707  '235.235.235.235'
708  ],
709  'reverse proxy with first HTTP_X_FORWARDED_FOR' => [
710  [
711  'HTTP_HOST' => 'www.domain.com',
712  'REMOTE_ADDR' => ' 123.123.123.123 ',
713  'HTTP_X_FORWARDED_FOR' => ' 234.234.234.234, 235.235.235.235,',
714  ],
715  [
716  'reverseProxyIP' => '123.123.123.123 ',
717  'reverseProxyHeaderMultiValue' => ' first ',
718  ],
719  '234.234.234.234'
720  ],
721  'reverse proxy with broken reverseProxyHeaderMultiValue returns REMOTE_ADDR' => [
722  [
723  'HTTP_HOST' => 'www.domain.com',
724  'REMOTE_ADDR' => ' 123.123.123.123 ',
725  'HTTP_X_FORWARDED_FOR' => ' 234.234.234.234, 235.235.235.235,',
726  ],
727  [
728  'reverseProxyIP' => '123.123.123.123 ',
729  'reverseProxyHeaderMultiValue' => ' foo ',
730  ],
731  '123.123.123.123'
732  ],
733  ];
734  }
735 
743  public function ‪getRemoteAddressReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
744  {
745  $serverRequestParameters = new ‪NormalizedParams($serverParams, $configuration, '', '');
746  $this->assertSame($expected, $serverRequestParameters->getRemoteAddress());
747  }
748 
753  {
754  return [
755  'localhost ipv4 without port' => [
756  [
757  'HTTP_HOST' => '127.0.0.1',
758  ],
759  '127.0.0.1'
760  ],
761  'localhost ipv4 with port' => [
762  [
763  'HTTP_HOST' => '127.0.0.1:81',
764  ],
765  '127.0.0.1'
766  ],
767  'localhost ipv6 without port' => [
768  [
769  'HTTP_HOST' => '[::1]',
770  ],
771  '[::1]'
772  ],
773  'localhost ipv6 with port' => [
774  [
775  'HTTP_HOST' => '[::1]:81',
776  ],
777  '[::1]'
778  ],
779  'ipv6 without port' => [
780  [
781  'HTTP_HOST' => '[2001:DB8::1]',
782  ],
783  '[2001:DB8::1]'
784  ],
785  'ipv6 with port' => [
786  [
787  'HTTP_HOST' => '[2001:DB8::1]:81',
788  ],
789  '[2001:DB8::1]'
790  ],
791  'hostname without port' => [
792  [
793  'HTTP_HOST' => 'lolli.did.this',
794  ],
795  'lolli.did.this'
796  ],
797  'hostname with port' => [
798  [
799  'HTTP_HOST' => 'lolli.did.this:42',
800  ],
801  'lolli.did.this'
802  ],
803  ];
804  }
805 
812  public function ‪getRequestHostOnlyReturnsExpectedValue(array $serverParams, string $expected)
813  {
814  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
815  $this->assertSame($expected, $serverRequestParameters->getRequestHostOnly());
816  }
817 
822  {
823  return [
824  'localhost ipv4 without port' => [
825  [
826  'HTTP_HOST' => '127.0.0.1',
827  ],
828  0
829  ],
830  'localhost ipv4 with port' => [
831  [
832  'HTTP_HOST' => '127.0.0.1:81',
833  ],
834  81
835  ],
836  'localhost ipv6 without port' => [
837  [
838  'HTTP_HOST' => '[::1]',
839  ],
840  0
841  ],
842  'localhost ipv6 with port' => [
843  [
844  'HTTP_HOST' => '[::1]:81',
845  ],
846  81
847  ],
848  'ipv6 without port' => [
849  [
850  'HTTP_HOST' => '[2001:DB8::1]',
851  ],
852  0
853  ],
854  'ipv6 with port' => [
855  [
856  'HTTP_HOST' => '[2001:DB8::1]:81',
857  ],
858  81
859  ],
860  'hostname without port' => [
861  [
862  'HTTP_HOST' => 'lolli.did.this',
863  ],
864  0
865  ],
866  'hostname with port' => [
867  [
868  'HTTP_HOST' => 'lolli.did.this:42',
869  ],
870  42
871  ],
872  ];
873  }
874 
881  public function ‪getRequestPortReturnsExpectedValue(array $serverParams, int $expected)
882  {
883  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
884  $this->assertSame($expected, $serverRequestParameters->getRequestPort());
885  }
886 
891  {
892  $serverParams = [
893  'HTTP_HOST' => 'www.domain.com',
894  'SCRIPT_NAME' => '/typo3/index.php',
895  ];
896  $pathSite = '/var/www/';
897  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '/var/www/typo3/index.php', $pathSite);
898  $this->assertSame('/var/www/typo3/index.php', $serverRequestParameters->getScriptFilename());
899  }
900 
905  {
906  $serverParams = [
907  'HTTP_HOST' => 'www.domain.com',
908  'SCRIPT_NAME' => '/typo3/index.php',
909  ];
910  $pathThisScript = '/var/www/myInstance/Web/typo3/index.php';
911  $pathSite = '/var/www/myInstance/Web/';
912  $expected = '/var/www/myInstance/Web';
913  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
914  $this->assertSame($expected, $serverRequestParameters->getDocumentRoot());
915  }
916 
921  {
922  $serverParams = [
923  'SCRIPT_NAME' => '/typo3/index.php',
924  'HTTP_HOST' => 'www.domain.com',
925  'PATH_INFO' => '/typo3/index.php',
926  ];
927  $pathThisScript = '/var/www/myInstance/Web/typo3/index.php';
928  $pathSite = '/var/www/myInstance/Web';
929  $expected = 'http://www.domain.com/';
930  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
931  $this->assertSame($expected, $serverRequestParameters->getSiteUrl());
932  }
933 
938  {
939  return [
940  'empty config' => [
941  [],
942  '',
943  '',
944  ''
945  ],
946  'not in a sub directory' => [
947  [
948  'SCRIPT_NAME' => '/typo3/index.php',
949  'HTTP_HOST' => 'www.domain.com',
950  ],
951  '/var/www/myInstance/Web/typo3/index.php',
952  '/var/www/myInstance/Web',
953  '/'
954  ],
955  'in a sub directory' => [
956  [
957  'SCRIPT_NAME' => '/some/sub/dir/typo3/index.php',
958  'HTTP_HOST' => 'www.domain.com',
959  ],
960  '/var/www/myInstance/Web/typo3/index.php',
961  '/var/www/myInstance/Web',
962  '/some/sub/dir/'
963  ],
964  ];
965  }
966 
975  public function ‪getSitePathReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected)
976  {
977  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
978  $this->assertSame($expected, $serverRequestParameters->getSitePath());
979  }
980 
985  {
986  return [
987  'not in a sub directory' => [
988  [
989  'SCRIPT_NAME' => '/typo3/index.php?id=42&foo=bar',
990  'HTTP_HOST' => 'www.domain.com',
991  ],
992  '/var/www/myInstance/Web/typo3/index.php',
993  '/var/www/myInstance/Web',
994  'typo3/index.php?id=42&foo=bar'
995  ],
996  'in a sub directory' => [
997  [
998  'SCRIPT_NAME' => '/some/sub/dir/typo3/index.php?id=42&foo=bar',
999  'HTTP_HOST' => 'www.domain.com',
1000  ],
1001  '/var/www/myInstance/Web/typo3/index.php',
1002  '/var/www/myInstance/Web',
1003  'typo3/index.php?id=42&foo=bar'
1004  ],
1005  'redirected to a sub directory' => [
1006  'serverParams' => [
1007  'REQUEST_URI' => '/',
1008  'SCRIPT_NAME' => '/public/',
1009  'HTTP_HOST' => 'www.domain.com',
1010  ],
1011  'pathThisScript' => '/var/www/html/public/index.php',
1012  'pathSite' => '/var/www/html/html/public',
1013  'expected' => ''
1014  ],
1015  ];
1016  }
1017 
1026  public function ‪getSiteScriptReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected)
1027  {
1028  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
1029  $this->assertSame($expected, $serverRequestParameters->getSiteScript());
1030  }
1031 
1036  {
1037  $serverParams = [
1038  'PATH_INFO' => '/typo3/index.php',
1039  ];
1040  $expected = '/typo3/index.php';
1041  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1042  $this->assertSame($expected, $serverRequestParameters->getPathInfo());
1043  }
1044 
1049  {
1050  $serverParams = [
1051  'HTTP_REFERER' => 'https://www.domain.com/typo3/index.php?id=42',
1052  ];
1053  $expected = 'https://www.domain.com/typo3/index.php?id=42';
1054  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1055  $this->assertSame($expected, $serverRequestParameters->getHttpReferer());
1056  }
1057 
1062  {
1063  $serverParams = [
1064  'HTTP_USER_AGENT' => 'the client browser',
1065  ];
1066  $expected = 'the client browser';
1067  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1068  $this->assertSame($expected, $serverRequestParameters->getHttpUserAgent());
1069  }
1070 
1075  {
1076  $serverParams = [
1077  'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
1078  ];
1079  $expected = 'gzip, deflate';
1080  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1081  $this->assertSame($expected, $serverRequestParameters->getHttpAcceptEncoding());
1082  }
1083 
1088  {
1089  $serverParams = [
1090  'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
1091  ];
1092  $expected = 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7';
1093  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1094  $this->assertSame($expected, $serverRequestParameters->getHttpAcceptLanguage());
1095  }
1096 
1101  {
1102  $serverParams = [
1103  'REMOTE_HOST' => 'www.clientDomain.com',
1104  ];
1105  $expected = 'www.clientDomain.com';
1106  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1107  $this->assertSame($expected, $serverRequestParameters->getRemoteHost());
1108  }
1109 
1114  {
1115  $serverParams = [
1116  'QUERY_STRING' => 'id=42&foo=bar',
1117  ];
1118  $expected = 'id=42&foo=bar';
1119  $serverRequestParameters = new ‪NormalizedParams($serverParams, [], '', '');
1120  $this->assertSame($expected, $serverRequestParameters->getQueryString());
1121  }
1122 }
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestHostReturnsRequestHost
‪getRequestHostReturnsRequestHost()
Definition: NormalizedParamsTest.php:334
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestScriptReturnsExpectedValue
‪getRequestScriptReturnsExpectedValue()
Definition: NormalizedParamsTest.php:599
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestUriFetchesFromConfiguredRequestUriVar
‪getRequestUriFetchesFromConfiguredRequestUriVar()
Definition: NormalizedParamsTest.php:568
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpUserAgentReturnsExpectedValue
‪getHttpUserAgentReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1061
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getScriptFilenameReturnsThirdConstructorArgument
‪getScriptFilenameReturnsThirdConstructorArgument()
Definition: NormalizedParamsTest.php:890
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestUriReturnsExpectedValueDataProvider
‪array[] getRequestUriReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:472
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestPortOnlyReturnsExpectedValueDataProvider
‪static array getRequestPortOnlyReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:821
‪TYPO3\CMS\Core\Tests\Unit\Http
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSitePathReturnsExpectedPathDataProvider
‪array[] getSitePathReturnsExpectedPathDataProvider()
Definition: NormalizedParamsTest.php:937
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\isHttpsReturnSanitizedValue
‪isHttpsReturnSanitizedValue(array $serverParams, array $configuration, bool $expected)
Definition: NormalizedParamsTest.php:325
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpAcceptEncodingReturnsExpectedValue
‪getHttpAcceptEncodingReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1074
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSiteScriptReturnsExpectedPath
‪getSiteScriptReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected)
Definition: NormalizedParamsTest.php:1026
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\isHttpsReturnSanitizedValueDataProvider
‪array[] isHttpsReturnSanitizedValueDataProvider()
Definition: NormalizedParamsTest.php:128
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestUriReturnsExpectedValue
‪getRequestUriReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
Definition: NormalizedParamsTest.php:559
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRemoteHostReturnsExpectedValue
‪getRemoteHostReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1100
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSitePathReturnsExpectedPath
‪getSitePathReturnsExpectedPath(array $serverParams, string $pathThisScript, string $pathSite, string $expected)
Definition: NormalizedParamsTest.php:975
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSiteScriptReturnsExpectedPathDataProvider
‪array[] getSiteScriptReturnsExpectedPathDataProvider()
Definition: NormalizedParamsTest.php:984
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestUrlReturnsExpectedValue
‪getRequestUrlReturnsExpectedValue()
Definition: NormalizedParamsTest.php:585
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpAcceptLanguageReturnsExpectedValue
‪getHttpAcceptLanguageReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1087
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRemoteAddressReturnsExpectedValue
‪getRemoteAddressReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
Definition: NormalizedParamsTest.php:743
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getPathInfoReturnsExpectedValue
‪getPathInfoReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1035
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestHostOnlyReturnsExpectedValueDataProvider
‪static array getRequestHostOnlyReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:752
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestDirReturnsExpectedValue
‪getRequestDirReturnsExpectedValue()
Definition: NormalizedParamsTest.php:613
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\isBehindReverseProxyReturnsExpectedValueDataProvider
‪array[] isBehindReverseProxyReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:627
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getDocumentRootReturnsExpectedPath
‪getDocumentRootReturnsExpectedPath()
Definition: NormalizedParamsTest.php:904
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpHostReturnsSanitizedValue
‪getHttpHostReturnsSanitizedValue(array $serverParams, array $configuration, string $expected)
Definition: NormalizedParamsTest.php:119
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRemoteAddressReturnsExpectedValueDataProvider
‪array[] getRemoteAddressReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:686
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getScriptNameReturnsExpectedValueDataProvider
‪array[] getScriptNameReturnsExpectedValueDataProvider()
Definition: NormalizedParamsTest.php:348
‪$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:881
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getQueryStringReturnsExpectedValue
‪getQueryStringReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1113
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpRefererReturnsExpectedValue
‪getHttpRefererReturnsExpectedValue()
Definition: NormalizedParamsTest.php:1048
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getScriptNameReturnsExpectedValue
‪getScriptNameReturnsExpectedValue(array $serverParams, array $configuration, string $expected)
Definition: NormalizedParamsTest.php:463
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getHttpHostReturnsSanitizedValueDataProvider
‪array[] getHttpHostReturnsSanitizedValueDataProvider()
Definition: NormalizedParamsTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest
Definition: NormalizedParamsTest.php:25
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:32
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getRequestHostOnlyReturnsExpectedValue
‪getRequestHostOnlyReturnsExpectedValue(array $serverParams, string $expected)
Definition: NormalizedParamsTest.php:812
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\getSiteUrlReturnsExpectedUrl
‪getSiteUrlReturnsExpectedUrl()
Definition: NormalizedParamsTest.php:920
‪TYPO3\CMS\Core\Tests\Unit\Http\NormalizedParamsTest\isBehindReverseProxyReturnsExpectedValue
‪isBehindReverseProxyReturnsExpectedValue(array $serverParams, array $configuration, bool $expected)
Definition: NormalizedParamsTest.php:677