diff options
author | Romain Neutron <imprec@gmail.com> | 2016-06-02 13:03:22 +0200 |
---|---|---|
committer | Romain Neutron <imprec@gmail.com> | 2016-06-02 16:45:44 +0200 |
commit | 55444da85ab15652323bdd3eeb23be9118aba45a (patch) | |
tree | 4ba377ce4c0dc402684ccff32e9dbe8b67d23ee3 | |
parent | 3b89f41a6a9e015da1bd008be13c985349f86e7b (diff) | |
download | symfony-security-55444da85ab15652323bdd3eeb23be9118aba45a.zip symfony-security-55444da85ab15652323bdd3eeb23be9118aba45a.tar.gz symfony-security-55444da85ab15652323bdd3eeb23be9118aba45a.tar.bz2 |
[Security] Fix DebugAccessDecisionManager when object is not a scalar
-rw-r--r-- | Core/Authorization/DebugAccessDecisionManager.php | 9 | ||||
-rw-r--r-- | Core/Tests/Authorization/DebugAccessDecisionManagerTest.php | 43 |
2 files changed, 51 insertions, 1 deletions
diff --git a/Core/Authorization/DebugAccessDecisionManager.php b/Core/Authorization/DebugAccessDecisionManager.php index 7c0cfc9..540d998 100644 --- a/Core/Authorization/DebugAccessDecisionManager.php +++ b/Core/Authorization/DebugAccessDecisionManager.php @@ -103,7 +103,14 @@ class DebugAccessDecisionManager implements AccessDecisionManagerInterface } if (!is_object($object)) { - return sprintf('%s (%s)', gettype($object), $object); + if (is_bool($object)) { + return sprintf('%s (%s)', gettype($object), $object ? 'true' : 'false'); + } + if (is_scalar($object)) { + return sprintf('%s (%s)', gettype($object), $object); + } + + return gettype($object); } $objectClass = class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($object) : get_class($object); diff --git a/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php b/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php new file mode 100644 index 0000000..f90f776 --- /dev/null +++ b/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php @@ -0,0 +1,43 @@ +<?php + +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Core\Tests\Authorization; + +use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; +use Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; + +class DebugAccessDecisionManagerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider provideObjectsAndLogs + */ + public function testDecideLog($expectedLog, $object) + { + $adm = new DebugAccessDecisionManager(new AccessDecisionManager()); + $adm->decide($this->getMock(TokenInterface::class), array('ATTRIBUTE_1'), $object); + + $this->assertSame($expectedLog, $adm->getDecisionLog()); + } + + public function provideObjectsAndLogs() + { + $object = new \stdClass(); + + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'NULL', 'result' => false)), null); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'boolean (true)', 'result' => false)), true); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'string (jolie string)', 'result' => false)), 'jolie string'); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'integer (12345)', 'result' => false)), 12345); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'resource', 'result' => false)), fopen(__FILE__, 'r')); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'array', 'result' => false)), array()); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => sprintf('stdClass (object hash: %s)', spl_object_hash($object)), 'result' => false)), $object); + } +} |