2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* AclComponentTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-10-30 17:30:26 +00:00
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5435
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
|
|
|
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
|
|
|
}
|
2009-03-21 23:55:39 +00:00
|
|
|
App::import(array('controller' .DS . 'components' . DS . 'acl', 'model' . DS . 'db_acl'));
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* AclNodeTwoTestBase class
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class AclNodeTwoTestBase extends AclNode {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useDbConfig property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'test_suite'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $useDbConfig = 'test_suite';
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* cacheSources property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $cacheSources = false;
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* AroTwoTest class
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class AroTwoTest extends AclNodeTwoTestBase {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'AroTwoTest'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'AroTwoTest';
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'aro_twos'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $useTable = 'aro_twos';
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $hasAndBelongsToMany = array('AcoTwoTest' => array('with' => 'PermissionTwoTest'));
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* AcoTwoTest class
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class AcoTwoTest extends AclNodeTwoTestBase {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'AcoTwoTest'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'AcoTwoTest';
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'aco_twos'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $useTable = 'aco_twos';
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $hasAndBelongsToMany = array('AroTwoTest' => array('with' => 'PermissionTwoTest'));
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* PermissionTwoTest class
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class PermissionTwoTest extends CakeTestModel {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'PermissionTwoTest'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'PermissionTwoTest';
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'aros_aco_twos'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $useTable = 'aros_aco_twos';
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* cacheQueries property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $cacheQueries = false;
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* belongsTo property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $belongsTo = array('AroTwoTest' => array('foreignKey' => 'aro_id'), 'AcoTwoTest' => array('foreignKey' => 'aco_id'));
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* actsAs property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var mixed null
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $actsAs = null;
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* DbAclTwoTest class
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class DbAclTwoTest extends DbAcl {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* construct method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access private
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function __construct() {
|
|
|
|
$this->Aro =& new AroTwoTest();
|
|
|
|
$this->Aro->Permission =& new PermissionTwoTest();
|
|
|
|
$this->Aco =& new AcoTwoTest();
|
|
|
|
$this->Aro->Permission =& new PermissionTwoTest();
|
|
|
|
}
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* IniAclTest class
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class IniAclTest extends IniAcl {
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Short description for class.
|
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class AclComponentTest extends CakeTestCase {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* fixtures property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two');
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* startTest method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function startTest() {
|
|
|
|
$this->Acl =& new AclComponent();
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* before method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
|
|
|
* @param mixed $method
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function before($method) {
|
|
|
|
Configure::write('Acl.classname', 'DbAclTwoTest');
|
|
|
|
Configure::write('Acl.database', 'test_suite');
|
|
|
|
parent::before($method);
|
|
|
|
}
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
|
|
|
unset($this->Acl);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAclCreate method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAclCreate() {
|
|
|
|
$this->Acl->Aro->create(array('alias' => 'Chotchkey'));
|
|
|
|
$this->assertTrue($this->Acl->Aro->save());
|
|
|
|
|
|
|
|
$parent = $this->Acl->Aro->id;
|
|
|
|
|
|
|
|
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Joanna'));
|
|
|
|
$this->assertTrue($this->Acl->Aro->save());
|
|
|
|
|
|
|
|
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Stapler'));
|
|
|
|
$this->assertTrue($this->Acl->Aro->save());
|
|
|
|
|
|
|
|
$root = $this->Acl->Aco->node('ROOT');
|
|
|
|
$parent = $root[0]['AcoTwoTest']['id'];
|
|
|
|
|
|
|
|
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'Drinks'));
|
|
|
|
$this->assertTrue($this->Acl->Aco->save());
|
|
|
|
|
|
|
|
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'PiecesOfFlair'));
|
|
|
|
$this->assertTrue($this->Acl->Aco->save());
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAclCreateWithParent method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAclCreateWithParent() {
|
|
|
|
$parent = $this->Acl->Aro->findByAlias('Peter', null, null, -1);
|
|
|
|
$this->Acl->Aro->create();
|
|
|
|
$this->Acl->Aro->save(array(
|
2008-05-31 04:31:30 +00:00
|
|
|
'alias' => 'Subordinate',
|
|
|
|
'model' => 'User',
|
2008-05-30 11:40:08 +00:00
|
|
|
'foreign_key' => 7,
|
|
|
|
'parent_id' => $parent['AroTwoTest']['id']
|
|
|
|
));
|
|
|
|
$result = $this->Acl->Aro->findByAlias('Subordinate', null, null, -1);
|
|
|
|
$this->assertEqual($result['AroTwoTest']['lft'], 16);
|
|
|
|
$this->assertEqual($result['AroTwoTest']['rght'], 17);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDbAclAllow method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDbAclAllow() {
|
|
|
|
$this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'read'));
|
|
|
|
$this->assertTrue($this->Acl->allow('Micheal', 'tpsReports', array('read', 'delete', 'update')));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'update'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'read'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
|
|
|
|
|
2008-05-31 04:31:30 +00:00
|
|
|
$this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'create'));
|
|
|
|
$this->assertTrue($this->Acl->allow('Micheal', 'ROOT/tpsReports', 'create'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'create'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->assertTrue($this->Acl->allow('Micheal', 'printers', 'create'));
|
2008-05-31 04:31:30 +00:00
|
|
|
// Michael no longer has his delete permission for tpsReports!
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
|
2008-05-31 04:31:30 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view'));
|
|
|
|
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/view', '*'));
|
|
|
|
$this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
|
|
|
|
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
|
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
|
2008-05-31 04:31:30 +00:00
|
|
|
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
|
|
|
|
$this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
|
|
|
|
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', 'update'));
|
2008-06-10 22:38:05 +00:00
|
|
|
// Samir should still have his tpsReports/view permissions, but does not
|
2008-05-31 04:31:30 +00:00
|
|
|
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->expectError('DbAcl::allow() - Invalid node');
|
|
|
|
$this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
|
|
|
|
|
|
|
$this->expectError('DbAcl::allow() - Invalid node');
|
|
|
|
$this->assertFalse($this->Acl->allow('Homer', 'tpsReports', 'create'));
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDbAclCheck method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function testDbAclCheck() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($this->Acl->check('Samir', 'print', 'read'));
|
|
|
|
$this->assertTrue($this->Acl->check('Lumbergh', 'current', 'read'));
|
|
|
|
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
|
|
|
|
$this->assertFalse($this->Acl->check('Milton', 'current', 'update'));
|
|
|
|
|
|
|
|
$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: WRONG\nAco: tpsReports");
|
|
|
|
$this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));
|
|
|
|
|
|
|
|
$this->expectError("ACO permissions key foobar does not exist in DbAcl::check()");
|
|
|
|
$this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));
|
|
|
|
|
2008-07-31 23:50:32 +00:00
|
|
|
$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: users\nAco: NonExistant");
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));
|
|
|
|
|
|
|
|
$this->assertFalse($this->Acl->check(null, 'printers', 'create'));
|
|
|
|
$this->assertFalse($this->Acl->check('managers', null, 'read'));
|
|
|
|
|
|
|
|
$this->assertTrue($this->Acl->check('Bobs', 'ROOT/tpsReports/view/current', 'read'));
|
|
|
|
$this->assertFalse($this->Acl->check('Samir', 'ROOT/tpsReports/update', 'read'));
|
|
|
|
|
|
|
|
$this->assertFalse($this->Acl->check('root/users/Milton', 'smash', 'delete'));
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* testDbAclCascadingDeny function
|
|
|
|
*
|
2008-05-31 04:31:30 +00:00
|
|
|
* Setup the acl permissions such that Bobs inherits from admin.
|
2008-05-30 11:40:08 +00:00
|
|
|
* deny Admin delete access to a specific resource, check the permisssions are inherited.
|
2008-05-31 04:31:30 +00:00
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testDbAclCascadingDeny() {
|
|
|
|
$this->Acl->inherit('Bobs', 'ROOT', '*');
|
|
|
|
$this->assertTrue($this->Acl->check('admin', 'tpsReports', 'delete'));
|
|
|
|
$this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'delete'));
|
|
|
|
$this->Acl->deny('admin', 'tpsReports', 'delete');
|
|
|
|
$this->assertFalse($this->Acl->check('admin', 'tpsReports', 'delete'));
|
|
|
|
$this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'delete'));
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDbAclDeny method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDbAclDeny() {
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'delete'));
|
|
|
|
$this->Acl->deny('Micheal', 'smash', 'delete');
|
|
|
|
$this->assertFalse($this->Acl->check('Micheal', 'smash', 'delete'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'read'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'create'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'update'));
|
|
|
|
$this->assertFalse($this->Acl->check('Micheal', 'smash', '*'));
|
|
|
|
|
|
|
|
$this->assertTrue($this->Acl->check('Samir', 'refill', '*'));
|
|
|
|
$this->Acl->deny('Samir', 'refill', '*');
|
|
|
|
$this->assertFalse($this->Acl->check('Samir', 'refill', 'create'));
|
|
|
|
$this->assertFalse($this->Acl->check('Samir', 'refill', 'update'));
|
|
|
|
$this->assertFalse($this->Acl->check('Samir', 'refill', 'read'));
|
|
|
|
$this->assertFalse($this->Acl->check('Samir', 'refill', 'delete'));
|
|
|
|
|
|
|
|
$result = $this->Acl->Aro->Permission->find('all', array('conditions' => array('AroTwoTest.alias' => 'Samir')));
|
|
|
|
$expected = '-1';
|
|
|
|
$this->assertEqual($result[0]['PermissionTwoTest']['_delete'], $expected);
|
|
|
|
|
|
|
|
$this->expectError('DbAcl::allow() - Invalid node');
|
|
|
|
$this->assertFalse($this->Acl->deny('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAclNodeLookup method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAclNodeLookup() {
|
|
|
|
$result = $this->Acl->Aro->node('root/users/Samir');
|
|
|
|
$expected = array(
|
|
|
|
array('AroTwoTest' => array('id' => '7', 'parent_id' => '4', 'model' => 'User', 'foreign_key' => 3, 'alias' => 'Samir')),
|
|
|
|
array('AroTwoTest' => array('id' => '4', 'parent_id' => '1', 'model' => 'Group', 'foreign_key' => 3, 'alias' => 'users')),
|
|
|
|
array('AroTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'root'))
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Acl->Aco->node('ROOT/tpsReports/view/current');
|
|
|
|
$expected = array(
|
|
|
|
array('AcoTwoTest' => array('id' => '4', 'parent_id' => '3', 'model' => null, 'foreign_key' => null, 'alias' => 'current')),
|
|
|
|
array('AcoTwoTest' => array('id' => '3', 'parent_id' => '2', 'model' => null, 'foreign_key' => null, 'alias' => 'view')),
|
|
|
|
array('AcoTwoTest' => array('id' => '2', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'tpsReports')),
|
|
|
|
array('AcoTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT')),
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDbInherit method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDbInherit() {
|
|
|
|
//parent doesn't have access inherit should still deny
|
|
|
|
$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
|
|
|
|
$this->Acl->inherit('Milton', 'smash', 'delete');
|
|
|
|
$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
|
|
|
|
|
|
|
|
//inherit parent
|
|
|
|
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
|
|
|
|
$this->Acl->inherit('Milton', 'smash', 'read');
|
|
|
|
$this->assertTrue($this->Acl->check('Milton', 'smash', 'read'));
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDbGrant method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDbGrant() {
|
|
|
|
$this->assertFalse($this->Acl->check('Samir', 'tpsReports', 'create'));
|
|
|
|
$this->Acl->grant('Samir', 'tpsReports', 'create');
|
|
|
|
$this->assertTrue($this->Acl->check('Samir', 'tpsReports', 'create'));
|
|
|
|
|
|
|
|
$this->assertFalse($this->Acl->check('Micheal', 'view', 'read'));
|
|
|
|
$this->Acl->grant('Micheal', 'view', array('read', 'create', 'update'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'view', 'read'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'view', 'create'));
|
|
|
|
$this->assertTrue($this->Acl->check('Micheal', 'view', 'update'));
|
|
|
|
$this->assertFalse($this->Acl->check('Micheal', 'view', 'delete'));
|
|
|
|
|
|
|
|
$this->expectError('DbAcl::allow() - Invalid node');
|
|
|
|
$this->assertFalse($this->Acl->grant('Peter', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDbRevoke method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDbRevoke() {
|
|
|
|
$this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'read'));
|
|
|
|
$this->Acl->revoke('Bobs', 'tpsReports', 'read');
|
|
|
|
$this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'read'));
|
|
|
|
|
|
|
|
$this->assertTrue($this->Acl->check('users', 'printers', 'read'));
|
|
|
|
$this->Acl->revoke('users', 'printers', 'read');
|
|
|
|
$this->assertFalse($this->Acl->check('users', 'printers', 'read'));
|
|
|
|
$this->assertFalse($this->Acl->check('Samir', 'printers', 'read'));
|
|
|
|
$this->assertFalse($this->Acl->check('Peter', 'printers', 'read'));
|
|
|
|
|
|
|
|
$this->expectError('DbAcl::allow() - Invalid node');
|
|
|
|
$this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testStartup method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testStartup() {
|
|
|
|
$controller = new Controller();
|
|
|
|
$this->assertTrue($this->Acl->startup($controller));
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-10-09 03:35:17 +00:00
|
|
|
* testIniReadConfigFile
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testIniReadConfigFile() {
|
|
|
|
Configure::write('Acl.classname', 'IniAclTest');
|
|
|
|
unset($this->Acl);
|
|
|
|
$this->Acl = new AclComponent();
|
|
|
|
$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
|
|
|
$result = $this->Acl->_Instance->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);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testIniCheck method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testIniCheck() {
|
|
|
|
Configure::write('Acl.classname', 'IniAclTest');
|
|
|
|
unset($this->Acl);
|
|
|
|
$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
|
|
|
|
|
|
|
$this->Acl = new AclComponent();
|
|
|
|
$this->Acl->_Instance->config= $this->Acl->_Instance->readConfigFile($iniFile);
|
|
|
|
|
|
|
|
$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
|
2008-05-31 04:31:30 +00:00
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* To check the overal ACL status at any time call $this->__debug();
|
|
|
|
* Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined
|
|
|
|
* Only designed to work with the db based ACL
|
|
|
|
*
|
2008-05-31 04:31:30 +00:00
|
|
|
* @param bool $treesToo
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access private
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function __debug ($printTreesToo = false) {
|
|
|
|
$this->Acl->Aro->displayField = 'alias';
|
|
|
|
$this->Acl->Aco->displayField = 'alias';
|
|
|
|
$aros = $this->Acl->Aro->find('list', array('order' => 'lft'));
|
|
|
|
$acos = $this->Acl->Aco->find('list', array('order' => 'lft'));
|
|
|
|
$rights = array('*', 'create', 'read', 'update', 'delete');
|
|
|
|
$permissions['Aros v Acos >'] = $acos;
|
|
|
|
foreach ($aros as $aro) {
|
|
|
|
$row = array();
|
|
|
|
foreach ($acos as $aco) {
|
|
|
|
$perms = '';
|
|
|
|
foreach ($rights as $right) {
|
|
|
|
if ($this->Acl->check($aro, $aco, $right)) {
|
|
|
|
if ($right == '*') {
|
|
|
|
$perms .= '****';
|
2008-05-31 04:31:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$perms .= $right[0];
|
|
|
|
} elseif ($right != '*') {
|
2008-05-31 04:31:30 +00:00
|
|
|
$perms .= ' ';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-31 04:31:30 +00:00
|
|
|
$row[] = $perms;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
$permissions[$aro] = $row;
|
|
|
|
}
|
|
|
|
foreach ($permissions as $key => $values) {
|
|
|
|
array_unshift($values, $key);
|
|
|
|
$values = array_map(array(&$this, '__pad'), $values);
|
|
|
|
$permissions[$key] = implode (' ', $values);
|
|
|
|
}
|
|
|
|
$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 (implode("\r\n", $permissions));
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* pad function
|
|
|
|
* Used by debug to format strings used in the data dump
|
2008-05-31 04:31:30 +00:00
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
* @param int $len
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access private
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function __pad($string = '', $len = 14) {
|
2008-05-31 04:31:30 +00:00
|
|
|
return str_pad($string, $len);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|