Fixed mc
This commit is contained in:
commit
54a20aec46
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue