From b2f7c3788d08bb1cd5cd070e90e0bc297d9fab2d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 22 Jan 2021 15:59:01 +0100 Subject: [PATCH] test: Roles have permissions, not users --- test/php/library/Icinga/UserTest.php | 11 ++++++++--- .../Icinga/Web/Widget/SearchDashboardTest.php | 13 +++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/test/php/library/Icinga/UserTest.php b/test/php/library/Icinga/UserTest.php index 00230b827..d73ed6b43 100644 --- a/test/php/library/Icinga/UserTest.php +++ b/test/php/library/Icinga/UserTest.php @@ -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')); diff --git a/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php b/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php index e5e0f1c62..7370338e5 100644 --- a/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php +++ b/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php @@ -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();