|
242 | 242 |
|
243 | 243 | }); |
244 | 244 |
|
| 245 | + it('redirect without www prefix for already has www prefix with configurable "remove_www_prefix" on force_all_routes', function () { |
| 246 | + |
| 247 | + $listener = new ForceHttps([ |
| 248 | + 'enable' => true, |
| 249 | + 'force_all_routes' => true, |
| 250 | + 'force_specific_routes' => [], |
| 251 | + 'strict_transport_security' => [ |
| 252 | + 'enable' => true, |
| 253 | + 'value' => 'max-age=31536000', |
| 254 | + ], |
| 255 | + 'add_www_prefix' => false, |
| 256 | + 'remove_www_prefix' => true, |
| 257 | + ]); |
| 258 | + |
| 259 | + allow($this->uri)->toReceive('toString')->andReturn('http://www.example.com/about'); |
| 260 | + allow($this->mvcEvent)->toReceive('getRequest')->andReturn($this->request); |
| 261 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 262 | + allow($this->uri)->toReceive('getScheme')->andReturn('http'); |
| 263 | + allow($this->mvcEvent)->toReceive('getRouteMatch', 'getMatchedRouteName')->andReturn('about'); |
| 264 | + allow($this->uri)->toReceive('setScheme')->with('https')->andReturn($this->uri); |
| 265 | + allow($this->uri)->toReceive('toString')->andReturn('https://www.example.com/about'); |
| 266 | + allow($this->mvcEvent)->toReceive('getResponse')->andReturn($this->response); |
| 267 | + allow($this->response)->toReceive('getHeaders', 'addHeaderLine') |
| 268 | + ->with('Location', 'https://example.com/about') |
| 269 | + ->andReturn($this->response); |
| 270 | + allow($this->response)->toReceive('setStatusCode')->with(308)->andReturn($this->response); |
| 271 | + allow($this->response)->toReceive('send'); |
| 272 | + |
| 273 | + $listener->forceHttpsScheme($this->mvcEvent); |
| 274 | + |
| 275 | + expect($this->mvcEvent)->toReceive('getResponse'); |
| 276 | + |
| 277 | + }); |
| 278 | + |
245 | 279 | it('not redirect with set strict_transport_security exists and uri already has https scheme', function () { |
246 | 280 |
|
247 | 281 | $listener = new ForceHttps([ |
|
0 commit comments