summaryrefslogtreecommitdiffstats
path: root/Tests/Core/Authorization
diff options
context:
space:
mode:
authorBernhard Schussek <bschussek@gmail.com>2013-09-16 10:03:00 +0200
committerFabien Potencier <fabien.potencier@gmail.com>2013-09-18 09:16:41 +0200
commit5a6aaab2c35213f5ca7e57f061fbb2675e2ece35 (patch)
tree461816fef8160401dc113d3fef190fb437d01cc7 /Tests/Core/Authorization
parent513a354be10f0ed87933adcb788e48660f8e6ed4 (diff)
downloadsymfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.zip
symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.tar.gz
symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.tar.bz2
[Security] Split the component into 3 sub-components Core, ACL, HTTP
Diffstat (limited to 'Tests/Core/Authorization')
-rw-r--r--Tests/Core/Authorization/AccessDecisionManagerTest.php159
-rw-r--r--Tests/Core/Authorization/Voter/AuthenticatedVoterTest.php78
-rw-r--r--Tests/Core/Authorization/Voter/RoleHierarchyVoterTest.php36
-rw-r--r--Tests/Core/Authorization/Voter/RoleVoterTest.php62
4 files changed, 0 insertions, 335 deletions
diff --git a/Tests/Core/Authorization/AccessDecisionManagerTest.php b/Tests/Core/Authorization/AccessDecisionManagerTest.php
deleted file mode 100644
index ead97d2..0000000
--- a/Tests/Core/Authorization/AccessDecisionManagerTest.php
+++ /dev/null
@@ -1,159 +0,0 @@
-<?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\Tests\Core\Authorization;
-
-use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
-use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
-
-class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
-{
- public function testSupportsClass()
- {
- $manager = new AccessDecisionManager(array(
- $this->getVoterSupportsClass(true),
- $this->getVoterSupportsClass(false),
- ));
- $this->assertTrue($manager->supportsClass('FooClass'));
-
- $manager = new AccessDecisionManager(array(
- $this->getVoterSupportsClass(false),
- $this->getVoterSupportsClass(false),
- ));
- $this->assertFalse($manager->supportsClass('FooClass'));
- }
-
- public function testSupportsAttribute()
- {
- $manager = new AccessDecisionManager(array(
- $this->getVoterSupportsAttribute(true),
- $this->getVoterSupportsAttribute(false),
- ));
- $this->assertTrue($manager->supportsAttribute('foo'));
-
- $manager = new AccessDecisionManager(array(
- $this->getVoterSupportsAttribute(false),
- $this->getVoterSupportsAttribute(false),
- ));
- $this->assertFalse($manager->supportsAttribute('foo'));
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testSetVotersEmpty()
- {
- $manager = new AccessDecisionManager(array());
- }
-
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testSetUnsupportedStrategy()
- {
- new AccessDecisionManager(array($this->getVoter(VoterInterface::ACCESS_GRANTED)), 'fooBar');
- }
-
- /**
- * @dataProvider getStrategyTests
- */
- public function testStrategies($strategy, $voters, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions, $expected)
- {
- $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
- $manager = new AccessDecisionManager($voters, $strategy, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions);
-
- $this->assertSame($expected, $manager->decide($token, array('ROLE_FOO')));
- }
-
- public function getStrategyTests()
- {
- return array(
- // affirmative
- array('affirmative', $this->getVoters(1, 0, 0), false, true, true),
- array('affirmative', $this->getVoters(1, 2, 0), false, true, true),
- array('affirmative', $this->getVoters(0, 1, 0), false, true, false),
- array('affirmative', $this->getVoters(0, 0, 1), false, true, false),
- array('affirmative', $this->getVoters(0, 0, 1), true, true, true),
-
- // consensus
- array('consensus', $this->getVoters(1, 0, 0), false, true, true),
- array('consensus', $this->getVoters(1, 2, 0), false, true, false),
- array('consensus', $this->getVoters(2, 1, 0), false, true, true),
-
- array('consensus', $this->getVoters(0, 0, 1), false, true, false),
-
- array('consensus', $this->getVoters(0, 0, 1), true, true, true),
-
- array('consensus', $this->getVoters(2, 2, 0), false, true, true),
- array('consensus', $this->getVoters(2, 2, 1), false, true, true),
-
- array('consensus', $this->getVoters(2, 2, 0), false, false, false),
- array('consensus', $this->getVoters(2, 2, 1), false, false, false),
-
- // unanimous
- array('unanimous', $this->getVoters(1, 0, 0), false, true, true),
- array('unanimous', $this->getVoters(1, 0, 1), false, true, true),
- array('unanimous', $this->getVoters(1, 1, 0), false, true, false),
-
- array('unanimous', $this->getVoters(0, 0, 2), false, true, false),
- array('unanimous', $this->getVoters(0, 0, 2), true, true, true),
- );
- }
-
- protected function getVoters($grants, $denies, $abstains)
- {
- $voters = array();
- for ($i = 0; $i < $grants; $i++) {
- $voters[] = $this->getVoter(VoterInterface::ACCESS_GRANTED);
- }
- for ($i = 0; $i < $denies; $i++) {
- $voters[] = $this->getVoter(VoterInterface::ACCESS_DENIED);
- }
- for ($i = 0; $i < $abstains; $i++) {
- $voters[] = $this->getVoter(VoterInterface::ACCESS_ABSTAIN);
- }
-
- return $voters;
- }
-
- protected function getVoter($vote)
- {
- $voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
- $voter->expects($this->any())
- ->method('vote')
- ->will($this->returnValue($vote));
- ;
-
- return $voter;
- }
-
- protected function getVoterSupportsClass($ret)
- {
- $voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
- $voter->expects($this->any())
- ->method('supportsClass')
- ->will($this->returnValue($ret));
- ;
-
- return $voter;
- }
-
- protected function getVoterSupportsAttribute($ret)
- {
- $voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
- $voter->expects($this->any())
- ->method('supportsAttribute')
- ->will($this->returnValue($ret));
- ;
-
- return $voter;
- }
-}
diff --git a/Tests/Core/Authorization/Voter/AuthenticatedVoterTest.php b/Tests/Core/Authorization/Voter/AuthenticatedVoterTest.php
deleted file mode 100644
index b077712..0000000
--- a/Tests/Core/Authorization/Voter/AuthenticatedVoterTest.php
+++ /dev/null
@@ -1,78 +0,0 @@
-<?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\Tests\Core\Authorization\Voter;
-
-use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver;
-use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
-use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
-
-class AuthenticatedVoterTest extends \PHPUnit_Framework_TestCase
-{
- public function testSupportsClass()
- {
- $voter = new AuthenticatedVoter($this->getResolver());
- $this->assertTrue($voter->supportsClass('stdClass'));
- }
-
- /**
- * @dataProvider getVoteTests
- */
- public function testVote($authenticated, $attributes, $expected)
- {
- $voter = new AuthenticatedVoter($this->getResolver());
-
- $this->assertSame($expected, $voter->vote($this->getToken($authenticated), null, $attributes));
- }
-
- public function getVoteTests()
- {
- return array(
- array('fully', array(), VoterInterface::ACCESS_ABSTAIN),
- array('fully', array('FOO'), VoterInterface::ACCESS_ABSTAIN),
- array('remembered', array(), VoterInterface::ACCESS_ABSTAIN),
- array('remembered', array('FOO'), VoterInterface::ACCESS_ABSTAIN),
- array('anonymously', array(), VoterInterface::ACCESS_ABSTAIN),
- array('anonymously', array('FOO'), VoterInterface::ACCESS_ABSTAIN),
-
- array('fully', array('IS_AUTHENTICATED_ANONYMOUSLY'), VoterInterface::ACCESS_GRANTED),
- array('remembered', array('IS_AUTHENTICATED_ANONYMOUSLY'), VoterInterface::ACCESS_GRANTED),
- array('anonymously', array('IS_AUTHENTICATED_ANONYMOUSLY'), VoterInterface::ACCESS_GRANTED),
-
- array('fully', array('IS_AUTHENTICATED_REMEMBERED'), VoterInterface::ACCESS_GRANTED),
- array('remembered', array('IS_AUTHENTICATED_REMEMBERED'), VoterInterface::ACCESS_GRANTED),
- array('anonymously', array('IS_AUTHENTICATED_REMEMBERED'), VoterInterface::ACCESS_DENIED),
-
- array('fully', array('IS_AUTHENTICATED_FULLY'), VoterInterface::ACCESS_GRANTED),
- array('remembered', array('IS_AUTHENTICATED_FULLY'), VoterInterface::ACCESS_DENIED),
- array('anonymously', array('IS_AUTHENTICATED_FULLY'), VoterInterface::ACCESS_DENIED),
- );
- }
-
- protected function getResolver()
- {
- return new AuthenticationTrustResolver(
- 'Symfony\\Component\\Security\\Core\\Authentication\\Token\\AnonymousToken',
- 'Symfony\\Component\\Security\\Core\\Authentication\\Token\\RememberMeToken'
- );
- }
-
- protected function getToken($authenticated)
- {
- if ('fully' === $authenticated) {
- return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
- } elseif ('remembered' === $authenticated) {
- return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', array('setPersistent'), array(), '', false);
- } else {
- return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', null, array('', ''));
- }
- }
-}
diff --git a/Tests/Core/Authorization/Voter/RoleHierarchyVoterTest.php b/Tests/Core/Authorization/Voter/RoleHierarchyVoterTest.php
deleted file mode 100644
index a50fa79..0000000
--- a/Tests/Core/Authorization/Voter/RoleHierarchyVoterTest.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?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\Tests\Core\Authorization\Voter;
-
-use Symfony\Component\Security\Core\Authorization\Voter\RoleHierarchyVoter;
-use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
-use Symfony\Component\Security\Core\Role\RoleHierarchy;
-
-class RoleHierarchyVoterTest extends RoleVoterTest
-{
- /**
- * @dataProvider getVoteTests
- */
- public function testVote($roles, $attributes, $expected)
- {
- $voter = new RoleHierarchyVoter(new RoleHierarchy(array('ROLE_FOO' => array('ROLE_FOOBAR'))));
-
- $this->assertSame($expected, $voter->vote($this->getToken($roles), null, $attributes));
- }
-
- public function getVoteTests()
- {
- return array_merge(parent::getVoteTests(), array(
- array(array('ROLE_FOO'), array('ROLE_FOOBAR'), VoterInterface::ACCESS_GRANTED),
- ));
- }
-}
diff --git a/Tests/Core/Authorization/Voter/RoleVoterTest.php b/Tests/Core/Authorization/Voter/RoleVoterTest.php
deleted file mode 100644
index 63608eb..0000000
--- a/Tests/Core/Authorization/Voter/RoleVoterTest.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?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\Tests\Core\Authorization\Voter;
-
-use Symfony\Component\Security\Core\Authorization\Voter\RoleVoter;
-use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
-use Symfony\Component\Security\Core\Role\Role;
-
-class RoleVoterTest extends \PHPUnit_Framework_TestCase
-{
- public function testSupportsClass()
- {
- $voter = new RoleVoter();
-
- $this->assertTrue($voter->supportsClass('Foo'));
- }
-
- /**
- * @dataProvider getVoteTests
- */
- public function testVote($roles, $attributes, $expected)
- {
- $voter = new RoleVoter();
-
- $this->assertSame($expected, $voter->vote($this->getToken($roles), null, $attributes));
- }
-
- public function getVoteTests()
- {
- return array(
- array(array(), array(), VoterInterface::ACCESS_ABSTAIN),
- array(array(), array('FOO'), VoterInterface::ACCESS_ABSTAIN),
- array(array(), array('ROLE_FOO'), VoterInterface::ACCESS_DENIED),
- array(array('ROLE_FOO'), array('ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
- array(array('ROLE_FOO'), array('FOO', 'ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
- array(array('ROLE_BAR', 'ROLE_FOO'), array('ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
- );
- }
-
- protected function getToken(array $roles)
- {
- foreach ($roles as $i => $role) {
- $roles[$i] = new Role($role);
- }
- $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
- $token->expects($this->once())
- ->method('getRoles')
- ->will($this->returnValue($roles));
- ;
-
- return $token;
- }
-}