Skip to content

Commit 5224dc4

Browse files
authored
Merge pull request #1207 from lucasmichot/feature/8.x/cleanup-resolveInheritedScopes
[8.x] Fix resolveInheritedScopes.
2 parents 86a2cd8 + 0319409 commit 5224dc4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Token.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ protected function resolveInheritedScopes($scope)
117117
{
118118
$parts = explode(':', $scope);
119119

120+
$partsCount = count($parts);
121+
120122
$scopes = [];
121123

122-
for ($i = 0; $i <= count($parts); $i++) {
124+
for ($i = 1; $i <= $partsCount; $i++) {
123125
$scopes[] = implode(':', array_slice($parts, 0, $i));
124126
}
125127

tests/TokenTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Laravel\Passport\Passport;
66
use Laravel\Passport\Token;
77
use PHPUnit\Framework\TestCase;
8+
use ReflectionObject;
89

910
class TokenTest extends TestCase
1011
{
@@ -58,4 +59,20 @@ public function test_token_can_determine_if_it_has_inherited_scopes()
5859
$this->assertTrue($token->can('something'));
5960
$this->assertTrue($token->can('admin:webhooks:write'));
6061
}
62+
63+
public function test_token_resolves_inherited_scopes()
64+
{
65+
$token = new Token;
66+
67+
$reflector = new ReflectionObject($token);
68+
$method = $reflector->getMethod('resolveInheritedScopes');
69+
$method->setAccessible(true);
70+
$inheritedScopes = $method->invoke($token, 'admin:webhooks:read');
71+
72+
$this->assertSame([
73+
'admin',
74+
'admin:webhooks',
75+
'admin:webhooks:read',
76+
], $inheritedScopes);
77+
}
6178
}

0 commit comments

Comments
 (0)