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