mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Changing AclBase into AclInterface as it is now an interface.
Splitting the test case into separate test cases for each class.
This commit is contained in:
parent
523eda018e
commit
e111735905
2 changed files with 219 additions and 100 deletions
|
@ -76,8 +76,8 @@ class AclComponent extends Object {
|
|||
if (is_string($adapter)) {
|
||||
$adapter = new $adapter();
|
||||
}
|
||||
if (!$adapter instanceof AclBase) {
|
||||
throw new Exception(__('AclComponent adapters must extend AclBase'));
|
||||
if (!$adapter instanceof AclInterface) {
|
||||
throw new Exception(__('AclComponent adapters must implement AclInterface'));
|
||||
}
|
||||
$this->_Instance = $adapter;
|
||||
$this->_Instance->initialize($this);
|
||||
|
@ -176,14 +176,13 @@ class AclComponent extends Object {
|
|||
}
|
||||
|
||||
/**
|
||||
* Access Control List abstract class. Not to be instantiated.
|
||||
* Subclasses of this class are used by AclComponent to perform ACL checks in Cake.
|
||||
* Access Control List interface.
|
||||
* Implementing classes are used by AclComponent to perform ACL checks in Cake.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.controller.components
|
||||
* @abstract
|
||||
*/
|
||||
abstract class AclBase extends Object {
|
||||
interface AclInterface {
|
||||
|
||||
/**
|
||||
* Empty method to be overridden in subclasses
|
||||
|
@ -192,14 +191,44 @@ abstract class AclBase extends Object {
|
|||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
*/
|
||||
public abstract function check($aro, $aco, $action = "*");
|
||||
public function check($aro, $aco, $action = "*");
|
||||
|
||||
/**
|
||||
* Empty method to be overridden in subclasses
|
||||
* Allow methods are used to grant an ARO access to an ACO.
|
||||
*
|
||||
* @param object $component Component
|
||||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
*/
|
||||
public abstract function initialize($component);
|
||||
public function allow($aro, $aco, $action = "*");
|
||||
|
||||
/**
|
||||
* Deny methods are used to remove permission from an ARO to access an ACO.
|
||||
*
|
||||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
*/
|
||||
public function deny($aro, $aco, $action = "*");
|
||||
|
||||
/**
|
||||
* Inherit methods modify the permission for an ARO to be that of its parent object.
|
||||
*
|
||||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
*/
|
||||
public function inherit($aro, $aco, $action = "*");
|
||||
|
||||
/**
|
||||
* Initialization method for the Acl implementation
|
||||
*
|
||||
* @param AclComponent $component
|
||||
*/
|
||||
public function initialize($component);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,7 +251,7 @@ abstract class AclBase extends Object {
|
|||
* @package cake
|
||||
* @subpackage cake.cake.libs.model
|
||||
*/
|
||||
class DbAcl extends AclBase {
|
||||
class DbAcl extends Object implements AclInterface {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -492,7 +521,7 @@ class DbAcl extends AclBase {
|
|||
* @package cake
|
||||
* @subpackage cake.cake.libs.model.iniacl
|
||||
*/
|
||||
class IniAcl extends AclBase {
|
||||
class IniAcl extends Object implements AclInterface {
|
||||
|
||||
/**
|
||||
* Array with configuration, parsed from ini file
|
||||
|
@ -512,6 +541,42 @@ class IniAcl extends AclBase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* No op method, allow cannot be done with IniAcl
|
||||
*
|
||||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
*/
|
||||
public function allow($aro, $aco, $action = "*") {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* No op method, deny cannot be done with IniAcl
|
||||
*
|
||||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
*/
|
||||
public function deny($aro, $aco, $action = "*") {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* No op method, inherit cannot be done with IniAcl
|
||||
*
|
||||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
*/
|
||||
public function inherit($aro, $aco, $action = "*") {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Main ACL check function. Checks to see if the ARO (access request object) has access to the
|
||||
* ACO (access control object).Looks at the acl.ini.php file for permissions
|
||||
|
|
|
@ -188,7 +188,6 @@ class DbAclTwoTest extends DbAcl {
|
|||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class AclComponentTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* fixtures property
|
||||
*
|
||||
|
@ -196,7 +195,6 @@ class AclComponentTest extends CakeTestCase {
|
|||
* @access public
|
||||
*/
|
||||
public $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two');
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
|
@ -265,6 +263,145 @@ class AclComponentTest extends CakeTestCase {
|
|||
$this->Acl->adapter($thing);
|
||||
}
|
||||
|
||||
/**
|
||||
* testStartup method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testStartup() {
|
||||
$controller = new Controller();
|
||||
$this->assertTrue($this->Acl->startup($controller));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for the IniAcl implementation
|
||||
*
|
||||
* @package cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class IniAclTestCase extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* testIniReadConfigFile
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testIniReadConfigFile() {
|
||||
$Ini = new IniAcl();
|
||||
$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
||||
$result = $Ini->readConfigFile($iniFile);
|
||||
$expected = array(
|
||||
'admin' => array(
|
||||
'groups' => 'administrators',
|
||||
'allow' => '',
|
||||
'deny' => 'ads',
|
||||
),
|
||||
'paul' => array(
|
||||
'groups' => 'users',
|
||||
'allow' =>'',
|
||||
'deny' => '',
|
||||
),
|
||||
'jenny' => array(
|
||||
'groups' => 'users',
|
||||
'allow' => 'ads',
|
||||
'deny' => 'images, files',
|
||||
),
|
||||
'nobody' => array(
|
||||
'groups' => 'anonymous',
|
||||
'allow' => '',
|
||||
'deny' => '',
|
||||
),
|
||||
'administrators' => array(
|
||||
'deny' => '',
|
||||
'allow' => 'posts, comments, images, files, stats, ads',
|
||||
),
|
||||
'users' => array(
|
||||
'allow' => 'posts, comments, images, files',
|
||||
'deny' => 'stats, ads',
|
||||
),
|
||||
'anonymous' => array(
|
||||
'allow' => '',
|
||||
'deny' => 'posts, comments, images, files, stats, ads',
|
||||
),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIniCheck method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testIniCheck() {
|
||||
$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
||||
|
||||
$Ini = new IniAcl();
|
||||
$Ini->config = $Ini->readConfigFile($iniFile);
|
||||
|
||||
$this->assertFalse($Ini->check('admin', 'ads'));
|
||||
$this->assertTrue($Ini->check('admin', 'posts'));
|
||||
|
||||
$this->assertTrue($Ini->check('jenny', 'posts'));
|
||||
$this->assertTrue($Ini->check('jenny', 'ads'));
|
||||
|
||||
$this->assertTrue($Ini->check('paul', 'posts'));
|
||||
$this->assertFalse($Ini->check('paul', 'ads'));
|
||||
|
||||
$this->assertFalse($Ini->check('nobody', 'comments'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test case for AclComponent using the DbAcl implementation.
|
||||
*
|
||||
* @package cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class DbAclTestCase extends CakeTestCase {
|
||||
/**
|
||||
* fixtures property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
public $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two');
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Acl =& new AclComponent();
|
||||
}
|
||||
|
||||
/**
|
||||
* before method
|
||||
*
|
||||
* @param mixed $method
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function before($method) {
|
||||
Configure::write('Acl.classname', 'DbAclTwoTest');
|
||||
Configure::write('Acl.database', 'test_suite');
|
||||
parent::before($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
unset($this->Acl);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAclCreate method
|
||||
*
|
||||
|
@ -517,90 +654,6 @@ class AclComponentTest extends CakeTestCase {
|
|||
$this->expectError('DbAcl::allow() - Invalid node');
|
||||
$this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testStartup method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testStartup() {
|
||||
$controller = new Controller();
|
||||
$this->assertTrue($this->Acl->startup($controller));
|
||||
}
|
||||
|
||||
/**
|
||||
* testIniReadConfigFile
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testIniReadConfigFile() {
|
||||
$Ini = new IniAcl();
|
||||
$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
||||
$result = $Ini->readConfigFile($iniFile);
|
||||
$expected = array(
|
||||
'admin' => array(
|
||||
'groups' => 'administrators',
|
||||
'allow' => '',
|
||||
'deny' => 'ads',
|
||||
),
|
||||
'paul' => array(
|
||||
'groups' => 'users',
|
||||
'allow' =>'',
|
||||
'deny' => '',
|
||||
),
|
||||
'jenny' => array(
|
||||
'groups' => 'users',
|
||||
'allow' => 'ads',
|
||||
'deny' => 'images, files',
|
||||
),
|
||||
'nobody' => array(
|
||||
'groups' => 'anonymous',
|
||||
'allow' => '',
|
||||
'deny' => '',
|
||||
),
|
||||
'administrators' => array(
|
||||
'deny' => '',
|
||||
'allow' => 'posts, comments, images, files, stats, ads',
|
||||
),
|
||||
'users' => array(
|
||||
'allow' => 'posts, comments, images, files',
|
||||
'deny' => 'stats, ads',
|
||||
),
|
||||
'anonymous' => array(
|
||||
'allow' => '',
|
||||
'deny' => 'posts, comments, images, files, stats, ads',
|
||||
),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIniCheck method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testIniCheck() {
|
||||
$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
||||
|
||||
$Ini = new IniAcl();
|
||||
$Ini->config = $Ini->readConfigFile($iniFile);
|
||||
$this->Acl->adapter($Ini);
|
||||
|
||||
$this->assertFalse($this->Acl->check('admin', 'ads'));
|
||||
$this->assertTrue($this->Acl->check('admin', 'posts'));
|
||||
|
||||
$this->assertTrue($this->Acl->check('jenny', 'posts'));
|
||||
$this->assertTrue($this->Acl->check('jenny', 'ads'));
|
||||
|
||||
$this->assertTrue($this->Acl->check('paul', 'posts'));
|
||||
$this->assertFalse($this->Acl->check('paul', 'ads'));
|
||||
|
||||
$this->assertFalse($this->Acl->check('nobody', 'comments'));
|
||||
}
|
||||
|
||||
/**
|
||||
* debug function - to help editing/creating test cases for the ACL component
|
||||
*
|
||||
|
@ -646,9 +699,9 @@ class AclComponentTest extends CakeTestCase {
|
|||
$permisssions = array_map(array(&$this, '__pad'), $permissions);
|
||||
array_unshift($permissions, 'Current Permissions :');
|
||||
if ($printTreesToo) {
|
||||
debug (array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList()));
|
||||
debug(array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList()));
|
||||
}
|
||||
debug (implode("\r\n", $permissions));
|
||||
debug(implode("\r\n", $permissions));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -664,4 +717,5 @@ class AclComponentTest extends CakeTestCase {
|
|||
return str_pad($string, $len);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue