Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60b83dc

Browse files
committed
bug #18949 [3.1][Security] Fix DebugAccessDecisionManager when object is not a scalar (romainneutron)
This PR was merged into the 3.1 branch. Discussion ---------- [3.1][Security] Fix DebugAccessDecisionManager when object is not a scalar | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT Commits ------- ff2d189 [Security] Fix DebugAccessDecisionManager when object is not a scalar
2 parents af6ada5 + ff2d189 commit 60b83dc

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/Symfony/Component/Security/Core/Authorization/DebugAccessDecisionManager.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ private function getStringRepresentation($object)
103103
}
104104

105105
if (!is_object($object)) {
106-
return sprintf('%s (%s)', gettype($object), $object);
106+
if (is_bool($object)) {
107+
return sprintf('%s (%s)', gettype($object), $object ? 'true' : 'false');
108+
}
109+
if (is_scalar($object)) {
110+
return sprintf('%s (%s)', gettype($object), $object);
111+
}
112+
113+
return gettype($object);
107114
}
108115

109116
$objectClass = class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($object) : get_class($object);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Core\Tests\Authorization;
13+
14+
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
15+
use Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager;
16+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
17+
18+
class DebugAccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @dataProvider provideObjectsAndLogs
22+
*/
23+
public function testDecideLog($expectedLog, $object)
24+
{
25+
$adm = new DebugAccessDecisionManager(new AccessDecisionManager());
26+
$adm->decide($this->getMock(TokenInterface::class), array('ATTRIBUTE_1'), $object);
27+
28+
$this->assertSame($expectedLog, $adm->getDecisionLog());
29+
}
30+
31+
public function provideObjectsAndLogs()
32+
{
33+
$object = new \stdClass();
34+
35+
yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'NULL', 'result' => false)), null);
36+
yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'boolean (true)', 'result' => false)), true);
37+
yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'string (jolie string)', 'result' => false)), 'jolie string');
38+
yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'integer (12345)', 'result' => false)), 12345);
39+
yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'resource', 'result' => false)), fopen(__FILE__, 'r'));
40+
yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'array', 'result' => false)), array());
41+
yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => sprintf('stdClass (object hash: %s)', spl_object_hash($object)), 'result' => false)), $object);
42+
}
43+
}

0 commit comments

Comments
 (0)