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;
use Icinga\Authentication\Role;
use Mockery;
use DateTimeZone;
use Icinga\User;
@ -62,14 +63,18 @@ class UserTest extends BaseTestCase
public function testPermissions()
{
$user = new User('test');
$user->setPermissions(array(
$role = new Role();
$role->setPermissions([
'test',
'test/some/specific',
'test/more/*',
'test/wildcard-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/some/specific'));
$this->assertTrue($user->can('test/more/everything'));

View File

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