|
13 | 13 |
|
14 | 14 | class phpbb_request_test extends phpbb_test_case |
15 | 15 | { |
| 16 | + /** @var \phpbb\request\type_cast_helper_interface */ |
16 | 17 | private $type_cast_helper; |
| 18 | + |
| 19 | + /** @var \phpbb\request\request */ |
17 | 20 | private $request; |
18 | 21 |
|
19 | 22 | protected function setUp() |
@@ -143,15 +146,112 @@ public function test_is_ajax_with_ajax() |
143 | 146 | $this->assertTrue($this->request->is_ajax()); |
144 | 147 | } |
145 | 148 |
|
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) |
147 | 247 | { |
148 | 248 | $this->assertFalse($this->request->is_secure()); |
149 | 249 |
|
150 | 250 | $this->request->enable_super_globals(); |
151 | | - $_SERVER['HTTPS'] = 'on'; |
| 251 | + $_SERVER = $server_data; |
152 | 252 | $this->request = new \phpbb\request\request($this->type_cast_helper); |
153 | 253 |
|
154 | | - $this->assertTrue($this->request->is_secure()); |
| 254 | + $this->assertSame($expected, $this->request->is_secure()); |
155 | 255 | } |
156 | 256 |
|
157 | 257 | public function test_variable_names() |
|
0 commit comments