-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If effective role is present in token, check it in Authorizator along…
…side with user role and scopes
- Loading branch information
Showing
7 changed files
with
142 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
include __DIR__ . "/../bootstrap.php"; | ||
|
||
use App\Security\Authorizator; | ||
use App\Security\Loader; | ||
use App\Security\PolicyRegistry; | ||
use App\Security\Roles; | ||
use App\Security\UserStorage; | ||
use Tester\Assert; | ||
|
||
class Resource1 { } | ||
|
||
interface ITestResource1Permissions { | ||
function canAction1(Resource1 $resource): bool; | ||
function canAction2(Resource1 $resource): bool; | ||
} | ||
|
||
/** | ||
* @testCase | ||
*/ | ||
class TestAuthorizatorWithEffectiveRole extends Tester\TestCase | ||
{ | ||
use MockeryTrait; | ||
|
||
/** @var PolicyRegistry */ | ||
private $policies; | ||
|
||
/** @var Roles */ | ||
private $roles; | ||
|
||
/** @var Authorizator */ | ||
private $authorizator; | ||
|
||
/** @var Loader */ | ||
private $loader; | ||
|
||
public function __construct() | ||
{ | ||
$this->loader = new Loader(TEMP_DIR . '/security', __DIR__ . '/config/with_effective_role.neon', [ | ||
'resource1' => ITestResource1Permissions::class | ||
], Mockery::mock(UserStorage::class)); | ||
} | ||
|
||
public function setUp() | ||
{ | ||
$this->policies = new PolicyRegistry(); | ||
$this->roles = $this->loader->loadRoles(); | ||
$this->authorizator = $this->loader->loadAuthorizator($this->policies, $this->roles); | ||
} | ||
|
||
public function testNoEffectiveRoles() | ||
{ | ||
Assert::true($this->authorizator->isAllowed( | ||
new MockIdentity([ 'normal_role' ]), | ||
'resource1', | ||
'action1', | ||
[ | ||
'resource1' => new Resource1(), | ||
] | ||
)); | ||
} | ||
|
||
public function testRestrictedEffectiveRole() | ||
{ | ||
Assert::false($this->authorizator->isAllowed( | ||
new MockIdentity([ 'normal_role' ], [], 'effective_role_2'), | ||
'resource1', | ||
'action1', | ||
[ | ||
'resource1' => new Resource1(), | ||
] | ||
)); | ||
} | ||
|
||
public function testAgreeingRoles() | ||
{ | ||
Assert::true($this->authorizator->isAllowed( | ||
new MockIdentity([ 'normal_role' ], [], 'effective_role_1'), | ||
'resource1', | ||
'action1', | ||
[ | ||
'resource1' => new Resource1(), | ||
] | ||
)); | ||
} | ||
} | ||
|
||
(new TestAuthorizatorWithEffectiveRole())->run(); |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
roles: | ||
- name: normal_role | ||
- name: effective_role_1 | ||
- name: effective_role_2 | ||
|
||
permissions: | ||
- allow: true | ||
role: normal_role | ||
resource: resource1 | ||
actions: | ||
- action1 | ||
- action2 | ||
- allow: true | ||
role: effective_role_1 | ||
resource: resource1 | ||
actions: | ||
- action1 | ||
- allow: true | ||
role: effective_role_2 | ||
resource: resource1 | ||
actions: | ||
- action2 |
File renamed without changes.