@@ -93,7 +93,9 @@ public function throw_exception_if_unauthorized_get_request_has_forbidden_reques
9393 return response ('All good ' , 200 );
9494 })->middleware (['api ' , 'auth.apikey ' ]);
9595
96- $ this ->get ("/api/posts? {$ queryParam }=value " )->assertInternalServerError ();
96+ $ this ->get ("/api/posts? {$ queryParam }=value " )
97+ ->assertBadRequest ()
98+ ->assertContent ("Request param ' {$ queryParam }' is not allowed. " );
9799 }
98100
99101 /**
@@ -106,7 +108,39 @@ public function throw_exception_if_unauthorized_post_request_has_forbidden_reque
106108 return response ('All good ' , 200 );
107109 })->middleware (['api ' , 'auth.apikey ' ]);
108110
109- $ this ->post ('/api/posts ' , [$ bodyParam => 'value ' ])->assertInternalServerError ();
111+ $ this ->post ('/api/posts ' , [$ bodyParam => 'value ' ])
112+ ->assertBadRequest ()
113+ ->assertContent ("Request param ' {$ bodyParam }' is not allowed. " );
114+ }
115+
116+ /**
117+ * @test
118+ * @dataProvider forbiddenRequestParams
119+ */
120+ public function throw_exception_if_unauthorized_json_get_request_has_forbidden_request_query_params (string $ queryParam ): void
121+ {
122+ Route::get ('/api/posts ' , function () {
123+ return response ('All good ' , 200 );
124+ })->middleware (['api ' , 'auth.apikey ' ]);
125+
126+ $ this ->getJson ("/api/posts? {$ queryParam }=value " )
127+ ->assertBadRequest ()
128+ ->assertJson (['message ' => "Request param ' {$ queryParam }' is not allowed. " ]);
129+ }
130+
131+ /**
132+ * @test
133+ * @dataProvider forbiddenRequestParams
134+ */
135+ public function throw_exception_if_unauthorized_json_post_request_has_forbidden_request_body_params (string $ bodyParam ): void
136+ {
137+ Route::post ('/api/posts ' , function () {
138+ return response ('All good ' , 200 );
139+ })->middleware (['api ' , 'auth.apikey ' ]);
140+
141+ $ this ->postJson ('/api/posts ' , [$ bodyParam => 'value ' ])
142+ ->assertBadRequest ()
143+ ->assertJson (['message ' => "Request param ' {$ bodyParam }' is not allowed. " ]);
110144 }
111145
112146 public function forbiddenRequestParams (): array
0 commit comments