Skip to content

Commit 034f476

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: [HttpFoundation] Improve phpdoc [Logging] Add support for firefox in ChromePhpHandler [Security] Fixed SwitchUserListener when exiting an impersonication with AnonymousToken [Form] fix "prototype" not required when parent form is not required
2 parents 5f5a717 + 5b6da77 commit 034f476

File tree

6 files changed

+96
-4
lines changed

6 files changed

+96
-4
lines changed

src/Symfony/Bridge/Monolog/Handler/ChromePhpHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function onKernelResponse(FilterResponseEvent $event)
4141
return;
4242
}
4343

44-
if (!preg_match('{\bChrome/\d+[\.\d+]*\b}', $event->getRequest()->headers->get('User-Agent'))) {
44+
if (!preg_match('{\b(?:Chrome/\d+(?:\.\d+)*|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}', $event->getRequest()->headers->get('User-Agent'))) {
4545
$this->sendHeaders = false;
4646
$this->headers = array();
4747

src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public function buildView(FormView $view, FormInterface $form, array $options)
5656
));
5757

5858
if ($form->getConfig()->hasAttribute('prototype')) {
59-
$view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view);
59+
$prototype = $form->getConfig()->getAttribute('prototype');
60+
$view->vars['prototype'] = $prototype->setParent($form)->createView($view);
6061
}
6162
}
6263

src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,46 @@ public function testPrototypeSetNotRequired()
300300
$this->assertFalse($form->createView()->vars['required'], 'collection is not required');
301301
$this->assertFalse($form->createView()->vars['prototype']->vars['required'], '"prototype" should not be required');
302302
}
303+
304+
public function testPrototypeSetNotRequiredIfParentNotRequired()
305+
{
306+
$child = $this->factory->create('collection', array(), array(
307+
'type' => 'file',
308+
'allow_add' => true,
309+
'prototype' => true,
310+
'prototype_name' => '__test__',
311+
));
312+
313+
$parent = $this->factory->create('form', array(), array(
314+
'required' => false,
315+
));
316+
317+
$child->setParent($parent);
318+
$this->assertFalse($parent->createView()->vars['required'], 'Parent is not required');
319+
$this->assertFalse($child->createView()->vars['required'], 'Child is not required');
320+
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
321+
}
322+
323+
public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent()
324+
{
325+
$child = $this->factory->create('collection', array(), array(
326+
'type' => 'file',
327+
'allow_add' => true,
328+
'prototype' => true,
329+
'prototype_name' => '__test__',
330+
'options' => array(
331+
'required' => true,
332+
),
333+
));
334+
335+
$parent = $this->factory->create('form', array(), array(
336+
'required' => false,
337+
));
338+
339+
$child->setParent($parent);
340+
341+
$this->assertFalse($parent->createView()->vars['required'], 'Parent is not required');
342+
$this->assertFalse($child->createView()->vars['required'], 'Child is not required');
343+
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
344+
}
303345
}

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ public static function getHttpMethodParameterOverride()
715715
* public property instead (query, attributes, request).
716716
*
717717
* @param string $key the key
718-
* @param mixed $default the default value
718+
* @param mixed $default the default value if the parameter key does not exist
719719
* @param bool $deep is parameter deep in multidimensional array
720720
*
721721
* @return mixed

src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Firewall;
1313

1414
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
15+
use Symfony\Component\Security\Core\User\UserInterface;
1516
use Symfony\Component\Security\Core\User\UserProviderInterface;
1617
use Symfony\Component\Security\Core\User\UserCheckerInterface;
1718
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
@@ -161,7 +162,7 @@ private function attemptExitUser(Request $request)
161162
throw new AuthenticationCredentialsNotFoundException('Could not find original Token object.');
162163
}
163164

164-
if (null !== $this->dispatcher) {
165+
if (null !== $this->dispatcher && $original->getUser() instanceof UserInterface) {
165166
$user = $this->provider->refreshUser($original->getUser());
166167
$switchEvent = new SwitchUserEvent($request, $user);
167168
$this->dispatcher->dispatch(SecurityEvents::SWITCH_USER, $switchEvent);

src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,54 @@ public function testExitUserDispatchesEventWithRefreshedUser()
158158
$listener->handle($this->event);
159159
}
160160

161+
public function testExitUserDoesNotDispatchEventWithStringUser()
162+
{
163+
$originalUser = 'anon.';
164+
$refreshedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
165+
$this
166+
->userProvider
167+
->expects($this->never())
168+
->method('refreshUser');
169+
$originalToken = $this->getToken();
170+
$originalToken
171+
->expects($this->any())
172+
->method('getUser')
173+
->willReturn($originalUser);
174+
$role = $this
175+
->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole')
176+
->disableOriginalConstructor()
177+
->getMock();
178+
$role
179+
->expects($this->any())
180+
->method('getSource')
181+
->willReturn($originalToken);
182+
$this
183+
->tokenStorage
184+
->expects($this->any())
185+
->method('getToken')
186+
->willReturn($this->getToken(array($role)));
187+
$this
188+
->request
189+
->expects($this->any())
190+
->method('all')
191+
->with('_switch_user')
192+
->willReturn('_exit');
193+
$this
194+
->request
195+
->expects($this->any())
196+
->method('getUri')
197+
->willReturn('/');
198+
199+
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
200+
$dispatcher
201+
->expects($this->never())
202+
->method('dispatch')
203+
;
204+
205+
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', $dispatcher);
206+
$listener->handle($this->event);
207+
}
208+
161209
/**
162210
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
163211
*/

0 commit comments

Comments
 (0)