6 require_once 'application/HttpUtils.php';
9 * Unitary tests for server_url()
11 class ServerUrlTest
extends PHPUnit_Framework_TestCase
14 * Detect if the server uses SSL
16 public function testHttpsScheme()
23 'SERVER_NAME' => 'host.tld',
24 'SERVER_PORT' => '443'
30 'https://host.tld:8080',
34 'SERVER_NAME' => 'host.tld',
35 'SERVER_PORT' => '8080'
42 * Detect a Proxy that sets Forwarded-Host
44 public function testHttpsProxyForwardedHost()
47 'https://host.tld:8080',
50 'HTTP_X_FORWARDED_PROTO' => 'https',
51 'HTTP_X_FORWARDED_PORT' => '8080',
52 'HTTP_X_FORWARDED_HOST' => 'host.tld'
58 'https://host.tld:4974',
61 'HTTP_X_FORWARDED_PROTO' => 'https, https',
62 'HTTP_X_FORWARDED_PORT' => '4974, 80',
63 'HTTP_X_FORWARDED_HOST' => 'host.tld, example.com'
70 * Detect a Proxy with SSL enabled
72 public function testHttpsProxyForward()
75 'https://host.tld:8080',
79 'SERVER_NAME' => 'host.tld',
80 'SERVER_PORT' => '80',
81 'HTTP_X_FORWARDED_PROTO' => 'https',
82 'HTTP_X_FORWARDED_PORT' => '8080'
92 'SERVER_NAME' => 'host.tld',
93 'SERVER_PORT' => '80',
94 'HTTP_X_FORWARDED_PROTO' => 'https'
104 'SERVER_NAME' => 'host.tld',
105 'SERVER_PORT' => '80',
106 'HTTP_X_FORWARDED_PROTO' => 'https',
107 'HTTP_X_FORWARDED_PORT' => '443'
113 'https://host.tld:4974',
117 'SERVER_NAME' => 'host.tld',
118 'SERVER_PORT' => '80',
119 'HTTP_X_FORWARDED_PROTO' => 'https, https',
120 'HTTP_X_FORWARDED_PORT' => '4974, 80'
127 * Detect if the server uses a specific port (!= 80)
129 public function testPort()
133 'http://host.tld:8080',
137 'SERVER_NAME' => 'host.tld',
138 'SERVER_PORT' => '8080'
145 'https://host.tld:8080',
149 'SERVER_NAME' => 'host.tld',
150 'SERVER_PORT' => '8080'
157 * HTTP server on port 80
159 public function testStandardHttpPort()
166 'SERVER_NAME' => 'host.tld',
167 'SERVER_PORT' => '80'
174 * HTTPS server on port 443
176 public function testStandardHttpsPort()
183 'SERVER_NAME' => 'host.tld',
184 'SERVER_PORT' => '443'
191 * Misconfigured server (see #1022): Proxy HTTP but 443
193 public function testHttpWithPort433()
200 'SERVER_NAME' => 'host.tld',
201 'SERVER_PORT' => '80',
202 'HTTP_X_FORWARDED_PROTO' => 'http',
203 'HTTP_X_FORWARDED_PORT' => '443'
213 'SERVER_NAME' => 'host.tld',
214 'SERVER_PORT' => '80',
215 'HTTP_X_FORWARDED_PROTO' => 'https, http',
216 'HTTP_X_FORWARDED_PORT' => '443, 80'