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

Commit 2fea8eb

Browse files
committed
Merge branch '2.3' into 2.4
* 2.3: [Console]Improve formatter for double-width character Lower mbstring dep, remove it for Yaml and CssSelector components [Security] Add check for supported attributes in AclVoter [Form] Fixed TrimListenerTest as of PHP 5.5 Added more IDE links [DependencyInjection] Fix parameter description in ConfigurationExtensionInterface [Finder] fixed typehint of the Finder::addAdapter() method [TwigBridge][Transchoice] set %count% from the current context. [DependencyInjection] Fix travis unit tests Update PHPUnit before run [Validator] fixed wrong test [WebProfilerBundle] added test case for #10773 [WebProfilerBundle] fixed profiler homepage, fixed #10806 [WebProfilerBundle] Added test case for #10806 changed travis to run on the nightly builds of HHVM until everything gets stable Fixed issue #5427 Allow URLs that don't contain a path Conflicts: .travis.yml
2 parents cfe0fa9 + 89c67b5 commit 2fea8eb

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

Acl/Tests/Voter/AclVoterTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
2727
*/
2828
public function testSupportsAttribute($attribute, $supported)
2929
{
30-
list($voter,, $permissionMap,,) = $this->getVoter();
30+
list($voter,, $permissionMap,,) = $this->getVoter(true, false);
3131

3232
$permissionMap
3333
->expects($this->once())
@@ -39,6 +39,16 @@ public function testSupportsAttribute($attribute, $supported)
3939
$this->assertSame($supported, $voter->supportsAttribute($attribute));
4040
}
4141

42+
/**
43+
* @dataProvider getSupportsAttributeNonStringTests
44+
*/
45+
public function testSupportsAttributeNonString($attribute)
46+
{
47+
list($voter,,,,,) = $this->getVoter(true, false);
48+
49+
$this->assertFalse($voter->supportsAttribute($attribute));
50+
}
51+
4252
public function getSupportsAttributeTests()
4353
{
4454
return array(
@@ -47,6 +57,16 @@ public function getSupportsAttributeTests()
4757
);
4858
}
4959

60+
public function getSupportsAttributeNonStringTests()
61+
{
62+
return array(
63+
array(new \stdClass()),
64+
array(1),
65+
array(true),
66+
array(array()),
67+
);
68+
}
69+
5070
/**
5171
* @dataProvider getSupportsClassTests
5272
*/
@@ -387,13 +407,20 @@ protected function getToken()
387407
return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
388408
}
389409

390-
protected function getVoter($allowIfObjectIdentityUnavailable = true)
410+
protected function getVoter($allowIfObjectIdentityUnavailable = true, $alwaysContains = true)
391411
{
392412
$provider = $this->getMock('Symfony\Component\Security\Acl\Model\AclProviderInterface');
393413
$permissionMap = $this->getMock('Symfony\Component\Security\Acl\Permission\PermissionMapInterface');
394414
$oidStrategy = $this->getMock('Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface');
395415
$sidStrategy = $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface');
396416

417+
if ($alwaysContains) {
418+
$permissionMap
419+
->expects($this->any())
420+
->method('contains')
421+
->will($this->returnValue(true));
422+
}
423+
397424
return array(
398425
new AclVoter($provider, $oidStrategy, $sidStrategy, $permissionMap, null, $allowIfObjectIdentityUnavailable),
399426
$provider,

Acl/Voter/AclVoter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ public function __construct(AclProviderInterface $aclProvider, ObjectIdentityRet
4848

4949
public function supportsAttribute($attribute)
5050
{
51-
return $this->permissionMap->contains($attribute);
51+
return is_string($attribute) && $this->permissionMap->contains($attribute);
5252
}
5353

5454
public function vote(TokenInterface $token, $object, array $attributes)
5555
{
5656
foreach ($attributes as $attribute) {
57+
if (!$this->supportsAttribute($attribute)) {
58+
continue;
59+
}
60+
5761
if (null === $masks = $this->permissionMap->getMasks($attribute, $object)) {
5862
continue;
5963
}

0 commit comments

Comments
 (0)