Skip to content

Commit f22bd4e

Browse files
committed
[ticket/14481] Add tests for x_forwarded_proto header
PHPBB3-14481
1 parent 9eedf29 commit f22bd4e

1 file changed

Lines changed: 103 additions & 3 deletions

File tree

tests/request/request_test.php

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
class phpbb_request_test extends phpbb_test_case
1515
{
16+
/** @var \phpbb\request\type_cast_helper_interface */
1617
private $type_cast_helper;
18+
19+
/** @var \phpbb\request\request */
1720
private $request;
1821

1922
protected function setUp()
@@ -143,15 +146,112 @@ public function test_is_ajax_with_ajax()
143146
$this->assertTrue($this->request->is_ajax());
144147
}
145148

146-
public function test_is_secure()
149+
public function data_is_secure()
150+
{
151+
return array(
152+
array(
153+
array(
154+
'HTTPS' => 'on',
155+
),
156+
true,
157+
),
158+
array(
159+
array(
160+
'HTTPS' => '1',
161+
),
162+
true,
163+
),
164+
array(
165+
array(
166+
'HTTPS' => 'yes',
167+
),
168+
true,
169+
),
170+
array(
171+
array(
172+
'HTTPS' => 1,
173+
),
174+
true,
175+
),
176+
array(
177+
array(
178+
'HTTPS' => 'off',
179+
),
180+
false,
181+
),
182+
array(
183+
array(
184+
'HTTPS' => '0',
185+
),
186+
false,
187+
),
188+
array(
189+
array(
190+
'HTTPS' => 0,
191+
),
192+
false,
193+
),
194+
array(
195+
array(
196+
'HTTPS' => '',
197+
),
198+
false,
199+
),
200+
array(
201+
array(
202+
'HTTPS' => 'off',
203+
'HTTP_X_FORWARDED_PROTO' => 'https',
204+
),
205+
true,
206+
),
207+
array(
208+
array(
209+
'HTTPS' => 'on',
210+
'HTTP_X_FORWARDED_PROTO' => 'http',
211+
),
212+
true,
213+
),
214+
array(
215+
array(
216+
'HTTPS' => 'off',
217+
'HTTP_X_FORWARDED_PROTO' => 'http',
218+
),
219+
false,
220+
),
221+
array(
222+
array(
223+
'HTTP_X_FORWARDED_PROTO' => 'http',
224+
),
225+
false,
226+
),
227+
array(
228+
array(
229+
'HTTP_X_FORWARDED_PROTO' => 'https',
230+
),
231+
true,
232+
),
233+
array(
234+
array(
235+
'HTTPS' => 'on',
236+
'HTTP_X_FORWARDED_PROTO' => 'http',
237+
),
238+
true,
239+
),
240+
);
241+
}
242+
243+
/**
244+
* @dataProvider data_is_secure
245+
*/
246+
public function test_is_secure($server_data, $expected)
147247
{
148248
$this->assertFalse($this->request->is_secure());
149249

150250
$this->request->enable_super_globals();
151-
$_SERVER['HTTPS'] = 'on';
251+
$_SERVER = $server_data;
152252
$this->request = new \phpbb\request\request($this->type_cast_helper);
153253

154-
$this->assertTrue($this->request->is_secure());
254+
$this->assertSame($expected, $this->request->is_secure());
155255
}
156256

157257
public function test_variable_names()

0 commit comments

Comments
 (0)