5
5
use Laravel \Passport \Bridge \Client ;
6
6
use Laravel \Passport \Bridge \Scope ;
7
7
use Laravel \Passport \Bridge \ScopeRepository ;
8
+ use Laravel \Passport \Client as ClientModel ;
9
+ use Laravel \Passport \ClientRepository ;
8
10
use Laravel \Passport \Passport ;
11
+ use Mockery ;
9
12
use PHPUnit \Framework \TestCase ;
10
13
11
14
class BridgeScopeRepositoryTest extends TestCase
@@ -16,7 +19,56 @@ public function test_invalid_scopes_are_removed()
16
19
'scope-1 ' => 'description ' ,
17
20
]);
18
21
19
- $ repository = new ScopeRepository ;
22
+ $ client = Mockery::mock (ClientModel::class)->makePartial ();
23
+
24
+ $ clients = Mockery::mock (ClientRepository::class);
25
+ $ clients ->shouldReceive ('findActive ' )->withAnyArgs ()->andReturn ($ client );
26
+
27
+ $ repository = new ScopeRepository ($ clients );
28
+
29
+ $ scopes = $ repository ->finalizeScopes (
30
+ [$ scope1 = new Scope ('scope-1 ' ), new Scope ('scope-2 ' )], 'client_credentials ' , new Client ('id ' , 'name ' , 'http://localhost ' ), 1
31
+ );
32
+
33
+ $ this ->assertEquals ([$ scope1 ], $ scopes );
34
+ }
35
+
36
+ public function test_clients_do_not_restrict_scopes_by_default ()
37
+ {
38
+ Passport::tokensCan ([
39
+ 'scope-1 ' => 'description ' ,
40
+ 'scope-2 ' => 'description ' ,
41
+ ]);
42
+
43
+ $ client = Mockery::mock (ClientModel::class)->makePartial ();
44
+ $ client ->scopes = null ;
45
+
46
+ $ clients = Mockery::mock (ClientRepository::class);
47
+ $ clients ->shouldReceive ('findActive ' )->withAnyArgs ()->andReturn ($ client );
48
+
49
+ $ repository = new ScopeRepository ($ clients );
50
+
51
+ $ scopes = $ repository ->finalizeScopes (
52
+ [$ scope1 = new Scope ('scope-1 ' ), $ scope2 = new Scope ('scope-2 ' )], 'client_credentials ' , new Client ('id ' , 'name ' , 'http://localhost ' ), 1
53
+ );
54
+
55
+ $ this ->assertEquals ([$ scope1 , $ scope2 ], $ scopes );
56
+ }
57
+
58
+ public function test_scopes_disallowed_for_client_are_removed ()
59
+ {
60
+ Passport::tokensCan ([
61
+ 'scope-1 ' => 'description ' ,
62
+ 'scope-2 ' => 'description ' ,
63
+ ]);
64
+
65
+ $ client = Mockery::mock (ClientModel::class)->makePartial ();
66
+ $ client ->scopes = ['scope-1 ' ];
67
+
68
+ $ clients = Mockery::mock (ClientRepository::class);
69
+ $ clients ->shouldReceive ('findActive ' )->withAnyArgs ()->andReturn ($ client );
70
+
71
+ $ repository = new ScopeRepository ($ clients );
20
72
21
73
$ scopes = $ repository ->finalizeScopes (
22
74
[$ scope1 = new Scope ('scope-1 ' ), new Scope ('scope-2 ' )], 'client_credentials ' , new Client ('id ' , 'name ' , 'http://localhost ' ), 1
@@ -31,7 +83,12 @@ public function test_superuser_scope_cant_be_applied_if_wrong_grant()
31
83
'scope-1 ' => 'description ' ,
32
84
]);
33
85
34
- $ repository = new ScopeRepository ;
86
+ $ client = Mockery::mock (ClientModel::class)->makePartial ();
87
+
88
+ $ clients = Mockery::mock (ClientRepository::class);
89
+ $ clients ->shouldReceive ('findActive ' )->withAnyArgs ()->andReturn ($ client );
90
+
91
+ $ repository = new ScopeRepository ($ clients );
35
92
36
93
$ scopes = $ repository ->finalizeScopes (
37
94
[$ scope1 = new Scope ('* ' )], 'refresh_token ' , new Client ('id ' , 'name ' , 'http://localhost ' ), 1
0 commit comments