Skip to content

Commit

Permalink
Merge pull request #2 from danielvalchev/fix/redirect-master-requests…
Browse files Browse the repository at this point in the history
…-only

Add check to redirect master requests only
  • Loading branch information
lsimeonov authored Mar 27, 2019
2 parents dd71bb1 + b804736 commit 11b2252
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/EventListener/PasswordExpiryListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function __construct(PasswordExpiryServiceInterface $passwordExpiryServic

public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}

$request = $event->getRequest();
$route = $request->get('_route');

Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/EventListener/PasswordExpiryListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public function testOnKernelRequest()
->andReturn('route');

$responseEventMock = \Mockery::mock(GetResponseEvent::class);
$responseEventMock->shouldReceive('isMasterRequest')
->andReturn(true);
$responseEventMock->shouldReceive('getRequest')
->andReturn($requestMock);

Expand Down Expand Up @@ -101,6 +103,8 @@ public function testOnKernelRequestAsLockedRoute()
->andReturn('/route');

$responseEventMock = \Mockery::mock(GetResponseEvent::class);
$responseEventMock->shouldReceive('isMasterRequest')
->andReturn(true);
$responseEventMock->shouldReceive('getRequest')
->andReturn($requestMock);

Expand All @@ -123,6 +127,8 @@ public function testOnKernelRequestExcludedRoute()
->andReturn('/excluded-2');

$responseEventMock = \Mockery::mock(GetResponseEvent::class);
$responseEventMock->shouldReceive('isMasterRequest')
->andReturn(true);
$responseEventMock->shouldReceive('getRequest')
->andReturn($requestMock);

Expand All @@ -145,6 +151,8 @@ public function testOnKernelRequestPasswordNotExpired()
->andReturn('/route');

$responseEventMock = \Mockery::mock(GetResponseEvent::class);
$responseEventMock->shouldReceive('isMasterRequest')
->andReturn(true);
$responseEventMock->shouldReceive('getRequest')
->andReturn($requestMock);

Expand All @@ -156,4 +164,17 @@ public function testOnKernelRequestPasswordNotExpired()

$this->assertTrue(true);
}

public function testOnKernelRequestAsSubRequest()
{
$responseEventMock = \Mockery::mock(GetResponseEvent::class);
$responseEventMock->shouldReceive('isMasterRequest')
->andReturn(false);

$this->passwordExpiryServiceMock->shouldNotReceive('isPasswordExpired');

$this->passwordExpiryListenerMock->onKernelRequest($responseEventMock);

$this->assertTrue(true);
}
}

0 comments on commit 11b2252

Please sign in to comment.