1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
require_once __DIR__.'/../../Base.php';
use Kanboard\Core\Security\AccessMap;
class AccessMapTest extends Base
{
public function testRoleHierarchy()
{
$acl = new AccessMap;
$acl->setRoleHierarchy('admin', array('manager', 'user'));
$acl->setRoleHierarchy('manager', array('user'));
$this->assertEquals(array('admin'), $acl->getRoleHierarchy('admin'));
$this->assertEquals(array('manager', 'admin'), $acl->getRoleHierarchy('manager'));
$this->assertEquals(array('user', 'admin', 'manager'), $acl->getRoleHierarchy('user'));
}
public function testGetHighestRole()
{
$acl = new AccessMap;
$acl->setRoleHierarchy('manager', array('member', 'viewer'));
$acl->setRoleHierarchy('member', array('viewer'));
$this->assertEquals('manager', $acl->getHighestRole(array('viewer', 'manager', 'member')));
$this->assertEquals('manager', $acl->getHighestRole(array('viewer', 'manager')));
$this->assertEquals('manager', $acl->getHighestRole(array('manager', 'member')));
$this->assertEquals('member', $acl->getHighestRole(array('viewer', 'member')));
$this->assertEquals('member', $acl->getHighestRole(array('member')));
$this->assertEquals('viewer', $acl->getHighestRole(array('viewer')));
}
public function testAddRulesAndGetRoles()
{
$acl = new AccessMap;
$acl->setDefaultRole('role3');
$acl->setRoleHierarchy('role2', array('role1'));
$acl->add('MyController', 'myAction1', 'role2');
$acl->add('MyController', 'myAction2', 'role1');
$acl->add('MyAdminController', '*', 'role2');
$acl->add('SomethingElse', array('actionA', 'actionB'), 'role2');
$this->assertEquals(array('role2'), $acl->getRoles('mycontroller', 'MyAction1'));
$this->assertEquals(array('role1', 'role2'), $acl->getRoles('mycontroller', 'MyAction2'));
$this->assertEquals(array('role2'), $acl->getRoles('Myadmincontroller', 'MyAction'));
$this->assertEquals(array('role3'), $acl->getRoles('AnotherController', 'ActionNotFound'));
$this->assertEquals(array('role2'), $acl->getRoles('somethingelse', 'actiona'));
$this->assertEquals(array('role2'), $acl->getRoles('somethingelse', 'actionb'));
$this->assertEquals(array('role3'), $acl->getRoles('somethingelse', 'actionc'));
}
}
|