From 2f423963174956602ae27d9f7aa3ee62bd98a7fe Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 5 Nov 2017 13:42:57 -0600 Subject: [PATCH] Fix bug with permissions including more than one dash, closes #727 --- app/Services/Api/KeyCreationService.php | 4 ++-- tests/Unit/Services/Api/KeyCreationServiceTest.php | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Services/Api/KeyCreationService.php b/app/Services/Api/KeyCreationService.php index b4fb8e4af..1a4312542 100644 --- a/app/Services/Api/KeyCreationService.php +++ b/app/Services/Api/KeyCreationService.php @@ -86,7 +86,7 @@ class KeyCreationService $nodes = $this->permissionService->getPermissions(); foreach ($permissions as $permission) { - @list($block, $search) = explode('-', $permission); + @list($block, $search) = explode('-', $permission, 2); if ( (empty($block) || empty($search)) || @@ -100,7 +100,7 @@ class KeyCreationService } foreach ($administrative as $permission) { - @list($block, $search) = explode('-', $permission); + @list($block, $search) = explode('-', $permission, 2); if ( (empty($block) || empty($search)) || diff --git a/tests/Unit/Services/Api/KeyCreationServiceTest.php b/tests/Unit/Services/Api/KeyCreationServiceTest.php index 57a0343cf..159d64255 100644 --- a/tests/Unit/Services/Api/KeyCreationServiceTest.php +++ b/tests/Unit/Services/Api/KeyCreationServiceTest.php @@ -82,19 +82,21 @@ class KeyCreationServiceTest extends TestCase ], true, true)->once()->andReturn((object) ['id' => 1]); $this->permissions->shouldReceive('getPermissions')->withNoArgs()->once()->andReturn([ - '_user' => ['server' => ['list']], - 'server' => ['create'], + '_user' => ['server' => ['list', 'multiple-dash-test']], + 'server' => ['create', 'admin-dash-test'], ]); $this->permissions->shouldReceive('create')->with(1, 'user.server-list')->once()->andReturnNull(); + $this->permissions->shouldReceive('create')->with(1, 'user.server-multiple-dash-test')->once()->andReturnNull(); $this->permissions->shouldReceive('create')->with(1, 'server-create')->once()->andReturnNull(); + $this->permissions->shouldReceive('create')->with(1, 'server-admin-dash-test')->once()->andReturnNull(); $this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull(); $response = $this->service->handle( ['test-data' => 'test'], - ['invalid-node', 'server-list'], - ['invalid-node', 'server-create'] + ['invalid-node', 'server-list', 'server-multiple-dash-test'], + ['invalid-node', 'server-create', 'server-admin-dash-test'] ); $this->assertNotEmpty($response);