-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cover permission instance verification based on its own guard (#…
- Loading branch information
1 parent
96c2761
commit 7a39f04
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,47 @@ public function it_can_check_wildcard_permission() | |
$this->assertFalse($user1->hasPermissionTo('projects.view')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_check_wildcard_permission_for_a_non_default_guard() | ||
{ | ||
app('config')->set('permission.enable_wildcard_permission', true); | ||
|
||
$user1 = User::create(['email' => '[email protected]']); | ||
|
||
$permission1 = Permission::create(['name' => 'articles.edit,view,create', 'guard_name' => 'api']); | ||
$permission2 = Permission::create(['name' => 'news.*', 'guard_name' => 'api']); | ||
$permission3 = Permission::create(['name' => 'posts.*', 'guard_name' => 'api']); | ||
|
||
$user1->givePermissionTo([$permission1, $permission2, $permission3]); | ||
|
||
$this->assertTrue($user1->hasPermissionTo('posts.create', 'api')); | ||
$this->assertTrue($user1->hasPermissionTo('posts.create.123', 'api')); | ||
$this->assertTrue($user1->hasPermissionTo('posts.*', 'api')); | ||
$this->assertTrue($user1->hasPermissionTo('articles.view', 'api')); | ||
$this->assertFalse($user1->hasPermissionTo('projects.view', 'api')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_check_wildcard_permission_from_instance_without_explicit_guard_argument() | ||
{ | ||
app('config')->set('permission.enable_wildcard_permission', true); | ||
|
||
$user1 = User::create(['email' => '[email protected]']); | ||
|
||
$permission2 = Permission::create(['name' => 'articles.view']); | ||
$permission1 = Permission::create(['name' => 'articles.edit', 'guard_name' => 'api']); | ||
$permission3 = Permission::create(['name' => 'news.*', 'guard_name' => 'api']); | ||
$permission4 = Permission::create(['name' => 'posts.*', 'guard_name' => 'api']); | ||
|
||
$user1->givePermissionTo([$permission1, $permission2, $permission3]); | ||
|
||
$this->assertTrue($user1->hasPermissionTo($permission1)); | ||
$this->assertTrue($user1->hasPermissionTo($permission2)); | ||
$this->assertTrue($user1->hasPermissionTo($permission3)); | ||
$this->assertFalse($user1->hasPermissionTo($permission4)); | ||
$this->assertFalse($user1->hasPermissionTo('articles.edit')); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
|