Skip to content

Commit

Permalink
add test when have inverted rule with whole action
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexzPurewoko committed Dec 28, 2023
1 parent 2e368bc commit be56c7b
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/Feature/Core/AbilityCheckerImplTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,43 @@
->toBeFalse();
});

it('must return false when the user have inverted rule with whole (star) action', function () {
$compiledRules = new CompiledRules([
(object) [
'id' => 1,
'rule' => 'scope2:resource1:read'
],
(object) [
'id' => 2,
'rule' => '!scope1:resource1/666:update'
],
(object) [
'id' => 3,
'rule' => 'scope1:resource1/[6, 7, 8]:update'
],
(object) [
'id' => 4,
'rule' => 'scope2:resource1/[6, 7, 8]:update'
],
(object) [
'id' => 5,
'rule' => 'scope2:resource1:*'
],
(object) [
'id' => 6,
'rule' => '!scope2:resource1/7:*'
],
(object) [
'id' => 7,
'rule' => 'scope2:resource1/7:update'
],
]);

$abilityChecker = new AbilityCheckerImpl($compiledRules);
expect($abilityChecker->can('update', 'resource1', 'scope2', 7))
->toBeFalse();
});

it('must return true when user have rule with ALL action', function () {
$compiledRules = new CompiledRules([
(object) [
Expand Down Expand Up @@ -199,4 +236,4 @@
expect($user->hasExactRule(RuleCompiler::compile('scope2:resource1/[8, 9]:update')))
->toBeFalse();
});
});
});

0 comments on commit be56c7b

Please sign in to comment.