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

Commit 8f099fc

Browse files
committed
Merge branch '2.4' into 2.5
* 2.4: (39 commits) [Form] Fix PHPDoc for builder setData methods The underlying data variable is typed as mixed whereas the methods paramers where typed as array. fixed CS [Intl] Improved bundle reader implementations [Console] guarded against invalid aliases switch before_script to before_install and script to install fixed typo [HttpFoundation] Request - URI - comment improvements [Validator] The ratio of the ImageValidator is rounded to two decimals now [Security] Added more tests remove `service` parameter type from XSD [Intl] Added exception handler to command line scripts [Intl] Fixed a few bugs in TextBundleWriter [Intl] Updated icu.ini up to ICU 53 [Intl] Removed non-working $fallback argument from ArrayAccessibleResourceBundle Use separated function to resolve command and related arguments [SwiftmailerBridge] Bump allowed versions of swiftmailer [FrameworkBundle] Remove invalid markup [Intl] Added "internal" tag to all classes under Symfony\Component\Intl\ResourceBundle Remove routes for removed WebProfiler actions [Security] Fix usage of unexistent method in DoctrineAclCache. ... Conflicts: .travis.yml src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/Process/PhpExecutableFinder.php
2 parents 1b9e95c + 9aefee3 commit 8f099fc

File tree

4 files changed

+96
-5
lines changed

4 files changed

+96
-5
lines changed

Acl/Domain/DoctrineAclCache.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Acl\Domain;
1313

1414
use Doctrine\Common\Cache\Cache;
15+
use Doctrine\Common\Cache\CacheProvider;
1516
use Symfony\Component\Security\Acl\Model\AclCacheInterface;
1617
use Symfony\Component\Security\Acl\Model\AclInterface;
1718
use Symfony\Component\Security\Acl\Model\ObjectIdentityInterface;
@@ -55,7 +56,9 @@ public function __construct(Cache $cache, PermissionGrantingStrategyInterface $p
5556
*/
5657
public function clearCache()
5758
{
58-
$this->cache->deleteByPrefix($this->prefix);
59+
if ($this->cache instanceof CacheProvider) {
60+
$this->cache->deleteAll();
61+
}
5962
}
6063

6164
/**

Core/Tests/Authorization/AccessDecisionManagerTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,48 @@ public function testStrategies($strategy, $voters, $allowIfAllAbstainDecisions,
7373
$this->assertSame($expected, $manager->decide($token, array('ROLE_FOO')));
7474
}
7575

76+
/**
77+
* @dataProvider getStrategiesWith2RolesTests
78+
*/
79+
public function testStrategiesWith2Roles($token, $strategy, $voter, $expected)
80+
{
81+
$manager = new AccessDecisionManager(array($voter), $strategy);
82+
83+
$this->assertSame($expected, $manager->decide($token, array('ROLE_FOO', 'ROLE_BAR')));
84+
}
85+
86+
public function getStrategiesWith2RolesTests()
87+
{
88+
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
89+
90+
return array(
91+
array($token, 'affirmative', $this->getVoter(VoterInterface::ACCESS_DENIED), false),
92+
array($token, 'affirmative', $this->getVoter(VoterInterface::ACCESS_GRANTED), true),
93+
94+
array($token, 'consensus', $this->getVoter(VoterInterface::ACCESS_DENIED), false),
95+
array($token, 'consensus', $this->getVoter(VoterInterface::ACCESS_GRANTED), true),
96+
97+
array($token, 'unanimous', $this->getVoterFor2Roles($token, VoterInterface::ACCESS_DENIED, VoterInterface::ACCESS_DENIED), false),
98+
array($token, 'unanimous', $this->getVoterFor2Roles($token, VoterInterface::ACCESS_DENIED, VoterInterface::ACCESS_GRANTED), false),
99+
array($token, 'unanimous', $this->getVoterFor2Roles($token, VoterInterface::ACCESS_GRANTED, VoterInterface::ACCESS_DENIED), false),
100+
array($token, 'unanimous', $this->getVoterFor2Roles($token, VoterInterface::ACCESS_GRANTED, VoterInterface::ACCESS_GRANTED), true),
101+
);
102+
}
103+
104+
protected function getVoterFor2Roles($token, $vote1, $vote2)
105+
{
106+
$voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
107+
$voter->expects($this->exactly(2))
108+
->method('vote')
109+
->will($this->returnValueMap(array(
110+
array($token, null, array("ROLE_FOO"),$vote1),
111+
array($token, null, array("ROLE_BAR"),$vote2),
112+
)))
113+
;
114+
115+
return $voter;
116+
}
117+
76118
public function getStrategyTests()
77119
{
78120
return array(

Core/Tests/Util/StringUtilsTest.php

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,49 @@
1313

1414
use Symfony\Component\Security\Core\Util\StringUtils;
1515

16+
/**
17+
* Data from PHP.net's hash_equals tests
18+
*/
1619
class StringUtilsTest extends \PHPUnit_Framework_TestCase
1720
{
18-
public function testEquals()
21+
public function dataProviderTrue()
22+
{
23+
return array(
24+
array('same', 'same'),
25+
array('', ''),
26+
array(123, 123),
27+
array(null, ''),
28+
array(null, null),
29+
);
30+
}
31+
32+
public function dataProviderFalse()
33+
{
34+
return array(
35+
array('not1same', 'not2same'),
36+
array('short', 'longer'),
37+
array('longer', 'short'),
38+
array('', 'notempty'),
39+
array('notempty', ''),
40+
array(123, 'NaN'),
41+
array('NaN', 123),
42+
array(null, 123),
43+
);
44+
}
45+
46+
/**
47+
* @dataProvider dataProviderTrue
48+
*/
49+
public function testEqualsTrue($known, $user)
50+
{
51+
$this->assertTrue(StringUtils::equals($known, $user));
52+
}
53+
54+
/**
55+
* @dataProvider dataProviderFalse
56+
*/
57+
public function testEqualsFalse($known, $user)
1958
{
20-
$this->assertTrue(StringUtils::equals('password', 'password'));
21-
$this->assertFalse(StringUtils::equals('password', 'foo'));
59+
$this->assertFalse(StringUtils::equals($known, $user));
2260
}
2361
}

Core/Util/StringUtils.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ private function __construct() {}
2727
* Compares two strings.
2828
*
2929
* This method implements a constant-time algorithm to compare strings.
30+
* Regardless of the used implementation, it will leak length information.
3031
*
3132
* @param string $knownString The string of known length to compare against
3233
* @param string $userInput The string that the user can control
@@ -35,6 +36,13 @@ private function __construct() {}
3536
*/
3637
public static function equals($knownString, $userInput)
3738
{
39+
$knownString = (string) $knownString;
40+
$userInput = (string) $userInput;
41+
42+
if (function_exists('hash_equals')) {
43+
return hash_equals($knownString, $userInput);
44+
}
45+
3846
$knownLen = strlen($knownString);
3947
$userLen = strlen($userInput);
4048

@@ -45,7 +53,7 @@ public static function equals($knownString, $userInput)
4553
$result = $knownLen - $userLen;
4654

4755
// Note that we ALWAYS iterate over the user-supplied length
48-
// This is to prevent leaking length information
56+
// This is to mitigate leaking length information
4957
for ($i = 0; $i < $userLen; $i++) {
5058
$result |= (ord($knownString[$i]) ^ ord($userInput[$i]));
5159
}

0 commit comments

Comments
 (0)