Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 38aba37

Browse files
committed
Merge branch '4.2'
* 4.2: fixed bad merge Show more accurate message in profiler when missing stopwatch CS Fixes: Not double split with one array argument [Serializer] Add default object class resolver Remove redundant animation prefixes Remove redundant `box-sizing` prefixes [VarExporter] support PHP7.4 __serialize & __unserialize Rework firewall access denied rule MetadataAwareNameConverter: Do not assume that property names are strings [VarExporter] fix exporting classes with private constructors fixed CS Fix missing $extraDirs when open_basedir returns
2 parents 8fd348c + 38dda98 commit 38aba37

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

Http/Firewall/ExceptionListener.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ private function handleAccessDeniedException(GetResponseForExceptionEvent $event
133133
} catch (\Exception $e) {
134134
$event->setException($e);
135135
}
136-
137-
return;
138136
}
139137

140138
if (null !== $this->logger) {
@@ -152,7 +150,7 @@ private function handleAccessDeniedException(GetResponseForExceptionEvent $event
152150
$subRequest = $this->httpUtils->createRequest($event->getRequest(), $this->errorPage);
153151
$subRequest->attributes->set(Security::ACCESS_DENIED_ERROR, $exception);
154152

155-
$event->setResponse($event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true));
153+
$event->setResponse($event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST));
156154
$event->allowCustomResponseCode();
157155
}
158156
} catch (\Exception $e) {

Http/Tests/Firewall/ExceptionListenerTest.php

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,8 @@ public function testAccessDeniedExceptionFullFledgedAndWithAccessDeniedHandlerAn
131131
{
132132
$event = $this->createEvent($exception);
133133

134-
$accessDeniedHandler = $this->getMockBuilder('Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface')->getMock();
135-
$accessDeniedHandler->expects($this->once())->method('handle')->will($this->returnValue(new Response('error')));
134+
$listener = $this->createExceptionListener(null, $this->createTrustResolver(true), null, null, null, $this->createCustomAccessDeniedHandler(new Response('error')));
136135

137-
$listener = $this->createExceptionListener(null, $this->createTrustResolver(true), null, null, null, $accessDeniedHandler);
138136
$listener->onKernelException($event);
139137

140138
$this->assertEquals('error', $event->getResponse()->getContent());
@@ -148,16 +146,51 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \
148146
{
149147
$event = $this->createEvent($exception);
150148

151-
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
152-
$tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
153-
154-
$listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false), null, $this->createEntryPoint());
149+
$listener = $this->createExceptionListener($this->createTokenStorage(), $this->createTrustResolver(false), null, $this->createEntryPoint());
155150
$listener->onKernelException($event);
156151

157152
$this->assertEquals('OK', $event->getResponse()->getContent());
158153
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
159154
}
160155

156+
/**
157+
* @dataProvider getAccessDeniedExceptionProvider
158+
*/
159+
public function testAccessDeniedExceptionNotFullFledgedAndWithAccessDeniedHandlerAndWithoutErrorPage(\Exception $exception, \Exception $eventException = null)
160+
{
161+
$event = $this->createEvent($exception);
162+
163+
$listener = $this->createExceptionListener($this->createTokenStorage(), $this->createTrustResolver(false), null, $this->createEntryPoint(), null, $this->createCustomAccessDeniedHandler(new Response('denied', 403)));
164+
$listener->onKernelException($event);
165+
166+
$this->assertEquals('denied', $event->getResponse()->getContent());
167+
$this->assertEquals(403, $event->getResponse()->getStatusCode());
168+
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
169+
}
170+
171+
/**
172+
* @dataProvider getAccessDeniedExceptionProvider
173+
*/
174+
public function testAccessDeniedExceptionNotFullFledgedAndWithoutAccessDeniedHandlerAndWithErrorPage(\Exception $exception, \Exception $eventException = null)
175+
{
176+
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
177+
$kernel->expects($this->once())->method('handle')->will($this->returnValue(new Response('Unauthorized', 401)));
178+
179+
$event = $this->createEvent($exception, $kernel);
180+
181+
$httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock();
182+
$httpUtils->expects($this->once())->method('createRequest')->will($this->returnValue(Request::create('/error')));
183+
184+
$listener = $this->createExceptionListener($this->createTokenStorage(), $this->createTrustResolver(true), $httpUtils, null, '/error');
185+
$listener->onKernelException($event);
186+
187+
$this->assertTrue($event->isAllowingCustomResponseCode());
188+
189+
$this->assertEquals('Unauthorized', $event->getResponse()->getContent());
190+
$this->assertEquals(401, $event->getResponse()->getStatusCode());
191+
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
192+
}
193+
161194
public function getAccessDeniedExceptionProvider()
162195
{
163196
return [
@@ -169,6 +202,22 @@ public function getAccessDeniedExceptionProvider()
169202
];
170203
}
171204

205+
private function createTokenStorage()
206+
{
207+
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
208+
$tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
209+
210+
return $tokenStorage;
211+
}
212+
213+
private function createCustomAccessDeniedHandler(Response $response)
214+
{
215+
$accessDeniedHandler = $this->getMockBuilder('Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface')->getMock();
216+
$accessDeniedHandler->expects($this->once())->method('handle')->will($this->returnValue($response));
217+
218+
return $accessDeniedHandler;
219+
}
220+
172221
private function createEntryPoint(Response $response = null)
173222
{
174223
$entryPoint = $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock();

0 commit comments

Comments
 (0)