Skip to content

Commit d853c0d

Browse files
committed
minor #11820 [Security] Uniform AccessDecisionManager decide behaviour (mTorres)
This PR was merged into the 2.3 branch. Discussion ---------- [Security] Uniform AccessDecisionManager decide behaviour | Q | A | --------------------|--- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10170 | License | MIT | Doc PR | none This PR uniforms the way the 3 decision policies (affirmative, consensus, unanimous) are handled in the Security\Core\Authoritzation\AccessDecisionManager.php See #10170 Commits ------- 938ae4b [Security] Added more tests
2 parents 4fd0cf3 + 938ae4b commit d853c0d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/Symfony/Component/Security/Tests/Core/Authorization/AccessDecisionManagerTest.php

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

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

0 commit comments

Comments
 (0)