File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 99
1010class ValidateWebAppData
1111{
12+ public function __construct (protected Nutgram $ bot )
13+ {
14+ }
15+
1216 public function handle (Request $ request , Closure $ next )
1317 {
1418 try {
1519 $ initData = $ request ->input ('initData ' , '' );
16- $ data = app (Nutgram::class) ->validateWebAppData ($ initData );
20+ $ data = $ this -> bot ->validateWebAppData ($ initData );
1721
18- $ request ->attributes ->add (['webapp ' => $ data ]);
22+ $ request ->attributes ->add (['webAppData ' => $ data ]);
1923 return $ next ($ request );
2024 } catch (InvalidDataException ) {
21- abort ( 403 );
25+ $ this -> handleInvalidData ( $ request , $ next );
2226 }
2327 }
28+
29+ protected function handleInvalidData (Request $ request , Closure $ next ): void
30+ {
31+ abort (403 );
32+ }
2433}
Original file line number Diff line number Diff line change 88use Symfony \Component \HttpKernel \Exception \HttpException ;
99
1010beforeEach (function () {
11+ /** @var FakeNutgram $bot */
12+ $ this ->bot = app (Nutgram::class);
1113 $ this ->request = new Request ();
1214});
1315
1416it ('validates web app data ' , function () {
15- /** @var FakeNutgram $bot */
16- $ bot = app (Nutgram::class);
17-
1817 $ this ->request ->merge ([
19- 'initData ' => $ bot ->generateWebAppData ([
18+ 'initData ' => $ this -> bot ->generateWebAppData ([
2019 'foo ' => 'bar ' ,
2120 'auth_date ' => time (),
2221 ])
2322 ]);
2423
25- $ middleware = new ValidateWebAppData ();
24+ $ middleware = new ValidateWebAppData ($ this -> bot );
2625 $ middleware ->handle ($ this ->request , function ($ request ) {
27- expect ($ request ->get ('webapp ' ))->toBeInstanceOf (WebAppData::class);
26+ expect ($ request ->get ('webAppData ' ))->toBeInstanceOf (WebAppData::class);
2827 });
2928});
3029
3130it ('fails to validate web app data ' , function () {
32- $ middleware = new ValidateWebAppData ();
31+ $ middleware = new ValidateWebAppData ($ this -> bot );
3332 $ middleware ->handle ($ this ->request , function ($ request ) {
3433 });
3534})->throws (HttpException::class);
You can’t perform that action at this time.
0 commit comments