test: Roles have permissions, not users

This commit is contained in:
Johannes Meyer 2021-01-22 15:59:01 +01:00
parent c0541d70e9
commit b2f7c3788d
2 changed files with 19 additions and 5 deletions

View File

@ -3,6 +3,7 @@
namespace Tests\Icinga; namespace Tests\Icinga;
use Icinga\Authentication\Role;
use Mockery; use Mockery;
use DateTimeZone; use DateTimeZone;
use Icinga\User; use Icinga\User;
@ -62,14 +63,18 @@ class UserTest extends BaseTestCase
public function testPermissions() public function testPermissions()
{ {
$user = new User('test'); $role = new Role();
$user->setPermissions(array( $role->setPermissions([
'test', 'test',
'test/some/specific', 'test/some/specific',
'test/more/*', 'test/more/*',
'test/wildcard-with-wildcard/*', 'test/wildcard-with-wildcard/*',
'test/even-more/specific-with-wildcard/*' 'test/even-more/specific-with-wildcard/*'
)); ]);
$user = new User('test');
$user->setRoles([$role]);
$this->assertTrue($user->can('test')); $this->assertTrue($user->can('test'));
$this->assertTrue($user->can('test/some/specific')); $this->assertTrue($user->can('test/some/specific'));
$this->assertTrue($user->can('test/more/everything')); $this->assertTrue($user->can('test/more/everything'));

View File

@ -3,6 +3,7 @@
namespace Tests\Icinga\Web; namespace Tests\Icinga\Web;
use Icinga\Authentication\Role;
use Mockery; use Mockery;
use Icinga\Test\BaseTestCase; use Icinga\Test\BaseTestCase;
use Icinga\User; use Icinga\User;
@ -47,8 +48,12 @@ class SearchDashboardTest extends BaseTestCase
public function testWhetherSearchLoadsSearchDashletsFromModules() public function testWhetherSearchLoadsSearchDashletsFromModules()
{ {
$role = new Role();
$role->setPermissions(['*']);
$user = new User('test'); $user = new User('test');
$user->setPermissions(array('*' => '*')); $user->setRoles([$role]);
$dashboard = new SearchDashboard(); $dashboard = new SearchDashboard();
$dashboard->setUser($user); $dashboard->setUser($user);
$dashboard = $dashboard->search('pending'); $dashboard = $dashboard->search('pending');
@ -60,8 +65,12 @@ class SearchDashboardTest extends BaseTestCase
public function testWhetherSearchProvidesHintWhenSearchStringIsEmpty() public function testWhetherSearchProvidesHintWhenSearchStringIsEmpty()
{ {
$role = new Role();
$role->setPermissions(['*']);
$user = new User('test'); $user = new User('test');
$user->setPermissions(array('*' => '*')); $user->setRoles([$role]);
$dashboard = new SearchDashboard(); $dashboard = new SearchDashboard();
$dashboard->setUser($user); $dashboard->setUser($user);
$dashboard = $dashboard->search(); $dashboard = $dashboard->search();