X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1a56de6cb41b0597e15c4bbd54023402102602bd..refs/pull/5721/head:/tests/User/RoleManagementTest.php diff --git a/tests/User/RoleManagementTest.php b/tests/User/RoleManagementTest.php index 4d61cf6e6..8683fcb6e 100644 --- a/tests/User/RoleManagementTest.php +++ b/tests/User/RoleManagementTest.php @@ -96,6 +96,31 @@ class RoleManagementTest extends TestCase $this->assertActivityExists(ActivityType::ROLE_DELETE); } + public function test_role_external_auth_id_validation() + { + config()->set('auth.method', 'oidc'); + $role = Role::query()->first(); + $routeByMethod = [ + 'post' => '/settings/roles/new', + 'put' => "/settings/roles/{$role->id}", + ]; + + foreach ($routeByMethod as $method => $route) { + $resp = $this->asAdmin()->get($route); + $resp->assertDontSee('The external auth id'); + + $resp = $this->asAdmin()->call($method, $route, [ + 'display_name' => 'Test role for auth id validation', + 'description' => '', + 'external_auth_id' => str_repeat('a', 181), + ]); + + $resp->assertRedirect($route); + $resp = $this->followRedirects($resp); + $resp->assertSee('The external auth id may not be greater than 180 characters.'); + } + } + public function test_admin_role_cannot_be_removed_if_user_last_admin() { /** @var Role $adminRole */ @@ -235,7 +260,7 @@ class RoleManagementTest extends TestCase /** @var Role $publicRole */ $publicRole = Role::getSystemRole('public'); $resp = $this->asAdmin()->delete('/settings/roles/delete/' . $publicRole->id); - $resp->assertRedirect('/'); + $resp->assertRedirect('/settings/roles/delete/' . $publicRole->id); $this->get('/settings/roles/delete/' . $publicRole->id); $resp = $this->delete('/settings/roles/delete/' . $publicRole->id); @@ -260,4 +285,30 @@ class RoleManagementTest extends TestCase $this->actingAs($viewer)->get($page->getUrl())->assertStatus(404); } + + public function test_index_listing_sorting() + { + $this->asAdmin(); + $role = $this->users->createRole(); + $role->display_name = 'zz test role'; + $role->created_at = now()->addDays(1); + $role->save(); + + $runTest = function (string $order, string $direction, bool $expectFirstResult) use ($role) { + setting()->putForCurrentUser('roles_sort', $order); + setting()->putForCurrentUser('roles_sort_order', $direction); + $html = $this->withHtml($this->get('/settings/roles')); + $selector = ".item-list-row:first-child a[href$=\"/roles/{$role->id}\"]"; + if ($expectFirstResult) { + $html->assertElementExists($selector); + } else { + $html->assertElementNotExists($selector); + } + }; + + $runTest('name', 'asc', false); + $runTest('name', 'desc', true); + $runTest('created_at', 'desc', true); + $runTest('created_at', 'asc', false); + } }