File tree Expand file tree Collapse file tree 4 files changed +63
-1
lines changed
tests/Feature/Controllers Expand file tree Collapse file tree 4 files changed +63
-1
lines changed Original file line number Diff line number Diff line change 2525 'authorized_to_force_delete ' => 'authorized_to_force_delete ' ,
2626 ]
2727 ],
28+
29+ /*
30+ |--------------------------------------------------------------------------
31+ | Rest Authorizations
32+ |--------------------------------------------------------------------------
33+ |
34+ | This is the feature that automatically binds to policies to validate incoming requests.
35+ | Laravel Rest Api will validate each models searched / mutated / deleted to avoid leaks in your API.
36+ |
37+ */
38+
39+ 'authorizations ' => [
40+ 'enabled ' => true
41+ ],
2842];
Original file line number Diff line number Diff line change @@ -73,6 +73,6 @@ public function isAutomaticGatingEnabled() : bool {
7373 }
7474
7575 public function isAuthorizingEnabled () : bool {
76- return true ;
76+ return config ( ' rest.authorizations.enabled ' ) ;
7777 }
7878}
Original file line number Diff line number Diff line change @@ -71,6 +71,30 @@ public function test_searching_automatic_gated_resource(): void
7171 );
7272 }
7373
74+ public function test_searching_automatic_gated_resource_with_global_config_disabled (): void
75+ {
76+ $ model = ModelFactory::new ()
77+ ->create ();
78+
79+ Gate::policy (Model::class, GreenPolicy::class);
80+
81+ config (['rest.automatic_gates.enabled ' => false ]);
82+
83+ $ response = $ this ->post (
84+ '/api/automatic-gating/search ' ,
85+ [
86+
87+ ],
88+ ['Accept ' => 'application/json ' ]
89+ );
90+
91+ $ this ->assertResourcePaginated (
92+ $ response ,
93+ [$ model ],
94+ new AutomaticGatingResource
95+ );
96+ }
97+
7498 public function test_searching_automatic_gated_resource_with_create_policy (): void
7599 {
76100 $ model = ModelFactory::new ()
Original file line number Diff line number Diff line change 3636
3737class NoAuthorizationTest extends TestCase
3838{
39+ public function test_searching_with_global_authorization_disabled (): void
40+ {
41+ $ model = ModelFactory::new ()
42+ ->create ();
43+
44+ Gate::policy (Model::class, RedPolicy::class);
45+
46+ config (['rest.authorizations.enabled ' => false ]);
47+
48+ $ response = $ this ->post (
49+ '/api/models/search ' ,
50+ [
51+
52+ ],
53+ ['Accept ' => 'application/json ' ]
54+ );
55+
56+ $ this ->assertResourcePaginated (
57+ $ response ,
58+ [$ model ],
59+ new ModelResource
60+ );
61+ }
62+
3963 public function test_searching_with_no_authorizations (): void
4064 {
4165 $ model = ModelFactory::new ()
You can’t perform that action at this time.
0 commit comments