diff options
author | Arturs Vonda <arturs@artursvonda.lv> | 2014-05-07 11:42:46 +0300 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2014-05-08 18:38:48 +0200 |
commit | 89c67b56212c3e050681ba0acc0c2fc169a35f9a (patch) | |
tree | 5d67056a1db2a11f36169faf8b5e41f48c30012f | |
parent | dc630adb7e869e60d54d8e7a7f883987eff21a12 (diff) | |
download | symfony-security-89c67b56212c3e050681ba0acc0c2fc169a35f9a.zip symfony-security-89c67b56212c3e050681ba0acc0c2fc169a35f9a.tar.gz symfony-security-89c67b56212c3e050681ba0acc0c2fc169a35f9a.tar.bz2 |
-rw-r--r-- | Acl/Voter/AclVoter.php | 6 | ||||
-rw-r--r-- | Tests/Acl/Voter/AclVoterTest.php | 31 |
2 files changed, 34 insertions, 3 deletions
diff --git a/Acl/Voter/AclVoter.php b/Acl/Voter/AclVoter.php index d401ef3..b21b1e6 100644 --- a/Acl/Voter/AclVoter.php +++ b/Acl/Voter/AclVoter.php @@ -48,12 +48,16 @@ class AclVoter implements VoterInterface public function supportsAttribute($attribute) { - return $this->permissionMap->contains($attribute); + return is_string($attribute) && $this->permissionMap->contains($attribute); } public function vote(TokenInterface $token, $object, array $attributes) { foreach ($attributes as $attribute) { + if (!$this->supportsAttribute($attribute)) { + continue; + } + if (null === $masks = $this->permissionMap->getMasks($attribute, $object)) { continue; } diff --git a/Tests/Acl/Voter/AclVoterTest.php b/Tests/Acl/Voter/AclVoterTest.php index 2474515..98e5ab9 100644 --- a/Tests/Acl/Voter/AclVoterTest.php +++ b/Tests/Acl/Voter/AclVoterTest.php @@ -27,7 +27,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase */ public function testSupportsAttribute($attribute, $supported) { - list($voter,, $permissionMap,,) = $this->getVoter(); + list($voter,, $permissionMap,,) = $this->getVoter(true, false); $permissionMap ->expects($this->once()) @@ -39,6 +39,16 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase $this->assertSame($supported, $voter->supportsAttribute($attribute)); } + /** + * @dataProvider getSupportsAttributeNonStringTests + */ + public function testSupportsAttributeNonString($attribute) + { + list($voter,,,,,) = $this->getVoter(true, false); + + $this->assertFalse($voter->supportsAttribute($attribute)); + } + public function getSupportsAttributeTests() { return array( @@ -47,6 +57,16 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase ); } + public function getSupportsAttributeNonStringTests() + { + return array( + array(new \stdClass()), + array(1), + array(true), + array(array()), + ); + } + /** * @dataProvider getSupportsClassTests */ @@ -387,13 +407,20 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); } - protected function getVoter($allowIfObjectIdentityUnavailable = true) + protected function getVoter($allowIfObjectIdentityUnavailable = true, $alwaysContains = true) { $provider = $this->getMock('Symfony\Component\Security\Acl\Model\AclProviderInterface'); $permissionMap = $this->getMock('Symfony\Component\Security\Acl\Permission\PermissionMapInterface'); $oidStrategy = $this->getMock('Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface'); $sidStrategy = $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface'); + if ($alwaysContains) { + $permissionMap + ->expects($this->any()) + ->method('contains') + ->will($this->returnValue(true)); + } + return array( new AclVoter($provider, $oidStrategy, $sidStrategy, $permissionMap, null, $allowIfObjectIdentityUnavailable), $provider, |