Skip to content

Commit

Permalink
use exit(0); to actually fix the overlap redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 4, 2019
1 parent d0f2529 commit 98741f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 24 additions & 5 deletions spec/Listener/ForceHttpsSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use ForceHttpsModule\Listener\ForceHttps;
use Kahlan\Plugin\Double;
use Kahlan\Plugin\Quit;
use Kahlan\QuitException;
use Zend\Console\Console;
use Zend\EventManager\EventManagerInterface;
use Zend\Http\PhpEnvironment\Request;
Expand Down Expand Up @@ -80,6 +82,8 @@
$this->request = Double::instance(['extends' => Request::class]);
$this->uri = Double::instance(['extends' => Uri::class]);
$this->routeMatch = Double::instance(['extends' => RouteMatch::class, 'methods' => '__construct']);

Quit::disable();
});

context('on current scheme is https', function () {
Expand Down Expand Up @@ -159,7 +163,10 @@
->with('SendResponseListener')
->andReturn($this->sendResponseListener);

$listener->forceHttpsScheme($this->mvcEvent);
$closure = function () use ($listener) {
$listener->forceHttpsScheme($this->mvcEvent);
};
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));

expect($this->mvcEvent)->toReceive('getResponse');

Expand Down Expand Up @@ -197,7 +204,10 @@
->with('SendResponseListener')
->andReturn($this->sendResponseListener);

$listener->forceHttpsScheme($this->mvcEvent);
$closure = function () use ($listener) {
$listener->forceHttpsScheme($this->mvcEvent);
};
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));

expect($this->mvcEvent)->toReceive('getResponse');

Expand Down Expand Up @@ -233,7 +243,10 @@
->with('SendResponseListener')
->andReturn($this->sendResponseListener);

$listener->forceHttpsScheme($this->mvcEvent);
$closure = function () use ($listener) {
$listener->forceHttpsScheme($this->mvcEvent);
};
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));

expect($this->mvcEvent)->toReceive('getResponse');
expect($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
Expand Down Expand Up @@ -271,7 +284,10 @@
->with('SendResponseListener')
->andReturn($this->sendResponseListener);

$listener->forceHttpsScheme($this->mvcEvent);
$closure = function () use ($listener) {
$listener->forceHttpsScheme($this->mvcEvent);
};
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));

expect($this->mvcEvent)->toReceive('getResponse');
expect($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://www.example.com/about');
Expand Down Expand Up @@ -314,7 +330,10 @@
allow($this->response)->toReceive('setStatusCode')->with(308)->andReturn($this->response);
allow($this->response)->toReceive('send');

$listener->forceHttpsScheme($this->mvcEvent);
$closure = function () use ($listener) {
$listener->forceHttpsScheme($this->mvcEvent);
};
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));

expect($this->mvcEvent)->toReceive('getResponse');

Expand Down
2 changes: 2 additions & 0 deletions src/Listener/ForceHttps.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,7 @@ public function forceHttpsScheme(MvcEvent $e) : void
$response->getHeaders()
->addHeaderLine('Location', $httpsRequestUri);
$response->send();

exit(0);
}
}

0 comments on commit 98741f9

Please sign in to comment.