mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Added testing coverage to API token auth
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
use BookStack\Api\ApiToken;
|
||||
use BookStack\Auth\Permissions\PermissionService;
|
||||
use BookStack\Auth\Permissions\RolePermission;
|
||||
use BookStack\Auth\Role;
|
||||
use BookStack\Auth\User;
|
||||
use BookStack\Entities\Bookshelf;
|
||||
@ -52,6 +54,18 @@ class DummyContentSeeder extends Seeder
|
||||
$shelves = factory(Bookshelf::class, 10)->create($byData);
|
||||
$largeBook->shelves()->attach($shelves->pluck('id'));
|
||||
|
||||
// Assign API permission to editor role and create an API key
|
||||
$apiPermission = RolePermission::getByName('access-api');
|
||||
$editorRole->attachPermission($apiPermission);
|
||||
$token = (new ApiToken())->forceFill([
|
||||
'user_id' => $editorUser->id,
|
||||
'name' => 'Testing API key',
|
||||
'expires_at' => ApiToken::defaultExpiry(),
|
||||
'secret' => Hash::make('password'),
|
||||
'token_id' => 'apitoken',
|
||||
]);
|
||||
$token->save();
|
||||
|
||||
app(PermissionService::class)->buildJointPermissions();
|
||||
app(SearchService::class)->indexAllEntities();
|
||||
}
|
||||
|
Reference in New Issue
Block a user