aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/HttpUtils/ServerUrlTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-12-03 00:34:53 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-12 22:47:48 +0100
commit51753e403fa69c0ce124ede27d300477e3e799ca (patch)
tree0afe2a84598648b49cc53bb3e8640569ac370240 /tests/HttpUtils/ServerUrlTest.php
parentfb1b182fbf0ee5afed586f77eec84d7a906831ef (diff)
downloadShaarli-51753e403fa69c0ce124ede27d300477e3e799ca.tar.gz
Shaarli-51753e403fa69c0ce124ede27d300477e3e799ca.tar.zst
Shaarli-51753e403fa69c0ce124ede27d300477e3e799ca.zip
namespacing: move HTTP utilities along \Shaarli\Http\ classes
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/HttpUtils/ServerUrlTest.php')
-rw-r--r--tests/HttpUtils/ServerUrlTest.php221
1 files changed, 0 insertions, 221 deletions
diff --git a/tests/HttpUtils/ServerUrlTest.php b/tests/HttpUtils/ServerUrlTest.php
deleted file mode 100644
index 324b827a..00000000
--- a/tests/HttpUtils/ServerUrlTest.php
+++ /dev/null
@@ -1,221 +0,0 @@
1<?php
2/**
3 * HttpUtils' tests
4 */
5
6require_once 'application/HttpUtils.php';
7
8/**
9 * Unitary tests for server_url()
10 */
11class ServerUrlTest extends PHPUnit_Framework_TestCase
12{
13 /**
14 * Detect if the server uses SSL
15 */
16 public function testHttpsScheme()
17 {
18 $this->assertEquals(
19 'https://host.tld',
20 server_url(
21 array(
22 'HTTPS' => 'ON',
23 'SERVER_NAME' => 'host.tld',
24 'SERVER_PORT' => '443'
25 )
26 )
27 );
28
29 $this->assertEquals(
30 'https://host.tld:8080',
31 server_url(
32 array(
33 'HTTPS' => 'ON',
34 'SERVER_NAME' => 'host.tld',
35 'SERVER_PORT' => '8080'
36 )
37 )
38 );
39 }
40
41 /**
42 * Detect a Proxy that sets Forwarded-Host
43 */
44 public function testHttpsProxyForwardedHost()
45 {
46 $this->assertEquals(
47 'https://host.tld:8080',
48 server_url(
49 array(
50 'HTTP_X_FORWARDED_PROTO' => 'https',
51 'HTTP_X_FORWARDED_PORT' => '8080',
52 'HTTP_X_FORWARDED_HOST' => 'host.tld'
53 )
54 )
55 );
56
57 $this->assertEquals(
58 'https://host.tld:4974',
59 server_url(
60 array(
61 'HTTP_X_FORWARDED_PROTO' => 'https, https',
62 'HTTP_X_FORWARDED_PORT' => '4974, 80',
63 'HTTP_X_FORWARDED_HOST' => 'host.tld, example.com'
64 )
65 )
66 );
67 }
68
69 /**
70 * Detect a Proxy with SSL enabled
71 */
72 public function testHttpsProxyForward()
73 {
74 $this->assertEquals(
75 'https://host.tld:8080',
76 server_url(
77 array(
78 'HTTPS' => 'Off',
79 'SERVER_NAME' => 'host.tld',
80 'SERVER_PORT' => '80',
81 'HTTP_X_FORWARDED_PROTO' => 'https',
82 'HTTP_X_FORWARDED_PORT' => '8080'
83 )
84 )
85 );
86
87 $this->assertEquals(
88 'https://host.tld',
89 server_url(
90 array(
91 'HTTPS' => 'Off',
92 'SERVER_NAME' => 'host.tld',
93 'SERVER_PORT' => '80',
94 'HTTP_X_FORWARDED_PROTO' => 'https'
95 )
96 )
97 );
98
99 $this->assertEquals(
100 'https://host.tld',
101 server_url(
102 array(
103 'HTTPS' => 'Off',
104 'SERVER_NAME' => 'host.tld',
105 'SERVER_PORT' => '80',
106 'HTTP_X_FORWARDED_PROTO' => 'https',
107 'HTTP_X_FORWARDED_PORT' => '443'
108 )
109 )
110 );
111
112 $this->assertEquals(
113 'https://host.tld:4974',
114 server_url(
115 array(
116 'HTTPS' => 'Off',
117 'SERVER_NAME' => 'host.tld',
118 'SERVER_PORT' => '80',
119 'HTTP_X_FORWARDED_PROTO' => 'https, https',
120 'HTTP_X_FORWARDED_PORT' => '4974, 80'
121 )
122 )
123 );
124 }
125
126 /**
127 * Detect if the server uses a specific port (!= 80)
128 */
129 public function testPort()
130 {
131 // HTTP
132 $this->assertEquals(
133 'http://host.tld:8080',
134 server_url(
135 array(
136 'HTTPS' => 'OFF',
137 'SERVER_NAME' => 'host.tld',
138 'SERVER_PORT' => '8080'
139 )
140 )
141 );
142
143 // HTTPS
144 $this->assertEquals(
145 'https://host.tld:8080',
146 server_url(
147 array(
148 'HTTPS' => 'ON',
149 'SERVER_NAME' => 'host.tld',
150 'SERVER_PORT' => '8080'
151 )
152 )
153 );
154 }
155
156 /**
157 * HTTP server on port 80
158 */
159 public function testStandardHttpPort()
160 {
161 $this->assertEquals(
162 'http://host.tld',
163 server_url(
164 array(
165 'HTTPS' => 'OFF',
166 'SERVER_NAME' => 'host.tld',
167 'SERVER_PORT' => '80'
168 )
169 )
170 );
171 }
172
173 /**
174 * HTTPS server on port 443
175 */
176 public function testStandardHttpsPort()
177 {
178 $this->assertEquals(
179 'https://host.tld',
180 server_url(
181 array(
182 'HTTPS' => 'ON',
183 'SERVER_NAME' => 'host.tld',
184 'SERVER_PORT' => '443'
185 )
186 )
187 );
188 }
189
190 /**
191 * Misconfigured server (see #1022): Proxy HTTP but 443
192 */
193 public function testHttpWithPort433()
194 {
195 $this->assertEquals(
196 'https://host.tld',
197 server_url(
198 array(
199 'HTTPS' => 'Off',
200 'SERVER_NAME' => 'host.tld',
201 'SERVER_PORT' => '80',
202 'HTTP_X_FORWARDED_PROTO' => 'http',
203 'HTTP_X_FORWARDED_PORT' => '443'
204 )
205 )
206 );
207
208 $this->assertEquals(
209 'https://host.tld',
210 server_url(
211 array(
212 'HTTPS' => 'Off',
213 'SERVER_NAME' => 'host.tld',
214 'SERVER_PORT' => '80',
215 'HTTP_X_FORWARDED_PROTO' => 'https, http',
216 'HTTP_X_FORWARDED_PORT' => '443, 80'
217 )
218 )
219 );
220 }
221}