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

Commit 184e996

Browse files
Merge branch '4.2'
* 4.2: Revert "bug #30423 [Security] Rework firewall's access denied rule (dimabory)" [FrameworkBundle] minor: remove a typo from changelog [VarDumper] fix tests with ICU 64.1 [VarDumper][Ldap] relax some locally failing tests [Validator] #30192 Added the missing translations for the Tagalog ("tl") locale. Make MimeTypeExtensionGuesser case insensitive Fix get session when the request stack is empty [Routing] fix trailing slash redirection with non-greedy trailing vars [FrameworkBundle] decorate the ValidatorBuilder's translator with LegacyTranslatorProxy
2 parents 955fd31 + ef1759e commit 184e996

File tree

2 files changed

+10
-57
lines changed

2 files changed

+10
-57
lines changed

Http/Firewall/ExceptionListener.php

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

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

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

Http/Tests/Firewall/ExceptionListenerTest.php

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

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

137+
$listener = $this->createExceptionListener(null, $this->createTrustResolver(true), null, null, null, $accessDeniedHandler);
136138
$listener->onKernelException($event);
137139

138140
$this->assertEquals('error', $event->getResponse()->getContent());
@@ -146,48 +148,13 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \
146148
{
147149
$event = $this->createEvent($exception);
148150

149-
$listener = $this->createExceptionListener($this->createTokenStorage(), $this->createTrustResolver(false), null, $this->createEntryPoint());
150-
$listener->onKernelException($event);
151-
152-
$this->assertEquals('OK', $event->getResponse()->getContent());
153-
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
154-
}
155-
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')));
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()));
183153

184-
$listener = $this->createExceptionListener($this->createTokenStorage(), $this->createTrustResolver(true), $httpUtils, null, '/error');
154+
$listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false), null, $this->createEntryPoint());
185155
$listener->onKernelException($event);
186156

187-
$this->assertTrue($event->isAllowingCustomResponseCode());
188-
189-
$this->assertEquals('Unauthorized', $event->getResponse()->getContent());
190-
$this->assertEquals(401, $event->getResponse()->getStatusCode());
157+
$this->assertEquals('OK', $event->getResponse()->getContent());
191158
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
192159
}
193160

@@ -202,22 +169,6 @@ public function getAccessDeniedExceptionProvider()
202169
];
203170
}
204171

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-
221172
private function createEntryPoint(Response $response = null)
222173
{
223174
$entryPoint = $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock();

0 commit comments

Comments
 (0)