From b804736552d25aa2545bd3b12bca4341c698c9e1 Mon Sep 17 00:00:00 2001 From: Daniel Valchev Date: Mon, 25 Mar 2019 14:17:47 +0200 Subject: [PATCH] Add check to redirect master requests only --- src/EventListener/PasswordExpiryListener.php | 4 ++++ .../PasswordExpiryListenerTest.php | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/EventListener/PasswordExpiryListener.php b/src/EventListener/PasswordExpiryListener.php index 7285cf0..d3a6e63 100644 --- a/src/EventListener/PasswordExpiryListener.php +++ b/src/EventListener/PasswordExpiryListener.php @@ -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'); diff --git a/tests/Unit/EventListener/PasswordExpiryListenerTest.php b/tests/Unit/EventListener/PasswordExpiryListenerTest.php index 8867767..e9bea2e 100644 --- a/tests/Unit/EventListener/PasswordExpiryListenerTest.php +++ b/tests/Unit/EventListener/PasswordExpiryListenerTest.php @@ -65,6 +65,8 @@ public function testOnKernelRequest() ->andReturn('route'); $responseEventMock = \Mockery::mock(GetResponseEvent::class); + $responseEventMock->shouldReceive('isMasterRequest') + ->andReturn(true); $responseEventMock->shouldReceive('getRequest') ->andReturn($requestMock); @@ -101,6 +103,8 @@ public function testOnKernelRequestAsLockedRoute() ->andReturn('/route'); $responseEventMock = \Mockery::mock(GetResponseEvent::class); + $responseEventMock->shouldReceive('isMasterRequest') + ->andReturn(true); $responseEventMock->shouldReceive('getRequest') ->andReturn($requestMock); @@ -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); @@ -145,6 +151,8 @@ public function testOnKernelRequestPasswordNotExpired() ->andReturn('/route'); $responseEventMock = \Mockery::mock(GetResponseEvent::class); + $responseEventMock->shouldReceive('isMasterRequest') + ->andReturn(true); $responseEventMock->shouldReceive('getRequest') ->andReturn($requestMock); @@ -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); + } } \ No newline at end of file