This repository was archived by the owner on Feb 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
src/Statistics/Http/Middleware
tests/Statistics/Controllers Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace BeyondCode \LaravelWebSockets \Statistics \Http \Middleware ;
4
+
5
+ use BeyondCode \LaravelWebSockets \Apps \App ;
6
+
7
+ class Authorize
8
+ {
9
+ public function handle ($ request , $ next )
10
+ {
11
+ $ app = App::findByKey ($ request ->key );
12
+
13
+ return is_null ($ app ) || $ app ->secret !== $ request ->secret
14
+ ? abort (403 )
15
+ : $ next ($ request );
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace BeyondCode \LaravelWebSockets \Tests \Statistics \Controllers ;
4
+
5
+ use BeyondCode \LaravelWebSockets \Statistics \Http \Controllers \WebSocketStatisticsEntriesController ;
6
+ use BeyondCode \LaravelWebSockets \Statistics \Models \WebSocketsStatisticsEntry ;
7
+ use BeyondCode \LaravelWebSockets \Tests \TestCase ;
8
+
9
+ class WebSocketsStatisticsControllerTest extends TestCase
10
+ {
11
+ /** @test */
12
+ public function it_can_store_statistics ()
13
+ {
14
+ $ this ->post (
15
+ action ([WebSocketStatisticsEntriesController::class, 'store ' ]),
16
+ array_merge ($ this ->payload (), [
17
+ 'key ' => config ('websockets.apps.0.key ' ),
18
+ 'secret ' => config ('websockets.apps.0.secret ' ),
19
+ ])
20
+ );
21
+
22
+ $ entries = WebSocketsStatisticsEntry::get ();
23
+
24
+ $ this ->assertCount (1 , $ entries );
25
+
26
+ $ this ->assertArrayHasKey ('app_id ' , $ entries ->first ()->attributesToArray ());
27
+ }
28
+
29
+ protected function payload (): array
30
+ {
31
+ return [
32
+ 'app_id ' => config ('websockets.apps.0.id ' ),
33
+ 'peak_connection_count ' => 1 ,
34
+ 'websocket_message_count ' => 2 ,
35
+ 'api_message_count ' => 3 ,
36
+ ];
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments