2 declare(strict_types = 1);
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
32 'simple HTTP_HOST' => [
34 'HTTP_HOST' =>
'www.domain.com'
39 'first HTTP_X_FORWARDED_HOST from configured proxy' => [
42 'REMOTE_ADDR' =>
'123.123.123.123',
43 'HTTP_X_FORWARDED_HOST' =>
'www.domain1.com, www.domain2.com,'
46 'reverseProxyIP' =>
' 123.123.123.123',
47 'reverseProxyHeaderMultiValue' =>
'first',
51 'last HTTP_X_FORWARDED_HOST from configured proxy' => [
54 'REMOTE_ADDR' =>
'123.123.123.123',
55 'HTTP_X_FORWARDED_HOST' =>
'www.domain1.com, www.domain2.com,'
58 'reverseProxyIP' =>
'123.123.123.123',
59 'reverseProxyHeaderMultiValue' =>
'last',
63 'simple HTTP_HOST if reverseProxyHeaderMultiValue is not configured' => [
65 'HTTP_HOST' =>
'www.domain.com',
66 'REMOTE_ADDR' =>
'123.123.123.123',
67 'HTTP_X_FORWARDED_HOST' =>
'www.domain1.com'
70 'reverseProxyIP' =>
'123.123.123.123',
74 'simple HTTP_HOST if proxy IP does not match' => [
76 'HTTP_HOST' =>
'www.domain.com',
77 'REMOTE_ADDR' =>
'123.123.123.123',
78 'HTTP_X_FORWARDED_HOST' =>
'www.domain1.com'
81 'reverseProxyIP' =>
'234.234.234.234',
82 'reverseProxyHeaderMultiValue' =>
'last',
86 'simple HTTP_HOST if REMOTE_ADDR misses' => [
88 'HTTP_HOST' =>
'www.domain.com',
89 'HTTP_X_FORWARDED_HOST' =>
'www.domain1.com'
92 'reverseProxyIP' =>
'234.234.234.234',
93 'reverseProxyHeaderMultiValue' =>
'last',
97 'simple HTTP_HOST if HTTP_X_FORWARDED_HOST is empty' => [
99 'HTTP_HOST' =>
'www.domain.com',
100 'REMOTE_ADDR' =>
'123.123.123.123',
101 'HTTP_X_FORWARDED_HOST' =>
''
104 'reverseProxyIP' =>
'123.123.123.123',
105 'reverseProxyHeaderMultiValue' =>
'last',
121 $serverRequestParameters =
new NormalizedParams($serverParams, $configuration,
'',
'');
122 $this->assertSame($expected, $serverRequestParameters->getHttpHost());
131 'false if nothing special is set' => [
133 'HTTP_HOST' =>
'www.domain.com',
138 'true if SSL_SESSION_ID is set' => [
140 'HTTP_HOST' =>
'www.domain.com',
141 'SSL_SESSION_ID' =>
'foo',
146 'false if SSL_SESSION_ID is empty' => [
148 'HTTP_HOST' =>
'www.domain.com',
149 'SSL_SESSION_ID' =>
'',
154 'true if HTTPS is "ON"' => [
156 'HTTP_HOST' =>
'www.domain.com',
162 'true if HTTPS is "on"' => [
164 'HTTP_HOST' =>
'www.domain.com',
170 'true if HTTPS is "1"' => [
172 'HTTP_HOST' =>
'www.domain.com',
178 'true if HTTPS is int(1)"' => [
180 'HTTP_HOST' =>
'www.domain.com',
186 'true if HTTPS is bool(true)' => [
188 'HTTP_HOST' =>
'www.domain.com',
196 'true if HTTPS is "somethingrandom"' => [
198 'HTTP_HOST' =>
'www.domain.com',
199 'HTTPS' =>
'somethingrandom',
204 'false if HTTPS is "0"' => [
206 'HTTP_HOST' =>
'www.domain.com',
212 'false if HTTPS is int(0)' => [
214 'HTTP_HOST' =>
'www.domain.com',
220 'false if HTTPS is float(0)' => [
222 'HTTP_HOST' =>
'www.domain.com',
228 'false if HTTPS is not on' => [
230 'HTTP_HOST' =>
'www.domain.com',
236 'false if HTTPS is empty' => [
238 'HTTP_HOST' =>
'www.domain.com',
244 'false if HTTPS is null' => [
246 'HTTP_HOST' =>
'www.domain.com',
252 'false if HTTPS is bool(false)' => [
254 'HTTP_HOST' =>
'www.domain.com',
273 'true if ssl proxy IP matches REMOTE_ADDR' => [
275 'HTTP_HOST' =>
'www.domain.com',
276 'REMOTE_ADDR' =>
'123.123.123.123 ',
279 'reverseProxySSL' =>
' 123.123.123.123',
283 'false if ssl proxy IP does not match REMOTE_ADDR' => [
285 'HTTP_HOST' =>
'www.domain.com',
286 'REMOTE_ADDR' =>
'123.123.123.123',
289 'reverseProxySSL' =>
'234.234.234.234',
293 'true if SSL proxy is * and reverse proxy IP matches REMOTE_ADDR' => [
295 'HTTP_HOST' =>
'www.domain.com',
296 'REMOTE_ADDR' =>
'123.123.123.123',
299 'reverseProxySSL' =>
'*',
300 'reverseProxyIP' =>
'123.123.123.123',
304 'false if SSL proxy is * and reverse proxy IP does not match REMOTE_ADDR' => [
306 'HTTP_HOST' =>
'www.domain.com',
307 'REMOTE_ADDR' =>
'123.123.123.123',
310 'reverseProxySSL' =>
'*',
311 'reverseProxyIP' =>
'234.234.234.234',
327 $serverRequestParameters =
new NormalizedParams($serverParams, $configuration,
'',
'');
328 $this->assertSame($expected, $serverRequestParameters->isHttps());
337 'HTTP_HOST' =>
'www.domain.com',
340 $expected =
'https://www.domain.com';
342 $this->assertSame($expected, $serverRequestParameters->getRequestHost());
351 'empty string if nothing is set' => [
353 'HTTP_HOST' =>
'www.domain.com',
358 'use ORIG_SCRIPT_NAME if ORIG_PATH_INFO is set but empty' => [
360 'ORIG_PATH_INFO' =>
'',
362 'ORIG_SCRIPT_NAME' =>
'/orig/script/name.php',
363 'SCRIPT_NAME' =>
'/script/name.php',
366 '/orig/script/name.php',
368 'use ORIG_SCRIPT_NAME if PATH_INFO is set but empty' => [
371 'ORIG_SCRIPT_NAME' =>
'/orig/script/name.php',
372 'SCRIPT_NAME' =>
'/script/name.php',
375 '/orig/script/name.php',
377 'use SCRIPT_NAME if ORIG_PATH_INFO is set but empty' => [
379 'ORIG_PATH_INFO' =>
'',
381 'ORIG_SCRIPT_NAME' =>
'',
382 'SCRIPT_NAME' =>
'/script/name.php',
387 'use SCRIPT_NAME if PATH_INFO is set but empty' => [
390 'ORIG_SCRIPT_NAME' =>
'',
391 'SCRIPT_NAME' =>
'/script/name.php',
396 'use SCRIPT_NAME if ORIG_PATH_INFO is set' => [
398 'ORIG_PATH_INFO' =>
'/foo/bar',
400 'ORIG_SCRIPT_NAME' =>
'',
401 'SCRIPT_NAME' =>
'/script/name.php',
406 'use SCRIPT_NAME if PATH_INFO is set' => [
408 'PATH_INFO' =>
'/foo/bar',
409 'ORIG_SCRIPT_NAME' =>
'',
410 'SCRIPT_NAME' =>
'/script/name.php',
415 'use ORIG_SCRIPT_NAME' => [
417 'ORIG_SCRIPT_NAME' =>
'/orig/script/name.php',
418 'SCRIPT_NAME' =>
'/script/name.php',
421 '/orig/script/name.php',
423 'use SCRIPT_NAME' => [
425 'SCRIPT_NAME' =>
'/script/name.php',
430 'add proxy ssl prefix' => [
432 'REMOTE_ADDR' =>
'123.123.123.123',
434 'SCRIPT_NAME' =>
'/path/info.php',
437 'reverseProxyIP' =>
'123.123.123.123',
438 'reverseProxyPrefixSSL' =>
'/proxyPrefixSSL',
440 '/proxyPrefixSSL/path/info.php',
442 'add proxy prefix' => [
444 'REMOTE_ADDR' =>
'123.123.123.123',
445 'SCRIPT_NAME' =>
'/path/info.php',
448 'reverseProxyIP' =>
'123.123.123.123',
449 'reverseProxyPrefix' =>
'/proxyPrefix',
451 '/proxyPrefix/path/info.php',
465 $serverRequestParameters =
new NormalizedParams($serverParams, $configuration,
'',
'');
466 $this->assertSame($expected, $serverRequestParameters->getScriptName());
475 'slash if nothing is set' => [
477 'HTTP_HOST' =>
'www.domain.com',
482 'use REQUEST_URI' => [
484 'HTTP_HOST' =>
'www.domain.com',
485 'REQUEST_URI' =>
'typo3/index.php?route=foo/bar&id=42',
488 '/typo3/index.php?route=foo/bar&id=42',
490 'use query string and script name if REQUEST_URI is not set' => [
492 'QUERY_STRING' =>
'route=foo/bar&id=42',
493 'SCRIPT_NAME' =>
'/typo3/index.php',
496 '/typo3/index.php?route=foo/bar&id=42',
498 'prefix with proxy prefix with ssl if using REQUEST_URI' => [
500 'HTTP_HOST' =>
'www.domain.com',
501 'REMOTE_ADDR' =>
'123.123.123.123',
503 'REQUEST_URI' =>
'typo3/index.php?route=foo/bar&id=42',
506 'reverseProxyIP' =>
'123.123.123.123',
507 'reverseProxyPrefixSSL' =>
'/proxyPrefixSSL',
509 '/proxyPrefixSSL/typo3/index.php?route=foo/bar&id=42',
511 'prefix with proxy prefix if using REQUEST_URI' => [
513 'HTTP_HOST' =>
'www.domain.com',
514 'REMOTE_ADDR' =>
'123.123.123.123',
515 'REQUEST_URI' =>
'typo3/index.php?route=foo/bar&id=42',
518 'reverseProxyIP' =>
'123.123.123.123',
519 'reverseProxyPrefix' =>
'/proxyPrefix',
521 '/proxyPrefix/typo3/index.php?route=foo/bar&id=42',
523 'prefix with proxy prefix with ssl if using query string and script name' => [
525 'REMOTE_ADDR' =>
'123.123.123.123',
527 'QUERY_STRING' =>
'route=foo/bar&id=42',
528 'SCRIPT_NAME' =>
'/typo3/index.php',
531 'reverseProxyIP' =>
'123.123.123.123',
532 'reverseProxyPrefixSSL' =>
'/proxyPrefixSSL',
534 '/proxyPrefixSSL/typo3/index.php?route=foo/bar&id=42',
536 'prefix with proxy prefix if using query string and script name' => [
538 'REMOTE_ADDR' =>
'123.123.123.123',
540 'QUERY_STRING' =>
'route=foo/bar&id=42',
541 'SCRIPT_NAME' =>
'/typo3/index.php',
544 'reverseProxyIP' =>
'123.123.123.123',
545 'reverseProxyPrefix' =>
'/proxyPrefix',
547 '/proxyPrefix/typo3/index.php?route=foo/bar&id=42',
561 $serverRequestParameters =
new NormalizedParams($serverParams, $configuration,
'',
'');
562 $this->assertSame($expected, $serverRequestParameters->getRequestUri());
570 $GLOBALS[
'foo'][
'bar'] =
'/foo/bar.php';
572 'HTTP_HOST' =>
'www.domain.com',
575 'requestURIvar' =>
'foo|bar',
577 $expected =
'/foo/bar.php';
578 $serverRequestParameters =
new NormalizedParams($serverParams, $configuration,
'',
'');
579 $this->assertSame($expected, $serverRequestParameters->getRequestUri());
588 'HTTP_HOST' =>
'www.domain.com',
589 'REQUEST_URI' =>
'typo3/index.php?route=foo/bar&id=42',
591 $expected =
'http://www.domain.com/typo3/index.php?route=foo/bar&id=42';
593 $this->assertSame($expected, $serverRequestParameters->getRequestUrl());
602 'HTTP_HOST' =>
'www.domain.com',
603 'SCRIPT_NAME' =>
'/typo3/index.php',
605 $expected =
'http://www.domain.com/typo3/index.php';
607 $this->assertSame($expected, $serverRequestParameters->getRequestScript());
616 'HTTP_HOST' =>
'www.domain.com',
617 'SCRIPT_NAME' =>
'/typo3/index.php',
619 $expected =
'http://www.domain.com/typo3/';
621 $this->assertSame($expected, $serverRequestParameters->getRequestDir());
630 'false with empty data' => [
632 'HTTP_HOST' =>
'www.domain.com',
637 'false if REMOTE_ADDR and reverseProxyIP do not match' => [
639 'HTTP_HOST' =>
'www.domain.com',
640 'REMOTE_ADDR' =>
'100.100.100.100',
643 'reverseProxyIP' =>
'200.200.200.200',
647 'true if REMOTE_ADDR matches configured reverseProxyIP' => [
649 'HTTP_HOST' =>
'www.domain.com',
650 'REMOTE_ADDR' =>
'100.100.100.100',
653 'reverseProxyIP' =>
'100.100.100.100',
657 'true if trimmed REMOTE_ADDR matches configured trimmed reverseProxyIP' => [
659 'HTTP_HOST' =>
'www.domain.com',
660 'REMOTE_ADDR' =>
' 100.100.100.100 ',
663 'reverseProxyIP' =>
' 100.100.100.100 ',
679 $serverRequestParameters =
new NormalizedParams($serverParams, $configuration,
'',
'');
680 $this->assertSame($expected, $serverRequestParameters->isBehindReverseProxy());
689 'simple REMOTE_ADDR' => [
691 'HTTP_HOST' =>
'www.domain.com',
692 'REMOTE_ADDR' =>
' 123.123.123.123 ',
697 'reverse proxy with last HTTP_X_FORWARDED_FOR' => [
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,',
704 'reverseProxyIP' =>
'123.123.123.123',
705 'reverseProxyHeaderMultiValue' =>
' last ',
709 'reverse proxy with first HTTP_X_FORWARDED_FOR' => [
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,',
716 'reverseProxyIP' =>
'123.123.123.123 ',
717 'reverseProxyHeaderMultiValue' =>
' first ',
721 'reverse proxy with broken reverseProxyHeaderMultiValue returns REMOTE_ADDR' => [
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,',
728 'reverseProxyIP' =>
'123.123.123.123 ',
729 'reverseProxyHeaderMultiValue' =>
' foo ',
745 $serverRequestParameters =
new NormalizedParams($serverParams, $configuration,
'',
'');
746 $this->assertSame($expected, $serverRequestParameters->getRemoteAddress());
755 'localhost ipv4 without port' => [
757 'HTTP_HOST' =>
'127.0.0.1',
761 'localhost ipv4 with port' => [
763 'HTTP_HOST' =>
'127.0.0.1:81',
767 'localhost ipv6 without port' => [
769 'HTTP_HOST' =>
'[::1]',
773 'localhost ipv6 with port' => [
775 'HTTP_HOST' =>
'[::1]:81',
779 'ipv6 without port' => [
781 'HTTP_HOST' =>
'[2001:DB8::1]',
785 'ipv6 with port' => [
787 'HTTP_HOST' =>
'[2001:DB8::1]:81',
791 'hostname without port' => [
793 'HTTP_HOST' =>
'lolli.did.this',
797 'hostname with port' => [
799 'HTTP_HOST' =>
'lolli.did.this:42',
815 $this->assertSame($expected, $serverRequestParameters->getRequestHostOnly());
824 'localhost ipv4 without port' => [
826 'HTTP_HOST' =>
'127.0.0.1',
830 'localhost ipv4 with port' => [
832 'HTTP_HOST' =>
'127.0.0.1:81',
836 'localhost ipv6 without port' => [
838 'HTTP_HOST' =>
'[::1]',
842 'localhost ipv6 with port' => [
844 'HTTP_HOST' =>
'[::1]:81',
848 'ipv6 without port' => [
850 'HTTP_HOST' =>
'[2001:DB8::1]',
854 'ipv6 with port' => [
856 'HTTP_HOST' =>
'[2001:DB8::1]:81',
860 'hostname without port' => [
862 'HTTP_HOST' =>
'lolli.did.this',
866 'hostname with port' => [
868 'HTTP_HOST' =>
'lolli.did.this:42',
884 $this->assertSame($expected, $serverRequestParameters->getRequestPort());
893 'HTTP_HOST' =>
'www.domain.com',
894 'SCRIPT_NAME' =>
'/typo3/index.php',
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());
907 'HTTP_HOST' =>
'www.domain.com',
908 'SCRIPT_NAME' =>
'/typo3/index.php',
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());
923 'SCRIPT_NAME' =>
'/typo3/index.php',
924 'HTTP_HOST' =>
'www.domain.com',
925 'PATH_INFO' =>
'/typo3/index.php',
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());
946 'not in a sub directory' => [
948 'SCRIPT_NAME' =>
'/typo3/index.php',
949 'HTTP_HOST' =>
'www.domain.com',
951 '/var/www/myInstance/Web/typo3/index.php',
952 '/var/www/myInstance/Web',
955 'in a sub directory' => [
957 'SCRIPT_NAME' =>
'/some/sub/dir/typo3/index.php',
958 'HTTP_HOST' =>
'www.domain.com',
960 '/var/www/myInstance/Web/typo3/index.php',
961 '/var/www/myInstance/Web',
977 $serverRequestParameters =
new NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
978 $this->assertSame($expected, $serverRequestParameters->getSitePath());
987 'not in a sub directory' => [
989 'SCRIPT_NAME' =>
'/typo3/index.php?id=42&foo=bar',
990 'HTTP_HOST' =>
'www.domain.com',
992 '/var/www/myInstance/Web/typo3/index.php',
993 '/var/www/myInstance/Web',
994 'typo3/index.php?id=42&foo=bar'
996 'in a sub directory' => [
998 'SCRIPT_NAME' =>
'/some/sub/dir/typo3/index.php?id=42&foo=bar',
999 'HTTP_HOST' =>
'www.domain.com',
1001 '/var/www/myInstance/Web/typo3/index.php',
1002 '/var/www/myInstance/Web',
1003 'typo3/index.php?id=42&foo=bar'
1005 'redirected to a sub directory' => [
1007 'REQUEST_URI' =>
'/',
1008 'SCRIPT_NAME' =>
'/public/',
1009 'HTTP_HOST' =>
'www.domain.com',
1011 'pathThisScript' =>
'/var/www/html/public/index.php',
1012 'pathSite' =>
'/var/www/html/html/public',
1028 $serverRequestParameters =
new NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
1029 $this->assertSame($expected, $serverRequestParameters->getSiteScript());
1038 'PATH_INFO' =>
'/typo3/index.php',
1040 $expected =
'/typo3/index.php';
1042 $this->assertSame($expected, $serverRequestParameters->getPathInfo());
1051 'HTTP_REFERER' =>
'https://www.domain.com/typo3/index.php?id=42',
1053 $expected =
'https://www.domain.com/typo3/index.php?id=42';
1055 $this->assertSame($expected, $serverRequestParameters->getHttpReferer());
1064 'HTTP_USER_AGENT' =>
'the client browser',
1066 $expected =
'the client browser';
1068 $this->assertSame($expected, $serverRequestParameters->getHttpUserAgent());
1077 'HTTP_ACCEPT_ENCODING' =>
'gzip, deflate',
1079 $expected =
'gzip, deflate';
1081 $this->assertSame($expected, $serverRequestParameters->getHttpAcceptEncoding());
1090 'HTTP_ACCEPT_LANGUAGE' =>
'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
1092 $expected =
'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7';
1094 $this->assertSame($expected, $serverRequestParameters->getHttpAcceptLanguage());
1103 'REMOTE_HOST' =>
'www.clientDomain.com',
1105 $expected =
'www.clientDomain.com';
1107 $this->assertSame($expected, $serverRequestParameters->getRemoteHost());
1116 'QUERY_STRING' =>
'id=42&foo=bar',
1118 $expected =
'id=42&foo=bar';
1120 $this->assertSame($expected, $serverRequestParameters->getQueryString());