summaryrefslogtreecommitdiffstats
path: root/Core
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2016-12-14 09:13:10 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2016-12-14 09:13:10 +0100
commitd97a78775c5df380551d5ba188216dd38d6628ab (patch)
tree2707c3fe66c98ce71f6b38cbe0249bffbdf6acf2 /Core
parentc5b0c58603619794b2d2d5461ec03b5360118264 (diff)
parente396644d91c69dd7844f83735832e896e6ed4bf3 (diff)
downloadsymfony-security-d97a78775c5df380551d5ba188216dd38d6628ab.zip
symfony-security-d97a78775c5df380551d5ba188216dd38d6628ab.tar.gz
symfony-security-d97a78775c5df380551d5ba188216dd38d6628ab.tar.bz2
Merge branch '2.7' into 2.8
* 2.7: [Validator] add Indonesian translation fixed CS [config] Fix issue when key removed and left value only [Security] AbstractVoter method supportsAttribute gives false positive if attribute is zero (0)
Diffstat (limited to 'Core')
-rw-r--r--Core/Authorization/Voter/AbstractVoter.php2
-rw-r--r--Core/Tests/Authorization/Voter/AbstractVoterTest.php71
2 files changed, 72 insertions, 1 deletions
diff --git a/Core/Authorization/Voter/AbstractVoter.php b/Core/Authorization/Voter/AbstractVoter.php
index 5dcf787..aaa6fda 100644
--- a/Core/Authorization/Voter/AbstractVoter.php
+++ b/Core/Authorization/Voter/AbstractVoter.php
@@ -30,7 +30,7 @@ abstract class AbstractVoter implements VoterInterface
*/
public function supportsAttribute($attribute)
{
- return in_array($attribute, $this->getSupportedAttributes());
+ return in_array($attribute, $this->getSupportedAttributes(), true);
}
/**
diff --git a/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/Core/Tests/Authorization/Voter/AbstractVoterTest.php
index b537c1b..7c60007 100644
--- a/Core/Tests/Authorization/Voter/AbstractVoterTest.php
+++ b/Core/Tests/Authorization/Voter/AbstractVoterTest.php
@@ -18,6 +18,9 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
*/
class AbstractVoterTest extends \PHPUnit_Framework_TestCase
{
+ /**
+ * @var TokenInterface
+ */
protected $token;
protected function setUp()
@@ -25,6 +28,9 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase
$this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
}
+ /**
+ * @return array
+ */
public function getTests()
{
return array(
@@ -55,4 +61,69 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
}
+
+ /**
+ * @return array
+ */
+ public function getSupportsAttributeData()
+ {
+ return array(
+ 'positive_string_edit' => array(
+ 'expected' => true,
+ 'attribute' => 'EDIT',
+ 'message' => 'expected TRUE given as attribute EDIT is supported',
+ ),
+ 'positive_string_create' => array(
+ 'expected' => true,
+ 'attribute' => 'CREATE',
+ 'message' => 'expected TRUE as given attribute CREATE is supported',
+ ),
+
+ 'negative_string_read' => array(
+ 'expected' => false,
+ 'attribute' => 'READ',
+ 'message' => 'expected FALSE as given attribute READ is not supported',
+ ),
+ 'negative_string_random' => array(
+ 'expected' => false,
+ 'attribute' => 'random',
+ 'message' => 'expected FALSE as given attribute "random" is not supported',
+ ),
+ 'negative_string_0' => array(
+ 'expected' => false,
+ 'attribute' => '0',
+ 'message' => 'expected FALSE as given attribute "0" is not supported',
+ ),
+ // this set of data gives false positive if in_array is not used with strict flag set to 'true'
+ 'negative_int_0' => array(
+ 'expected' => false,
+ 'attribute' => 0,
+ 'message' => 'expected FALSE as given attribute 0 is not string',
+ ),
+ 'negative_int_1' => array(
+ 'expected' => false,
+ 'attribute' => 1,
+ 'message' => 'expected FALSE as given attribute 1 is not string',
+ ),
+ 'negative_int_7' => array(
+ 'expected' => false,
+ 'attribute' => 7,
+ 'message' => 'expected FALSE as attribute 7 is not string',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider getSupportsAttributeData
+ *
+ * @param bool $expected
+ * @param string $attribute
+ * @param string $message
+ */
+ public function testSupportsAttribute($expected, $attribute, $message)
+ {
+ $voter = new AbstractVoterTest_Voter();
+
+ $this->assertEquals($expected, $voter->supportsAttribute($attribute), $message);
+ }
}