diff --git a/src/Statistics/Http/Middleware/Authorize.php b/src/Statistics/Http/Middleware/Authorize.php new file mode 100644 index 0000000..4611dc5 --- /dev/null +++ b/src/Statistics/Http/Middleware/Authorize.php @@ -0,0 +1,17 @@ +key); + + return is_null($app) || $app->secret !== $request->secret + ? abort(403) + : $next($request); + } +} diff --git a/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php b/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php new file mode 100644 index 0000000..beede8a --- /dev/null +++ b/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php @@ -0,0 +1,38 @@ +post( + action([WebSocketStatisticsEntriesController::class, 'store']), + array_merge($this->payload(), [ + 'key' => config('websockets.apps.0.key'), + 'secret' => config('websockets.apps.0.secret'), + ]) + ); + + $entries = WebSocketsStatisticsEntry::get(); + + $this->assertCount(1, $entries); + + $this->assertArrayHasKey('app_id', $entries->first()->attributesToArray()); + } + + protected function payload(): array + { + return [ + 'app_id' => config('websockets.apps.0.id'), + 'peak_connection_count' => 1, + 'websocket_message_count' => 2, + 'api_message_count' => 3, + ]; + } +}