This commit is contained in:
Alex Renoki 2021-01-23 16:51:59 +02:00
commit 54a20aec46
2 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,17 @@
<?php
namespace BeyondCode\LaravelWebSockets\Statistics\Http\Middleware;
use BeyondCode\LaravelWebSockets\Apps\App;
class Authorize
{
public function handle($request, $next)
{
$app = App::findByKey($request->key);
return is_null($app) || $app->secret !== $request->secret
? abort(403)
: $next($request);
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Controllers;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
class WebSocketsStatisticsControllerTest extends TestCase
{
/** @test */
public function it_can_store_statistics()
{
$this->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,
];
}
}